upload-pack: make reachable() more generic
In anticipation of moving the reachable() method to commit-reach.c, modify the prototype to be more generic to flags known outside of upload-pack.c. Also rename 'want' to 'from' to make the statement more clear outside of the context of haves/wants negotiation. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jul 20, 2018 at 16:33 UTC
f044bb49add413915d699ca9e3458071dac6c731
1 file changed
+9
-8
upload-pack.c
+9
-8
@@ -336,17 +336,18 @@ static int got_oid(const char *hex, struct object_id *oid)
336
return 0;
337
}
338
339
-static int reachable(struct commit *want)
339
+static int reachable(struct commit *from, unsigned int with_flag,
340
+ unsigned int assign_flag)
341
{
342
struct prio_queue work = { compare_commits_by_commit_date };
343
343
- prio_queue_put(&work, want);
344
+ prio_queue_put(&work, from);
345
while (work.nr) {
346
struct commit_list *list;
347
struct commit *commit = prio_queue_get(&work);
348
348
- if (commit->object.flags & THEY_HAVE) {
349
- want->object.flags |= COMMON_KNOWN;
349
+ if (commit->object.flags & with_flag) {
350
+ from->object.flags |= assign_flag;
351
break;
352
}
353
if (!commit->object.parsed)
@@ -362,10 +363,10 @@ static int reachable(struct commit *want)
363
prio_queue_put(&work, parent);
364
}
365
}
365
- want->object.flags |= REACHABLE;
366
- clear_commit_marks(want, REACHABLE);
366
+ from->object.flags |= REACHABLE;
367
+ clear_commit_marks(from, REACHABLE);
368
clear_prio_queue(&work);
368
- return (want->object.flags & COMMON_KNOWN);
369
+ return (from->object.flags & assign_flag);
370
}
371
372
static int ok_to_give_up(void)
@@ -390,7 +391,7 @@ static int ok_to_give_up(void)
391
want_obj.objects[i].item->flags |= COMMON_KNOWN;
392
continue;
393
}
393
- if (!reachable((struct commit *)want))
394
+ if (!reachable((struct commit *)want, THEY_HAVE, COMMON_KNOWN))
395
return 0;
396
}
397
return 1;