git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC] receive-pack: allow for hiding refs outside the namespace

From
Lukas Fleischer <lfleischer@lfos.de>
Date
Oct 26, 2015, 08:09 UTC
Message-ID
<1445846999-8627-1-git-send-email-lfleischer@lfos.de>

Right now, we always advertise all refs as ".have", even those outside the current namespace. This leads to problems when trying to push to a repository with a huge number of namespaces from a slow connection.

Add a configuration option receive.advertiseAllRefs that can be used to determine whether refs outside the current namespace should be advertised or not.

Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
---
We are using Git namespaces to store a huge number of (virtual)
repositories inside a shared repository. While the blobs in the virtual
repositories are fairly similar, they do not share any refs, so
advertising any refs outside the current namespace is undesirable. See
the discussion on [1] for details.

Note that this patch is just a draft: I didn't do any testing, apart from checking that it compiles. I would like to hear some opinions before sending a polished version.

Is our use case considered common enough to justify the inclusion of such a configuration option in mainline?

Are there suggestions for a better name for the option? Ideally, it should contain the word "namespace" but I could not come up with something sensible that is short enough.

[1] https://lists.archlinux.org/pipermail/aur-general/2015-October/031596.html
 Documentation/config.txt |  6 ++++++
 builtin/receive-pack.c   | 31 +++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 315f271..aa101a7 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2201,6 +2201,12 @@ receive.advertiseAtomic::
 	capability to its clients. If you don't want to this capability
 	to be advertised, set this variable to false.
 
+receive.advertiseAllRefs::
+	By default, git-receive-pack will advertise all refs, even those
+	outside the current namespace, so that the client can use them to
+	minimize data transfer. If you only want to advertise refs from the
+	active namespace to be advertised, set this variable to false.
+
 receive.autogc::
 	By default, git-receive-pack will run "git-gc --auto" after
 	receiving data from git-push and updating refs.  You can stop
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e6b93d0..ea9a820 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -41,6 +41,7 @@ static struct strbuf fsck_msg_types = STRBUF_INIT;
 static int receive_unpack_limit = -1;
 static int transfer_unpack_limit = -1;
 static int advertise_atomic_push = 1;
+static int advertise_all_refs = 1;
 static int unpack_limit = 100;
 static int report_status;
 static int use_sideband;
@@ -190,6 +191,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (strcmp(var, "receive.advertiseallrefs") == 0) {
+		advertise_all_refs = git_config_bool(var, value);
+		return 0;
+	}
+
 	return git_default_config(var, value, cb);
 }
 
@@ -222,16 +228,21 @@ static void show_ref(const char *path, const unsigned char *sha1)
 static int show_ref_cb(const char *path, const struct object_id *oid, int flag, void *unused)
 {
 	path = strip_namespace(path);
-	/*
-	 * Advertise refs outside our current namespace as ".have"
-	 * refs, so that the client can use them to minimize data
-	 * transfer but will otherwise ignore them. This happens to
-	 * cover ".have" that are thrown in by add_one_alternate_ref()
-	 * to mark histories that are complete in our alternates as
-	 * well.
-	 */
-	if (!path)
-		path = ".have";
+	if (!path) {
+		if (advertise_all_refs) {
+			/*
+			 * Advertise refs outside our current namespace as
+			 * ".have" refs, so that the client can use them to
+			 * minimize data transfer but will otherwise ignore
+			 * them. This happens to cover ".have" that are thrown
+			 * in by add_one_alternate_ref() to mark histories that
+			 * are complete in our alternates as well.
+			 */
+			path = ".have";
+		} else {
+			return 0;
+		}
+	}
 	show_ref(path, oid->hash);
 	return 0;
 }
-- 
2.6.2
Next: Junio C Hamano
Message 1 of 17 in “receive-pack: allow for hiding refs outside the namespace”
  1. receive-pack: allow for hiding refs outside the namespaceLukas Fleischer, Oct 26, 2015
  2. Junio C HamanoOct 26, 2015
  3. Allow hideRefs to match refs outside the namespaceLukas Fleischer, Oct 28, 2015
  4. Junio C HamanoOct 28, 2015
  5. Lukas FleischerOct 31, 2015
  6. Junio C HamanoOct 31, 2015
  7. Lukas FleischerOct 31, 2015
  8. Lukas FleischerNov 1, 2015
  9. Junio C HamanoNov 1, 2015
  10. Lukas FleischerOct 27, 2015
  11. Junio C HamanoOct 27, 2015
  12. Lukas FleischerOct 28, 2015
  13. Jeff KingOct 28, 2015
  14. Junio C HamanoOct 28, 2015
  15. Junio C HamanoOct 30, 2015
  16. Jeff KingOct 30, 2015
  17. Lukas FleischerOct 31, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.