Re: [RFC PATCH 04/13] upload-pack: make reachable() more generic

2018-06-29 Thread Junio C Hamano
Derrick Stolee  writes:

> 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.

FWIW, I find the order of things done quite sensible.  Rename,
extend, etc., to prepare before moving and then move, not the other
way around.  You would want to do the same for some symbols named
overly broadly you moved in earlier steps, too.

Also, if you will be making this function a global one in a later
step, now is the time to give it a good name suitable in the new
global context before moving in this preparatory step.  If it will
be file-scope static in its new home, then reachable() may still be
a good enough name.  Let's keep reading...


[RFC PATCH 04/13] upload-pack: make reachable() more generic

2018-06-29 Thread Derrick Stolee
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 
---
 upload-pack.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 87c6722ea5..95c56dc027 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -28,7 +28,6 @@
 #define OUR_REF(1u << 12)
 #define WANTED (1u << 13)
 #define COMMON_KNOWN   (1u << 14)
-#define REACHABLE  (1u << 15)
 
 #define SHALLOW(1u << 16)
 #define NOT_SHALLOW(1u << 17)
@@ -334,36 +333,36 @@ static int got_oid(const char *hex, struct object_id *oid)
return 0;
 }
 
-static int reachable(struct commit *want)
+static int reachable(struct commit *from, int with_flag, int assign_flag)
 {
struct prio_queue work = { compare_commits_by_commit_date };
 
-   prio_queue_put(, want);
+   prio_queue_put(, from);
while (work.nr) {
struct commit_list *list;
struct commit *commit = prio_queue_get();
 
-   if (commit->object.flags & THEY_HAVE) {
-   want->object.flags |= COMMON_KNOWN;
+   if (commit->object.flags & with_flag) {
+   from->object.flags |= assign_flag;
break;
}
if (!commit->object.parsed)
parse_object(>object.oid);
-   if (commit->object.flags & REACHABLE)
+   if (commit->object.flags & TMP_MARK)
continue;
-   commit->object.flags |= REACHABLE;
+   commit->object.flags |= TMP_MARK;
if (commit->date < oldest_have)
continue;
for (list = commit->parents; list; list = list->next) {
struct commit *parent = list->item;
-   if (!(parent->object.flags & REACHABLE))
+   if (!(parent->object.flags & TMP_MARK))
prio_queue_put(, parent);
}
}
-   want->object.flags |= REACHABLE;
-   clear_commit_marks(want, REACHABLE);
+   from->object.flags |= TMP_MARK;
+   clear_commit_marks(from, TMP_MARK);
clear_prio_queue();
-   return (want->object.flags & COMMON_KNOWN);
+   return (from->object.flags & assign_flag);
 }
 
 static int ok_to_give_up(void)
@@ -388,7 +387,7 @@ static int ok_to_give_up(void)
want_obj.objects[i].item->flags |= COMMON_KNOWN;
continue;
}
-   if (!reachable((struct commit *)want))
+   if (!reachable((struct commit *)want, THEY_HAVE, COMMON_KNOWN))
return 0;
}
return 1;
-- 
2.18.0.118.gd4f65b8d14