Skip to content

Commit 118be57

Browse files
derrickstoleegitster
authored andcommitted
upload-pack: generalize commit date cutoff
The ok_to_give_up() method uses the commit date as a cutoff to avoid walking the entire reachble set of commits. Before moving the reachable() method to commit-reach.c, pull out the dependence on the global constant 'oldest_have' with a 'min_commit_date' parameter. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 921bf77 commit 118be57

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

upload-pack.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static int got_oid(const char *hex, struct object_id *oid)
337337
}
338338

339339
static int reachable(struct commit *from, unsigned int with_flag,
340-
unsigned int assign_flag)
340+
unsigned int assign_flag, time_t min_commit_date)
341341
{
342342
struct prio_queue work = { compare_commits_by_commit_date };
343343

@@ -355,7 +355,7 @@ static int reachable(struct commit *from, unsigned int with_flag,
355355
if (commit->object.flags & REACHABLE)
356356
continue;
357357
commit->object.flags |= REACHABLE;
358-
if (commit->date < oldest_have)
358+
if (commit->date < min_commit_date)
359359
continue;
360360
for (list = commit->parents; list; list = list->next) {
361361
struct commit *parent = list->item;
@@ -372,11 +372,13 @@ static int reachable(struct commit *from, unsigned int with_flag,
372372
/*
373373
* Determine if every commit in 'from' can reach at least one commit
374374
* that is marked with 'with_flag'. As we traverse, use 'assign_flag'
375-
* as a marker for commits that are already visited.
375+
* as a marker for commits that are already visited. Do not walk
376+
* commits with date below 'min_commit_date'.
376377
*/
377378
static int can_all_from_reach_with_flag(struct object_array *from,
378379
unsigned int with_flag,
379-
unsigned int assign_flag)
380+
unsigned int assign_flag,
381+
time_t min_commit_date)
380382
{
381383
int i;
382384

@@ -395,7 +397,8 @@ static int can_all_from_reach_with_flag(struct object_array *from,
395397
from->objects[i].item->flags |= assign_flag;
396398
continue;
397399
}
398-
if (!reachable((struct commit *)from_one, with_flag, assign_flag))
400+
if (!reachable((struct commit *)from_one, with_flag, assign_flag,
401+
min_commit_date))
399402
return 0;
400403
}
401404
return 1;
@@ -406,7 +409,8 @@ static int ok_to_give_up(void)
406409
if (!have_obj.nr)
407410
return 0;
408411

409-
return can_all_from_reach_with_flag(&want_obj, THEY_HAVE, COMMON_KNOWN);
412+
return can_all_from_reach_with_flag(&want_obj, THEY_HAVE,
413+
COMMON_KNOWN, oldest_have);
410414
}
411415

412416
static int get_common_commits(void)

0 commit comments

Comments
 (0)