@@ -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 "null" 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".
@@ -917,6 +917,7 @@ LIB_OBJS += mergesort.o
LIB_OBJS += midx.o
LIB_OBJS += name-hash.o
LIB_OBJS += negotiator/default.o
+LIB_OBJS += negotiator/null.o
LIB_OBJS += negotiator/skipping.o
LIB_OBJS += notes-cache.o
LIB_OBJS += notes-merge.o
@@ -2,6 +2,7 @@
#include "fetch-negotiator.h"
#include "negotiator/default.h"
#include "negotiator/skipping.h"
+#include "negotiator/null.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_NULL:
+ null_negotiator_init(negotiator);
+ return;
+
case FETCH_NEGOTIATION_DEFAULT:
default:
default_negotiator_init(negotiator);
new file mode 100644
@@ -0,0 +1,34 @@
+#include "cache.h"
+#include "null.h"
+#include "../commit.h"
+#include "../fetch-negotiator.h"
+
+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 null negotiator, which does not emit any commits");
+ return 0;
+}
+
+static void release(struct fetch_negotiator *n)
+{
+ /* nothing to release */
+}
+
+void null_negotiator_init(struct fetch_negotiator *negotiator)
+{
+ negotiator->known_common = NULL;
+ negotiator->add_tip = NULL;
+ negotiator->next = next;
+ negotiator->ack = ack;
+ negotiator->release = release;
+ negotiator->data = NULL;
+}
new file mode 100644
@@ -0,0 +1,8 @@
+#ifndef NEGOTIATOR_NULL_H
+#define NEGOTIATOR_NULL_H
+
+struct fetch_negotiator;
+
+void null_negotiator_init(struct fetch_negotiator *negotiator);
+
+#endif
@@ -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, "null"))
+ r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NULL;
else
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT;
}
@@ -23,6 +23,7 @@ enum fetch_negotiation_setting {
FETCH_NEGOTIATION_NONE = 0,
FETCH_NEGOTIATION_DEFAULT = 1,
FETCH_NEGOTIATION_SKIPPING = 2,
+ FETCH_NEGOTIATION_NULL = 3,
};
struct repo_settings {
new file mode 100755
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+test_description='test null fetch negotiator'
+. ./test-lib.sh
+
+test_expect_success 'null 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 null &&
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+
+ ! grep "fetch> have" trace &&
+ grep "fetch> done" trace
+'
+
+test_done
Add a null fetch negotiator. This is introduced to allow partial clones to perform lazy fetches (which do not need negotiation at all) by spawning a subprocess (to be done in a subsequent patch), but can be useful for end users, e.g. as a blunt fix for object corruption. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> --- Documentation/config/fetch.txt | 5 ++++- Makefile | 1 + fetch-negotiator.c | 5 +++++ negotiator/null.c | 34 ++++++++++++++++++++++++++++++++ negotiator/null.h | 8 ++++++++ repo-settings.c | 2 ++ repository.h | 1 + t/t5554-null-fetch-negotiator.sh | 22 +++++++++++++++++++++ 8 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 negotiator/null.c create mode 100644 negotiator/null.h create mode 100755 t/t5554-null-fetch-negotiator.sh