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

[RFC/PATCH 5/6] Let transport_helper_init() decide if a remote helper program can be used

From
Johan Herland <johan@herland.net>
Date
Aug 11, 2009, 10:10 UTC
Message-ID
<1249985426-13726-6-git-send-email-johan@herland.net>
In-Reply-To
<alpine.LNX.2.00.0908101205120.27553@iabervon.org>

Teach the transport-helper mechanism to verify that the remote helper program is available, before finalizing the transport setup. If the remote helper is NOT available, transport_helper_init() returns -1, and transport_get() falls back to trying a native transport.

This patch introduces a subtle, but important change in the handling of remotes and their URLs:

Before this patch, we only invoke transport_helper_init() _after_ we find that the transport-helper mechanism is appropriate for this remote (i.e. the remote is "foreign", or is handled by the curl helper).

This patch moves the decision point into transport_helper_init(): If the remote is not obviously using a native transport (URL starts with "file:", "git:" or "ssh:"), then we first call transport_helper_init(), and only if it returns error (meaning that no appropriate remote helper program was found) do we fall back to native transport handling.

Signed-off-by: Johan Herland <johan@herland.net>
---
 transport-helper.c |   22 ++++++++++++++++++++--
 transport.c        |   11 ++++++-----
 2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/transport-helper.c b/transport-helper.c
index d3ce984..de30727 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -5,6 +5,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
+#include "help.h"
 
 struct helper_data
 {
@@ -279,11 +280,18 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, cons
 
 int transport_helper_init(struct transport *transport)
 {
-	struct helper_data *data = xcalloc(sizeof(*data), 1);
+	struct helper_data *data;
+	struct strbuf buf = STRBUF_INIT;
+	char *cmd;
+
+	if (!transport->remote)
+		return -1;
 
+	data = xcalloc(sizeof(*data), 1);
 	if (transport->remote->foreign_vcs) {
 		data->name = xstrdup(transport->remote->foreign_vcs);
-		transport->url = transport->remote->foreign_vcs;
+		if (!transport->url)
+			transport->url = transport->remote->foreign_vcs;
 	} else {
 		char *eom = strchr(transport->url, ':');
 		if (!eom) {
@@ -293,6 +301,16 @@ int transport_helper_init(struct transport *transport)
 		data->name = xstrndup(transport->url, eom - transport->url);
 	}
 
+	strbuf_addf(&buf, "remote-%s", data->name);
+	cmd = strbuf_detach(&buf, NULL);
+	if (!is_git_command_or_alias(cmd)) {
+		warning("Could not find remote helper command \"git %s\". Assuming native remote.", cmd);
+		free(cmd);
+		free(data->name);
+		free(data);
+		return -1;
+	}
+
 	transport->data = data;
 	transport->get_refs_list = get_refs_list;
 	transport->fetch = fetch;
diff --git a/transport.c b/transport.c
index 81a28bc..b7033eb 100644
--- a/transport.c
+++ b/transport.c
@@ -794,11 +794,12 @@ struct transport *transport_get(struct remote *remote, const char *url)
 		ret->fetch = fetch_objs_via_rsync;
 		ret->push = rsync_transport_push;
 
-	} else if (!url
-	        || !prefixcmp(url, "http://")
-	        || !prefixcmp(url, "https://")
-	        || !prefixcmp(url, "ftp://")) {
-		transport_helper_init(ret);
+	} else if ((!url
+	         || (prefixcmp(url, "git:")
+	          && prefixcmp(url, "ssh:")
+	          && prefixcmp(url, "file:")))
+	        && !transport_helper_init(ret)) {
+		/* no-op, ret is initialized by transport_helper_init() */
 
 	} else if (url && is_local(url) && is_file(url)) {
 		struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
-- 
1.6.4.rc3.138.ga6b98.dirty
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 16 of 35 in “Add a config option for remotes to specify a foreign vcs”
  1. 5/8 Add a config option for remotes to specify a foreign vcsDaniel Barkalow, Aug 9, 2009
  2. Johannes SchindelinAug 9, 2009
  3. Junio C HamanoAug 10, 2009
  4. Daniel BarkalowAug 10, 2009
  5. Johan HerlandAug 10, 2009
  6. Daniel BarkalowAug 10, 2009
  7. 0/6 Graceful handling of missing remote helpersJohan Herland, Aug 11, 2009
  8. 1/6 Minor unrelated fixesJohan Herland, Aug 11, 2009
  9. 2/6 transport_get(): Don't SEGFAULT on missing urlJohan Herland, Aug 11, 2009
  10. Junio C HamanoAug 12, 2009
  11. Johan HerlandAug 12, 2009
  12. 3/6 Move setup of curl remote helper from transport.c to transport-helper.cJohan Herland, Aug 11, 2009
  13. Johannes SchindelinAug 11, 2009
  14. 4/6 Add is_git_command_or_alias() for checking availability of a given git commandJohan Herland, Aug 11, 2009
  15. Johannes SchindelinAug 11, 2009
  16. 5/6 Let transport_helper_init() decide if a remote helper program can be usedJohan Herland, Aug 11, 2009
  17. Johannes SchindelinAug 11, 2009
  18. Daniel BarkalowAug 11, 2009
  19. Jeff KingAug 12, 2009
  20. Daniel BarkalowAug 12, 2009
  21. 6/6 Add testcase to verify handling of missing remote helper programsJohan Herland, Aug 11, 2009
  22. Junio C HamanoAug 11, 2009
  23. Johannes SchindelinAug 11, 2009
  24. Junio C HamanoAug 10, 2009
  25. Bert WesargAug 11, 2009
  26. Johannes SchindelinAug 11, 2009
  27. Jeff KingAug 11, 2009
  28. Johannes SchindelinAug 11, 2009
  29. Jeff KingAug 12, 2009
  30. Jakub NarebskiAug 12, 2009
  31. Junio C HamanoAug 12, 2009
  32. Jakub NarebskiAug 13, 2009
  33. Jeff KingAug 11, 2009
  34. Johannes SchindelinAug 12, 2009
  35. Junio C HamanoAug 12, 2009

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.