Skip to content

Commit 921bf77

Browse files
derrickstoleegitster
authored andcommitted
upload-pack: refactor ok_to_give_up()
In anticipation of consolidating all commit reachability algorithms, refactor ok_to_give_up() in order to allow splitting its logic into an external method. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f044bb4 commit 921bf77

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

upload-pack.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,34 +369,46 @@ static int reachable(struct commit *from, unsigned int with_flag,
369369
return (from->object.flags & assign_flag);
370370
}
371371

372-
static int ok_to_give_up(void)
372+
/*
373+
* Determine if every commit in 'from' can reach at least one commit
374+
* that is marked with 'with_flag'. As we traverse, use 'assign_flag'
375+
* as a marker for commits that are already visited.
376+
*/
377+
static int can_all_from_reach_with_flag(struct object_array *from,
378+
unsigned int with_flag,
379+
unsigned int assign_flag)
373380
{
374381
int i;
375382

376-
if (!have_obj.nr)
377-
return 0;
378-
379-
for (i = 0; i < want_obj.nr; i++) {
380-
struct object *want = want_obj.objects[i].item;
383+
for (i = 0; i < from->nr; i++) {
384+
struct object *from_one = from->objects[i].item;
381385

382-
if (want->flags & COMMON_KNOWN)
386+
if (from_one->flags & assign_flag)
383387
continue;
384-
want = deref_tag(the_repository, want, "a want line", 0);
385-
if (!want || want->type != OBJ_COMMIT) {
388+
from_one = deref_tag(the_repository, from_one, "a from object", 0);
389+
if (!from_one || from_one->type != OBJ_COMMIT) {
386390
/* no way to tell if this is reachable by
387391
* looking at the ancestry chain alone, so
388392
* leave a note to ourselves not to worry about
389393
* this object anymore.
390394
*/
391-
want_obj.objects[i].item->flags |= COMMON_KNOWN;
395+
from->objects[i].item->flags |= assign_flag;
392396
continue;
393397
}
394-
if (!reachable((struct commit *)want, THEY_HAVE, COMMON_KNOWN))
398+
if (!reachable((struct commit *)from_one, with_flag, assign_flag))
395399
return 0;
396400
}
397401
return 1;
398402
}
399403

404+
static int ok_to_give_up(void)
405+
{
406+
if (!have_obj.nr)
407+
return 0;
408+
409+
return can_all_from_reach_with_flag(&want_obj, THEY_HAVE, COMMON_KNOWN);
410+
}
411+
400412
static int get_common_commits(void)
401413
{
402414
struct object_id oid;

0 commit comments

Comments
 (0)