Re: [PATCH 06/16] upload-pack: generalize commit date cutoff

2018-07-18 Thread Derrick Stolee

On 7/16/2018 3:38 PM, Stefan Beller wrote:

On Mon, Jul 16, 2018 at 6:00 AM Derrick Stolee via GitGitGadget
 wrote:

From: Derrick Stolee 

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.


   'oldest_have' seems to be used in only one method after that
   (function got_oid); but as that function is called many times
   we either have to make it a function-global or pass around as a parameter,
   we'll defer that to later.


There is a lot of global state involved in this negotiation code, and it 
lives between negotiation rounds when the transfer is stateful. Tread 
carefully!


I did not attempt to reduce the global state at all.

Thanks,

-Stolee



Re: [PATCH 06/16] upload-pack: generalize commit date cutoff

2018-07-16 Thread Stefan Beller
On Mon, Jul 16, 2018 at 6:00 AM Derrick Stolee via GitGitGadget
 wrote:
>
> From: Derrick Stolee 
>
> 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.


  'oldest_have' seems to be used in only one method after that
  (function got_oid); but as that function is called many times
  we either have to make it a function-global or pass around as a parameter,
  we'll defer that to later.

Code (of all previous patches and this one) look good!
Thanks,
Stefan


[PATCH 06/16] upload-pack: generalize commit date cutoff

2018-07-16 Thread Derrick Stolee via GitGitGadget
From: Derrick Stolee 

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 
---
 upload-pack.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index e7ad7f24b..96298e50e 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -336,7 +336,8 @@ static int got_oid(const char *hex, struct object_id *oid)
return 0;
 }
 
-static int reachable(struct commit *from, int with_flag, int assign_flag)
+static int reachable(struct commit *from, int with_flag, int assign_flag,
+time_t min_commit_date)
 {
struct prio_queue work = { compare_commits_by_commit_date };
 
@@ -354,7 +355,7 @@ static int reachable(struct commit *from, int with_flag, 
int assign_flag)
if (commit->object.flags & REACHABLE)
continue;
commit->object.flags |= REACHABLE;
-   if (commit->date < oldest_have)
+   if (commit->date < min_commit_date)
continue;
for (list = commit->parents; list; list = list->next) {
struct commit *parent = list->item;
@@ -371,10 +372,12 @@ static int reachable(struct commit *from, int with_flag, 
int assign_flag)
 /*
  * 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.
+ * as a marker for commits that are already visited. Do not walk
+ * commits with date below 'min_commit_date'.
  */
 static int can_all_from_reach_with_flag(struct object_array *from,
-   int with_flag, int assign_flag)
+   int with_flag, int assign_flag,
+   time_t min_commit_date)
 {
int i;
 
@@ -393,7 +396,8 @@ static int can_all_from_reach_with_flag(struct object_array 
*from,
from->objects[i].item->flags |= assign_flag;
continue;
}
-   if (!reachable((struct commit *)from_one, with_flag, 
assign_flag))
+   if (!reachable((struct commit *)from_one, with_flag, 
assign_flag,
+  min_commit_date))
return 0;
}
return 1;
@@ -404,7 +408,8 @@ static int ok_to_give_up(void)
if (!have_obj.nr)
return 0;
 
-   return can_all_from_reach_with_flag(_obj, THEY_HAVE, COMMON_KNOWN);
+   return can_all_from_reach_with_flag(_obj, THEY_HAVE,
+   COMMON_KNOWN, oldest_have);
 }
 
 static int get_common_commits(void)
-- 
gitgitgadget