summaryrefslogtreecommitdiff
path: root/commit-reach.c
diff options
context:
space:
mode:
Diffstat (limited to 'commit-reach.c')
-rw-r--r--commit-reach.c89
1 files changed, 49 insertions, 40 deletions
diff --git a/commit-reach.c b/commit-reach.c
index e3edd11995..cc18c86d3b 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,5 +1,4 @@
#define USE_THE_REPOSITORY_VARIABLE
-#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
#include "commit.h"
@@ -42,8 +41,7 @@ static int compare_commits_by_gen(const void *_a, const void *_b)
static int queue_has_nonstale(struct prio_queue *queue)
{
- int i;
- for (i = 0; i < queue->nr; i++) {
+ for (size_t i = 0; i < queue->nr; i++) {
struct commit *commit = queue->array[i].data;
if (!(commit->object.flags & STALE))
return 1;
@@ -62,6 +60,7 @@ static int paint_down_to_common(struct repository *r,
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
int i;
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
+ struct commit_list **tail = result;
if (!min_generation && !corrected_commit_dates_enabled(r))
queue.compare = compare_commits_by_commit_date;
@@ -97,7 +96,7 @@ static int paint_down_to_common(struct repository *r,
if (flags == (PARENT1 | PARENT2)) {
if (!(commit->object.flags & RESULT)) {
commit->object.flags |= RESULT;
- commit_list_insert_by_date(commit, result);
+ tail = commit_list_append(commit, tail);
}
/* Mark parents of a found merge stale */
flags |= STALE;
@@ -130,6 +129,7 @@ static int paint_down_to_common(struct repository *r,
}
clear_prio_queue(&queue);
+ commit_list_sort_by_date(result);
return 0;
}
@@ -138,7 +138,7 @@ static int merge_bases_many(struct repository *r,
struct commit **twos,
struct commit_list **result)
{
- struct commit_list *list = NULL;
+ struct commit_list *list = NULL, **tail = result;
int i;
for (i = 0; i < n; i++) {
@@ -173,8 +173,9 @@ static int merge_bases_many(struct repository *r,
while (list) {
struct commit *commit = pop_commit(&list);
if (!(commit->object.flags & STALE))
- commit_list_insert_by_date(commit, result);
+ tail = commit_list_append(commit, tail);
}
+ commit_list_sort_by_date(result);
return 0;
}
@@ -213,12 +214,13 @@ int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result)
}
static int remove_redundant_no_gen(struct repository *r,
- struct commit **array, int cnt)
+ struct commit **array,
+ size_t cnt, size_t *dedup_cnt)
{
struct commit **work;
unsigned char *redundant;
- int *filled_index;
- int i, j, filled;
+ size_t *filled_index;
+ size_t i, j, filled;
CALLOC_ARRAY(work, cnt);
redundant = xcalloc(cnt, 1);
@@ -268,20 +270,22 @@ static int remove_redundant_no_gen(struct repository *r,
for (i = filled = 0; i < cnt; i++)
if (!redundant[i])
array[filled++] = work[i];
+ *dedup_cnt = filled;
free(work);
free(redundant);
free(filled_index);
- return filled;
+ return 0;
}
static int remove_redundant_with_gen(struct repository *r,
- struct commit **array, int cnt)
+ struct commit **array, size_t cnt,
+ size_t *dedup_cnt)
{
- int i, count_non_stale = 0, count_still_independent = cnt;
+ size_t i, count_non_stale = 0, count_still_independent = cnt;
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
struct commit **walk_start, **sorted;
size_t walk_start_nr = 0, walk_start_alloc = cnt;
- int min_gen_pos = 0;
+ size_t min_gen_pos = 0;
/*
* Sort the input by generation number, ascending. This allows
@@ -327,12 +331,12 @@ static int remove_redundant_with_gen(struct repository *r,
* terminate early. Otherwise, we will do the same amount of work
* as before.
*/
- for (i = walk_start_nr - 1; i >= 0 && count_still_independent > 1; i--) {
+ for (i = walk_start_nr; i && count_still_independent > 1; i--) {
/* push the STALE bits up to min generation */
struct commit_list *stack = NULL;
- commit_list_insert(walk_start[i], &stack);
- walk_start[i]->object.flags |= STALE;
+ commit_list_insert(walk_start[i - 1], &stack);
+ walk_start[i - 1]->object.flags |= STALE;
while (stack) {
struct commit_list *parents;
@@ -389,10 +393,12 @@ static int remove_redundant_with_gen(struct repository *r,
clear_commit_marks_many(walk_start_nr, walk_start, STALE);
free(walk_start);
- return count_non_stale;
+ *dedup_cnt = count_non_stale;
+ return 0;
}
-static int remove_redundant(struct repository *r, struct commit **array, int cnt)
+static int remove_redundant(struct repository *r, struct commit **array,
+ size_t cnt, size_t *dedup_cnt)
{
/*
* Some commit in the array may be an ancestor of
@@ -402,31 +408,30 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
* that number.
*/
if (generation_numbers_enabled(r)) {
- int i;
-
/*
* If we have a single commit with finite generation
* number, then the _with_gen algorithm is preferred.
*/
- for (i = 0; i < cnt; i++) {
+ for (size_t i = 0; i < cnt; i++) {
if (commit_graph_generation(array[i]) < GENERATION_NUMBER_INFINITY)
- return remove_redundant_with_gen(r, array, cnt);
+ return remove_redundant_with_gen(r, array, cnt, dedup_cnt);
}
}
- return remove_redundant_no_gen(r, array, cnt);
+ return remove_redundant_no_gen(r, array, cnt, dedup_cnt);
}
static int get_merge_bases_many_0(struct repository *r,
struct commit *one,
- int n,
+ size_t n,
struct commit **twos,
int cleanup,
struct commit_list **result)
{
- struct commit_list *list;
+ struct commit_list *list, **tail = result;
struct commit **rslt;
- int cnt, i;
+ size_t cnt, i;
+ int ret;
if (merge_bases_many(r, one, n, twos, result) < 0)
return -1;
@@ -453,20 +458,21 @@ static int get_merge_bases_many_0(struct repository *r,
clear_commit_marks(one, all_flags);
clear_commit_marks_many(n, twos, all_flags);
- cnt = remove_redundant(r, rslt, cnt);
- if (cnt < 0) {
+ ret = remove_redundant(r, rslt, cnt, &cnt);
+ if (ret < 0) {
free(rslt);
return -1;
}
for (i = 0; i < cnt; i++)
- commit_list_insert_by_date(rslt[i], result);
+ tail = commit_list_append(rslt[i], tail);
+ commit_list_sort_by_date(result);
free(rslt);
return 0;
}
int repo_get_merge_bases_many(struct repository *r,
struct commit *one,
- int n,
+ size_t n,
struct commit **twos,
struct commit_list **result)
{
@@ -475,7 +481,7 @@ int repo_get_merge_bases_many(struct repository *r,
int repo_get_merge_bases_many_dirty(struct repository *r,
struct commit *one,
- int n,
+ size_t n,
struct commit **twos,
struct commit_list **result)
{
@@ -583,7 +589,8 @@ struct commit_list *reduce_heads(struct commit_list *heads)
struct commit_list *p;
struct commit_list *result = NULL, **tail = &result;
struct commit **array;
- int num_head, i;
+ size_t num_head, i;
+ int ret;
if (!heads)
return NULL;
@@ -604,11 +611,13 @@ struct commit_list *reduce_heads(struct commit_list *heads)
p->item->object.flags &= ~STALE;
}
}
- num_head = remove_redundant(the_repository, array, num_head);
- if (num_head < 0) {
+
+ ret = remove_redundant(the_repository, array, num_head, &num_head);
+ if (ret < 0) {
free(array);
return NULL;
}
+
for (i = 0; i < num_head; i++)
tail = &commit_list_insert(array[i], tail)->next;
free(array);
@@ -781,12 +790,12 @@ int commit_contains(struct ref_filter *filter, struct commit *commit,
int can_all_from_reach_with_flag(struct object_array *from,
unsigned int with_flag,
unsigned int assign_flag,
- time_t min_commit_date,
+ timestamp_t min_commit_date,
timestamp_t min_generation)
{
struct commit **list = NULL;
- int i;
- int nr_commits;
+ size_t i;
+ size_t nr_commits;
int result = 1;
ALLOC_ARRAY(list, from->nr);
@@ -884,9 +893,9 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
int cutoff_by_min_date)
{
struct object_array from_objs = OBJECT_ARRAY_INIT;
- time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
struct commit_list *from_iter = from, *to_iter = to;
int result;
+ timestamp_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
while (from_iter) {
@@ -938,8 +947,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
return result;
}
-struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
- struct commit **to, int nr_to,
+struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
+ struct commit **to, size_t nr_to,
unsigned int reachable_flag)
{
struct commit **item;