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

Re: [PATCH v2 2/3] transport-helper: run do_take_over in connect_helper

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 25, 2023, 21:34 UTC
Message-ID
<xmqqil7yq6ms.fsf@gitster.g>
In-Reply-To
<20230923152201.14741-3-worldhello.net@gmail.com>
Jiang Xin <worldhello.net@gmail.com> writes:
Show 6 quoted lines
> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
>
> After successfully connecting to the smart transport by calling
> "process_connect_service()" in "connect_helper()", run "do_take_over()"
> to replace the old vtable with a new one which has methods ready for
> the smart transport connection.

The existing pattern among all callers of process_connect() seems to be

	if (process_connect(...)) {
		do_take_over();
		... dispatch to the underlying method ...
	}
	... otherwise implement the fallback ...

where the return value from process_connect() is the return value of the call it makes to process_connect_service().

And the only other caller of process_connect_service() is connect_helper(), so in that sense, making a call to do_take_over() when process_connect_service() succeeds in the helper does make things consistent. The connect_helper() function being static, the helper transport is the only transport that gets affected, but how has it been working without having this do_take_over() step? An obvious related question is if it has been working so far, would it break if we have do_take_over() added here?

In any case, this makes me wonder if we should do the following patch to help developers who may want to add new callers to process_connect_service() by adding calls to process_connect().

 transport-helper.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
