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

[PATCH 03/14] upload-pack-2: Implement the version 2 of upload-pack

From
Stefan Beller <sbeller@google.com>
Date
Apr 29, 2016, 23:34 UTC
Message-ID
<1461972887-22100-4-git-send-email-sbeller@google.com>
In-Reply-To
<1461972887-22100-1-git-send-email-sbeller@google.com>

In upload-pack-2 we send each capability in its own packet buffer. The construction of upload-pack-2 is a bit unfortunate as I would like it to not be depending on a symlink linking to upload-pack.c, but I did not find another easy way to do it. I would like it to generate upload-pack-2.o from upload-pack.c but with '-DTRANSPORT_VERSION=2' set.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 .gitignore      |  1 +
 Makefile        |  4 ++++
 upload-pack-2.c |  1 +
 upload-pack.c   | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 120000 upload-pack-2.c
diff --git a/.gitignore b/.gitignore
index 5087ce1..9a6ea8c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -166,6 +166,7 @@
 /git-update-server-info
 /git-upload-archive
 /git-upload-pack
+/git-upload-pack-2
 /git-var
 /git-verify-commit
 /git-verify-pack
diff --git a/Makefile b/Makefile
index a83e322..3d96126 100644
--- a/Makefile
+++ b/Makefile
@@ -580,6 +580,7 @@ PROGRAM_OBJS += sh-i18n--envsubst.o
 PROGRAM_OBJS += shell.o
 PROGRAM_OBJS += show-index.o
 PROGRAM_OBJS += upload-pack.o
+PROGRAM_OBJS += upload-pack-2.o
 PROGRAM_OBJS += remote-testsvn.o
 
 # Binary suffix, set to .exe for Windows builds
@@ -648,6 +649,7 @@ OTHER_PROGRAMS = git$X
 # what test wrappers are needed and 'install' will install, in bindir
 BINDIR_PROGRAMS_NEED_X += git
 BINDIR_PROGRAMS_NEED_X += git-upload-pack
+BINDIR_PROGRAMS_NEED_X += git-upload-pack-2
 BINDIR_PROGRAMS_NEED_X += git-receive-pack
 BINDIR_PROGRAMS_NEED_X += git-upload-archive
 BINDIR_PROGRAMS_NEED_X += git-shell
@@ -1730,6 +1732,8 @@ $(BUILT_INS): git$X
 	ln -s $< $@ 2>/dev/null || \
 	cp $< $@
 
+$X%-2.o: EXTRA_CPPFLAGS = '-DTRANSPORT_VERSION=2'
+
 common-cmds.h: generate-cmdlist.sh command-list.txt
 
 common-cmds.h: $(wildcard Documentation/git-*.txt)
diff --git a/upload-pack-2.c b/upload-pack-2.c
new file mode 120000
index 0000000..e30a871
--- /dev/null
+++ b/upload-pack-2.c
@@ -0,0 +1 @@
+upload-pack.c
\ No newline at end of file
diff --git a/upload-pack.c b/upload-pack.c
index 85381d5..edfd417 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -820,6 +820,45 @@ static void upload_pack(void)
 	}
 }
 
