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

[PATCH 4/4] git_connect: add a flag to consider the path part of ssh urls relative

From
Mike Hommey <mh@glandium.org>
Date
Apr 28, 2016, 14:12 UTC
Message-ID
<1461852759-28429-5-git-send-email-mh@glandium.org>
In-Reply-To
<1461852759-28429-1-git-send-email-mh@glandium.org>

In Mercurial ssh urls, the path part of the url is relative to the home directory of the account being logged to instead of being absolute.

Add a flag allowing git_connect() to handle this kind of usecase.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
 connect.c | 10 +++++++---
 connect.h |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/connect.c b/connect.c
index 9feedd8..0df6297 100644
--- a/connect.c
+++ b/connect.c
@@ -592,7 +592,7 @@ static char *get_port(char *host)
  * The caller must free() the returned strings.
  */
 static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
-				       char **ret_path)
+				       char **ret_path, int relative_ssh)
 {
 	char *url;
 	char *host, *path;
@@ -642,7 +642,10 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
 	end = path; /* Need to \0 terminate host here */
 	if (separator == ':')
 		path++; /* path starts after ':' */
-	if (protocol == PROTO_GIT || protocol == PROTO_SSH) {
+	if (protocol == PROTO_SSH && relative_ssh) {
+		if (path[0] == separator)
+			path++;
+	} else if (protocol == PROTO_GIT || protocol == PROTO_SSH) {
 		if (path[1] == '~')
 			path++;
 	}
@@ -712,7 +715,8 @@ struct child_process *git_connect(int fd[2], const char *url,
 	 */
 	signal(SIGCHLD, SIG_DFL);
 
-	protocol = parse_connect_url(url, &hostandport, &path);
+	protocol = parse_connect_url(url, &hostandport, &path,
+	                             flags & CONNECT_RELATIVE_SSH);
 	if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
 		printf("Diag: url=%s\n", url ? url : "NULL");
 		printf("Diag: protocol=%s\n", prot_name(protocol));
diff --git a/connect.h b/connect.h
index fb3331b..1377028 100644
--- a/connect.h
+++ b/connect.h
@@ -6,6 +6,7 @@
 #define CONNECT_IPV4          (1u << 2)
 #define CONNECT_IPV6          (1u << 3)
 #define CONNECT_WANT_STDERR   (1u << 4)
+#define CONNECT_RELATIVE_SSH  (1u << 5)
 extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
 extern int finish_connect(struct child_process *conn);
 extern int git_connection_is_socket(struct child_process *conn);
-- 
2.8.1.5.g18c8a48
Previous: Mike HommeyNext: Junio C Hamano
Message 6 of 15 in “git_connect: add some flexibility”
  1. 0/4 git_connect: add some flexibilityMike Hommey, Apr 28, 2016
  2. 1/4 git_connect: extend to take a pseudo format string for the program to runMike Hommey, Apr 28, 2016
  3. 2/4 git_connect: avoid quoting the path on the command line when it's not necessaryMike Hommey, Apr 28, 2016
  4. Stefan BellerApr 28, 2016
  5. 3/4 git_connect: allow a file descriptor to be allocated for stderrMike Hommey, Apr 28, 2016
  6. 4/4 git_connect: add a flag to consider the path part of ssh urls relativeMike Hommey, Apr 28, 2016
  7. Junio C HamanoApr 28, 2016
  8. Mike HommeyApr 28, 2016
  9. 1/3 connect: make parse_connect_url publicMike Hommey, Apr 29, 2016
  10. 2/3 connect: group CONNECT_DIAG_URL handling codeMike Hommey, Apr 29, 2016
  11. Junio C HamanoApr 29, 2016
  12. Junio C HamanoApr 29, 2016
  13. Torsten BögershausenApr 29, 2016
  14. 3/3 connect: move ssh command line preparation to a separate (public) functionMike Hommey, Apr 29, 2016
  15. Junio C HamanoApr 29, 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.