diff --git c/transport-helper.c w/transport-helper.c
index 91381be622..566f7473df 100644
--- c/transport-helper.c
+++ w/transport-helper.c
@@ -646,6 +646,7 @@ static int process_connect(struct transport *transport,
 	struct helper_data *data = transport->data;
 	const char *name;
 	const char *exec;
+	int ret;
 
 	name = for_push ? "git-receive-pack" : "git-upload-pack";
 	if (for_push)
@@ -653,7 +654,10 @@ static int process_connect(struct transport *transport,
 	else
 		exec = data->transport_options.uploadpack;
 
-	return process_connect_service(transport, name, exec);
+	ret = process_connect_service(transport, name, exec);
+	if (ret)
+		do_take_over(transport);
+	return ret;
 }
 
 static int connect_helper(struct transport *transport, const char *name,
@@ -685,10 +689,8 @@ static int fetch_refs(struct transport *transport,
 
 	get_helper(transport);
 
-	if (process_connect(transport, 0)) {
-		do_take_over(transport);
+	if (process_connect(transport, 0))
 		return transport->vtable->fetch_refs(transport, nr_heads, to_fetch);
-	}
 
 	/*
 	 * If we reach here, then the server, the client, and/or the transport
@@ -1145,10 +1147,8 @@ static int push_refs(struct transport *transport,
 {
 	struct helper_data *data = transport->data;
 
-	if (process_connect(transport, 1)) {
-		do_take_over(transport);
+	if (process_connect(transport, 1))
 		return transport->vtable->push_refs(transport, remote_refs, flags);
-	}
 
 	if (!remote_refs) {
 		fprintf(stderr,
@@ -1189,11 +1189,9 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
 {
 	get_helper(transport);
 
-	if (process_connect(transport, for_push)) {
-		do_take_over(transport);
+	if (process_connect(transport, for_push))
 		return transport->vtable->get_refs_list(transport, for_push,
 							transport_options);
-	}
 
 	return get_refs_list_using_list(transport, for_push);
 }
@@ -1277,10 +1275,8 @@ static int get_bundle_uri(struct transport *transport)
 {
 	get_helper(transport);
 
-	if (process_connect(transport, 0)) {
-		do_take_over(transport);
+	if (process_connect(transport, 0))
 		return transport->vtable->get_bundle_uri(transport);
-	}
 
 	return -1;
 }
Previous: Jiang XinNext: Jiang Xin
Message 11 of 61 in “transport-helper: no connection restriction in connect_helper”
  1. 1/2 transport-helper: no connection restriction in connect_helperJiang Xin, Sep 19, 2023
  2. 2/2 archive: support remote archive from stateless transportJiang Xin, Sep 19, 2023
  3. Junio C HamanoSep 19, 2023
  4. Jiang XinSep 20, 2023
  5. 0/3 support remote archive from stateless transportJiang Xin, Sep 23, 2023
  6. Junio C HamanoSep 25, 2023
  7. Jiang XinSep 26, 2023
  8. 1/3 transport-helper: no connection restriction in connect_helperJiang Xin, Sep 23, 2023
  9. Junio C HamanoSep 25, 2023
  10. 2/3 transport-helper: run do_take_over in connect_helperJiang Xin, Sep 23, 2023
  11. Junio C HamanoSep 25, 2023
  12. Jiang XinOct 4, 2023
  13. 0/4 support remote archive from stateless transportJiang Xin, Oct 4, 2023
  14. 1/4 transport-helper: no connection restriction in connect_helperJiang Xin, Oct 4, 2023
  15. 3/4 transport-helper: call do_take_over() in connect_helperJiang Xin, Oct 4, 2023
  16. 4/4 archive: support remote archive from stateless transportJiang Xin, Oct 4, 2023
  17. 2/4 transport-helper: call do_take_over() in process_connectJiang Xin, Oct 4, 2023
  18. Junio C HamanoOct 4, 2023
  19. 0/4 support remote archive via stateless transportJiang Xin, Dec 14, 2023
  20. 1/4 transport-helper: no connection restriction in connect_helperJiang Xin, Dec 14, 2023
  21. Linus ArverJan 12, 2024
  22. Junio C HamanoJan 12, 2024
  23. Jiang XinJan 16, 2024
  24. Linus ArverJan 18, 2024
  25. Jiang XinJan 19, 2024
  26. Linus ArverJan 20, 2024
  27. 2/4 transport-helper: call do_take_over() in process_connectJiang Xin, Dec 14, 2023
  28. 3/4 transport-helper: call do_take_over() in connect_helperJiang Xin, Dec 14, 2023
  29. Linus ArverJan 12, 2024
  30. Jiang XinJan 16, 2024
  31. 4/4 archive: support remote archive from stateless transportJiang Xin, Dec 14, 2023
  32. Linus ArverJan 12, 2024
  33. 0/6 support remote archive via stateless transportJiang Xin, Jan 16, 2024
  34. 1/6 transport-helper: no connection restriction in connect_helperJiang Xin, Jan 16, 2024
  35. Linus ArverJan 20, 2024
  36. 2/6 remote-curl: supports git-upload-archive serviceJiang Xin, Jan 16, 2024
  37. Linus ArverJan 20, 2024
  38. 3/6 transport-helper: protocol-v2 supports upload-archiveJiang Xin, Jan 16, 2024
  39. 4/6 http-backend: new rpc-service for git-upload-archiveJiang Xin, Jan 16, 2024
  40. 5/6 transport-helper: call do_take_over() in connect_helperJiang Xin, Jan 16, 2024
  41. Linus ArverJan 20, 2024
  42. 6/6 transport-helper: call do_take_over() in process_connectJiang Xin, Jan 16, 2024
  43. Linus ArverJan 20, 2024
  44. Jiang XinJan 21, 2024
  45. 0/6 support remote archive via stateless transportJiang Xin, Jan 21, 2024
  46. 1/6 transport-helper: no connection restriction in connect_helperJiang Xin, Jan 21, 2024
  47. 2/6 remote-curl: supports git-upload-archive serviceJiang Xin, Jan 21, 2024
  48. 3/6 transport-helper: protocol v2 supports upload-archiveJiang Xin, Jan 21, 2024
  49. 4/6 http-backend: new rpc-service for git-upload-archiveJiang Xin, Jan 21, 2024
  50. 5/6 transport-helper: call do_take_over() in connect_helperJiang Xin, Jan 21, 2024
  51. 6/6 transport-helper: call do_take_over() in process_connectJiang Xin, Jan 21, 2024
  52. Linus ArverJan 21, 2024
  53. Junio C HamanoJan 22, 2024
  54. 3/3 archive: support remote archive from stateless transportJiang Xin, Sep 23, 2023
  55. Eric SunshineSep 24, 2023
  56. Jiang XinSep 24, 2023
  57. rsbecker@nexbridge.comSep 24, 2023
  58. Jiang XinSep 25, 2023
  59. rsbecker@nexbridge.comSep 25, 2023
  60. Phillip WoodSep 24, 2023
  61. Jiang XinSep 24, 2023

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.