summaryrefslogtreecommitdiff
path: root/upload-pack.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2018-07-20 16:33:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-20 22:38:54 (GMT)
commit921bf7734f11da75516bfd12da5e4fa203cc6d19 (patch)
treefea49dfaa3a1c596a6ffa619e4017785b16232fd /upload-pack.c
parentf044bb49add413915d699ca9e3458071dac6c731 (diff)
downloadgit-921bf7734f11da75516bfd12da5e4fa203cc6d19.zip
git-921bf7734f11da75516bfd12da5e4fa203cc6d19.tar.gz
git-921bf7734f11da75516bfd12da5e4fa203cc6d19.tar.bz2
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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'upload-pack.c')
-rw-r--r--upload-pack.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/upload-pack.c b/upload-pack.c
index 5a639cb..9fe1900 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -369,34 +369,46 @@ static int reachable(struct commit *from, unsigned int with_flag,
return (from->object.flags & assign_flag);
}
-static int ok_to_give_up(void)
+/*
+ * Determine if every commit in 'from' can reach at least one commit
+ * that is marked with 'with_flag'. As we traverse, use 'assign_flag'
+ * as a marker for commits that are already visited.
+ */
+static int can_all_from_reach_with_flag(struct object_array *from,
+ unsigned int with_flag,
+ unsigned int assign_flag)
{
int i;
- if (!have_obj.nr)
- return 0;
-
- for (i = 0; i < want_obj.nr; i++) {
- struct object *want = want_obj.objects[i].item;
+ for (i = 0; i < from->nr; i++) {
+ struct object *from_one = from->objects[i].item;
- if (want->flags & COMMON_KNOWN)
+ if (from_one->flags & assign_flag)
continue;
- want = deref_tag(the_repository, want, "a want line", 0);
- if (!want || want->type != OBJ_COMMIT) {
+ from_one = deref_tag(the_repository, from_one, "a from object", 0);
+ if (!from_one || from_one->type != OBJ_COMMIT) {
/* no way to tell if this is reachable by
* looking at the ancestry chain alone, so
* leave a note to ourselves not to worry about
* this object anymore.
*/
- want_obj.objects[i].item->flags |= COMMON_KNOWN;
+ from->objects[i].item->flags |= assign_flag;
continue;
}
- if (!reachable((struct commit *)want, THEY_HAVE, COMMON_KNOWN))
+ if (!reachable((struct commit *)from_one, with_flag, assign_flag))
return 0;
}
return 1;
}
+static int ok_to_give_up(void)
+{
+ if (!have_obj.nr)
+ return 0;
+
+ return can_all_from_reach_with_flag(&want_obj, THEY_HAVE, COMMON_KNOWN);
+}
+
static int get_common_commits(void)
{
struct object_id oid;