+#if (TRANSPORT_VERSION == 2)
+static void send_capabilities_version_2(void)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(all_capabilities); i++) {
+		const char *cap = all_capabilities[i];
+		if (!strcmp(cap, "allow-tip-sha1-in-want")
+		    && !(allow_unadvertised_object_request & ALLOW_TIP_SHA1))
+			continue;
+		if (!strcmp(cap, "no-done") && !stateless_rpc)
+			continue;
+		packet_write(1, "%s\n", cap);
+	}
+
+	packet_write(1, "agent=%s\n", git_user_agent_sanitized());
+	packet_flush(1);
+}
+
+static void receive_capabilities_version_2(void)
+{
+	char *line = packet_read_line(0, NULL);
+	while (line) {
+		parse_features(line);
+		line = packet_read_line(0, NULL);
+	}
+}
+
+static void upload_pack_version_2(void)
+{
+	send_capabilities_version_2();
+	receive_capabilities_version_2();
+
+	/* The rest of the protocol stays the same, capabilities advertising
+	   is disabled though. */
+	advertise_capabilities = 0;
+	upload_pack();
+}
+#endif
+
 static int upload_pack_config(const char *var, const char *value, void *unused)
 {
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
@@ -847,8 +886,11 @@ int main(int argc, char **argv)
 	int strict = 0;
 
 	git_setup_gettext();
-
+#if TRANSPORT_VERSION == 2
+	packet_trace_identity("upload-pack-2");
+#else
 	packet_trace_identity("upload-pack");
+#endif
 	git_extract_argv0_path(argv[0]);
 	check_replace_refs = 0;
 
@@ -891,6 +933,11 @@ int main(int argc, char **argv)
 		die("'%s' does not appear to be a git repository", dir);
 
 	git_config(upload_pack_config, NULL);
+
+#if TRANSPORT_VERSION == 2
+	upload_pack_version_2();
+#else
 	upload_pack();
+#endif
 	return 0;
 }
-- 
2.8.0.32.g71f8beb.dirty
Previous: Junio C HamanoNext: David Turner
Message 6 of 40 in “Protocol v2 patches”
  1. 00/14 Protocol v2 patchesStefan Beller, Apr 29, 2016
  2. 01/14 upload-pack: make client capability parsing code a separate functionStefan Beller, Apr 29, 2016
  3. 02/14 upload-pack.c: Refactor capability advertisingStefan Beller, Apr 29, 2016
  4. David TurnerApr 30, 2016
  5. Junio C HamanoMay 4, 2016
  6. 03/14 upload-pack-2: Implement the version 2 of upload-packStefan Beller, Apr 29, 2016
  7. David TurnerMay 2, 2016
  8. Stefan BellerMay 2, 2016
  9. David TurnerMay 2, 2016
  10. Duy NguyenMay 3, 2016
  11. Junio C HamanoMay 4, 2016
  12. 04/14 connect: rewrite feature parsing to work on string_listStefan Beller, Apr 29, 2016
  13. David TurnerMay 2, 2016
  14. Stefan BellerMay 2, 2016
  15. Junio C HamanoMay 4, 2016
  16. David TurnerMay 17, 2016
  17. 05/14 transport: add infrastructure to support a protocol version numberStefan Beller, Apr 29, 2016
  18. 06/14 remote.h: add get_remote_capabilities, request_capabilitiesStefan Beller, Apr 29, 2016
  19. David TurnerMay 2, 2016
  20. Jeff KingMay 3, 2016
  21. David TurnerMay 3, 2016
  22. Stefan BellerMay 4, 2016
  23. 07/14 fetch-pack: move capability selection out of do_fetch_packStefan Beller, Apr 29, 2016
  24. 08/14 fetch-pack: factor out get_selected_capabilities_listStefan Beller, Apr 29, 2016
  25. David TurnerMay 2, 2016
  26. 09/14 fetch-pack: Add negotiate_capabilitiesStefan Beller, Apr 29, 2016
  27. 10/14 do_fetch_pack: select capabilities for transport version 1 onlyStefan Beller, Apr 29, 2016
  28. 11/14 builtin/fetch-pack: add argument for transport versionStefan Beller, Apr 29, 2016
  29. 12/14 Add test for fetch-packStefan Beller, Apr 29, 2016
  30. David TurnerMay 2, 2016
  31. 13/14 WIP add test for git pullStefan Beller, Apr 29, 2016
  32. 14/14 WIP test git fetchStefan Beller, Apr 29, 2016
  33. David TurnerMay 2, 2016
  34. Stefan BellerMay 2, 2016
  35. David TurnerMay 24, 2016
  36. Duy NguyenMay 24, 2016
  37. David TurnerMay 25, 2016
  38. Junio C HamanoMay 25, 2016
  39. David TurnerMay 25, 2016
  40. Jeff KingMay 25, 2016

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.