]> git.ipfire.org Git - thirdparty/git.git/commitdiff
negotiator: add have_sent() interface
authorDerrick Stolee <stolee@gmail.com>
Tue, 19 May 2026 16:24:52 +0000 (16:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 May 2026 02:33:24 +0000 (11:33 +0900)
In a future change, we will introduce a capability to choose specific commit
OIDs as 'have's in fetch negotiation, with the ability to have the
negotiator choose more 'have's to increase coverage beyond that required
core set. The negotiator works to avoid emitting 'have's that can reach each
other, but that logic is hidden beneath the negotiator's iterator function
pointer ('next'). We need a way to communicate to the negotiator that we
have picked a 'have' so it could incorporate that into its logic.

Add a have_sent() method to the fetch_negotiator interface. This is the
signal that allows the negotiator to track the commit as already shown and
can perform the proper bookkeeping to avoid emitting those objects or
anything they can reach.

For our non-trivial negotiators, it is sufficient to mark these commits as
common, so the implementation is quite simple. This logic will be exercised
in the next change.

Reviewed-by: Matthew John Cheetham <mjcheetham@outlook.com>
Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fetch-negotiator.h
negotiator/default.c
negotiator/noop.c
negotiator/skipping.c

index e348905a1f0008950c66aca1c7b1d69a1253cccf..6ca422a064768c14f855dca430108279f2b48da5 100644 (file)
@@ -47,6 +47,15 @@ struct fetch_negotiator {
         */
        int (*ack)(struct fetch_negotiator *, struct commit *);
 
+       /*
+        * Inform the negotiator that this commit has already been sent as
+        * a "have" line outside of the negotiator's control. The negotiator
+        * should avoid outputting it from next() and may use it to optimize
+        * further negotiation (e.g., by treating it and its ancestors as
+        * common).
+        */
+       void (*have_sent)(struct fetch_negotiator *, struct commit *);
+
        void (*release)(struct fetch_negotiator *);
 
        /* internal use */
index 116dedcf83035db968103a73753000ed165fe87c..05ab616f399116b288ba9d0187bdbc44281b0934 100644 (file)
@@ -175,6 +175,13 @@ static int ack(struct fetch_negotiator *n, struct commit *c)
        return known_to_be_common;
 }
 
+static void have_sent(struct fetch_negotiator *n, struct commit *c)
+{
+       if (repo_parse_commit(the_repository, c))
+               return;
+       mark_common(n->data, c, 0, 0);
+}
+
 static void release(struct fetch_negotiator *n)
 {
        clear_prio_queue(&((struct negotiation_state *)n->data)->rev_list);
@@ -188,6 +195,7 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)
        negotiator->add_tip = add_tip;
        negotiator->next = next;
        negotiator->ack = ack;
+       negotiator->have_sent = have_sent;
        negotiator->release = release;
        negotiator->data = CALLOC_ARRAY(ns, 1);
        ns->rev_list.compare = compare_commits_by_commit_date;
index 65e3c200084aa4a198145e2433ad6055425ae2fa..edf1b456f312041233066f8c9b3624827db88f8c 100644 (file)
@@ -29,6 +29,12 @@ static int ack(struct fetch_negotiator *n UNUSED, struct commit *c UNUSED)
        return 0;
 }
 
+static void have_sent(struct fetch_negotiator *n UNUSED,
+                     struct commit *c UNUSED)
+{
+       /* nothing to do */
+}
+
 static void release(struct fetch_negotiator *n UNUSED)
 {
        /* nothing to release */
@@ -40,6 +46,7 @@ void noop_negotiator_init(struct fetch_negotiator *negotiator)
        negotiator->add_tip = add_tip;
        negotiator->next = next;
        negotiator->ack = ack;
+       negotiator->have_sent = have_sent;
        negotiator->release = release;
        negotiator->data = NULL;
 }
index 0a272130fb1b6d2007b24a01ac003a438cf43c2a..69472c58e18a7a2393c0d6f15f3286a9a332c029 100644 (file)
@@ -243,6 +243,13 @@ static int ack(struct fetch_negotiator *n, struct commit *c)
        return known_to_be_common;
 }
 
+static void have_sent(struct fetch_negotiator *n, struct commit *c)
+{
+       if (repo_parse_commit(the_repository, c))
+               return;
+       mark_common(n->data, c);
+}
+
 static void release(struct fetch_negotiator *n)
 {
        struct data *data = n->data;
@@ -259,6 +266,7 @@ void skipping_negotiator_init(struct fetch_negotiator *negotiator)
        negotiator->add_tip = add_tip;
        negotiator->next = next;
        negotiator->ack = ack;
+       negotiator->have_sent = have_sent;
        negotiator->release = release;
        negotiator->data = CALLOC_ARRAY(data, 1);
        data->rev_list.compare = compare;