]> git.ipfire.org Git - thirdparty/git.git/commitdiff
negotiator/noop: add noop fetch negotiator
authorJonathan Tan <jonathantanmy@google.com>
Tue, 18 Aug 2020 04:01:31 +0000 (21:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Aug 2020 20:25:05 +0000 (13:25 -0700)
Add a noop fetch negotiator. This is introduced to allow partial clones
to skip the unneeded negotiation step when fetching missing objects
using a "git fetch" subprocess. (The implementation of spawning a "git
fetch" subprocess will be done in a subsequent patch.) But this can also
be useful for end users, e.g. as a blunt fix for object corruption.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/fetch.txt
Makefile
fetch-negotiator.c
negotiator/noop.c [new file with mode: 0644]
negotiator/noop.h [new file with mode: 0644]
repo-settings.c
repository.h
t/t5554-noop-fetch-negotiator.sh [new file with mode: 0755]

index b20394038d1eef83d7e454cf0fee7ceb8a457a0f..6af6f5edb278f53ceb2f4c69f47f72d6ef120e2f 100644 (file)
@@ -60,7 +60,10 @@ fetch.negotiationAlgorithm::
        sent when negotiating the contents of the packfile to be sent by the
        server. Set to "skipping" to use an algorithm that skips commits in an
        effort to converge faster, but may result in a larger-than-necessary
-       packfile; The default is "default" which instructs Git to use the default algorithm
+       packfile; or set to "noop" to not send any information at all, which
+       will almost certainly result in a larger-than-necessary packfile, but
+       will skip the negotiation step.
+       The default is "default" which instructs Git to use the default algorithm
        that never skips commits (unless the server has acknowledged it or one
        of its descendants). If `feature.experimental` is enabled, then this
        setting defaults to "skipping".
index 65f8cfb2368d2d6099bdfd845a7beb505702b86f..acdd2e356d5c575432216fc5c3813524dbb2f23f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -916,6 +916,7 @@ LIB_OBJS += mergesort.o
 LIB_OBJS += midx.o
 LIB_OBJS += name-hash.o
 LIB_OBJS += negotiator/default.o
+LIB_OBJS += negotiator/noop.o
 LIB_OBJS += negotiator/skipping.o
 LIB_OBJS += notes-cache.o
 LIB_OBJS += notes-merge.o
index 0a1357dc9d55b34992ff5a6f65e3bdf77375465e..57ed5784e1468aa661d59446273ba9cbbad760ca 100644 (file)
@@ -2,6 +2,7 @@
 #include "fetch-negotiator.h"
 #include "negotiator/default.h"
 #include "negotiator/skipping.h"
+#include "negotiator/noop.h"
 #include "repository.h"
 
 void fetch_negotiator_init(struct repository *r,
@@ -13,6 +14,10 @@ void fetch_negotiator_init(struct repository *r,
                skipping_negotiator_init(negotiator);
                return;
 
+       case FETCH_NEGOTIATION_NOOP:
+               noop_negotiator_init(negotiator);
+               return;
+
        case FETCH_NEGOTIATION_DEFAULT:
        default:
                default_negotiator_init(negotiator);
diff --git a/negotiator/noop.c b/negotiator/noop.c
new file mode 100644 (file)
index 0000000..60569b8
--- /dev/null
@@ -0,0 +1,44 @@
+#include "cache.h"
+#include "noop.h"
+#include "../commit.h"
+#include "../fetch-negotiator.h"
+
+static void known_common(struct fetch_negotiator *n, struct commit *c)
+{
+       /* do nothing */
+}
+
+static void add_tip(struct fetch_negotiator *n, struct commit *c)
+{
+       /* do nothing */
+}
+
+static const struct object_id *next(struct fetch_negotiator *n)
+{
+       return NULL;
+}
+
+static int ack(struct fetch_negotiator *n, struct commit *c)
+{
+       /*
+        * This negotiator does not emit any commits, so there is no commit to
+        * be acknowledged. If there is any ack, there is a bug.
+        */
+       BUG("ack with noop negotiator, which does not emit any commits");
+       return 0;
+}
+
+static void release(struct fetch_negotiator *n)
+{
+       /* nothing to release */
+}
+
+void noop_negotiator_init(struct fetch_negotiator *negotiator)
+{
+       negotiator->known_common = known_common;
+       negotiator->add_tip = add_tip;
+       negotiator->next = next;
+       negotiator->ack = ack;
+       negotiator->release = release;
+       negotiator->data = NULL;
+}
diff --git a/negotiator/noop.h b/negotiator/noop.h
new file mode 100644 (file)
index 0000000..2b4ec5d
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef NEGOTIATOR_NOOP_H
+#define NEGOTIATOR_NOOP_H
+
+struct fetch_negotiator;
+
+void noop_negotiator_init(struct fetch_negotiator *negotiator);
+
+#endif
index 0918408b34436a02589cdb850da8345671e4a5f1..aa61a35338138edb31ff6791ad08d560b674c04b 100644 (file)
@@ -39,6 +39,8 @@ void prepare_repo_settings(struct repository *r)
        if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
                if (!strcasecmp(strval, "skipping"))
                        r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
+               else if (!strcasecmp(strval, "noop"))
+                       r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
                else
                        r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT;
        }
index 3c1f7d54bd37a55f6cd1b1ac1f936dc0c17b3dab..628c8343672dbcbbb6b36f732a6d225c726546e0 100644 (file)
@@ -23,6 +23,7 @@ enum fetch_negotiation_setting {
        FETCH_NEGOTIATION_NONE = 0,
        FETCH_NEGOTIATION_DEFAULT = 1,
        FETCH_NEGOTIATION_SKIPPING = 2,
+       FETCH_NEGOTIATION_NOOP = 3,
 };
 
 struct repo_settings {
diff --git a/t/t5554-noop-fetch-negotiator.sh b/t/t5554-noop-fetch-negotiator.sh
new file mode 100755 (executable)
index 0000000..2ac7b58
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+test_description='test noop fetch negotiator'
+. ./test-lib.sh
+
+test_expect_success 'noop negotiator does not emit any "have"' '
+       rm -f trace &&
+
+       test_create_repo server &&
+       test_commit -C server to_fetch &&
+
+       test_create_repo client &&
+       test_commit -C client we_have &&
+
+       test_config -C client fetch.negotiationalgorithm noop &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+
+       ! grep "fetch> have" trace &&
+       grep "fetch> done" trace
+'
+
+test_done