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

[PATCH] git-proxy updates.

From
Junio C Hamano <junkio@cox.net>
Date
Nov 19, 2005, 12:13 UTC
Message-ID
<7vd5kw6djy.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<871x1wbgvn.fsf_-_@briny.internal.ondioline.org>
Paul Collins <paul@briny.ondioline.org> writes:
> Here is an updated patch that first looks for GIT_PROXY_COMMAND in the
> environment and then git.proxycommand in the repository's
> configuration file.

Sorry for holding onto your patch without any action (other than looking at it, which from your end you cannot tell I was doing ;-). I think we will benefit from your patch in some form, and here is what I tried on top to update it to the multivalue configuration syntax Linus suggested during the list discussion. Requesting for comments the original author and from the general public.

I suspect this touches the same area as the user-path series Andreas Ericsson has been working on, so it might need some adjusting after that patch series goes in. I'll see that soon enough when I make the proposed updates branch tomorrow.

 -- >8 --

This builds on top of the git-proxy mechanism Paul Collins did, and updates its configuration mechanism.

 * GIT_PROXY_COMMAND environment variable is used as the
   catch-all fallback, as in the original.  This has not
   changed.
 * Renames proxy configuration variables to core.gitproxy; this
   has become a multi-value variable per list discussion, most
   notably from suggestion by Linus.
	[core]
	;# matches www.kernel.org as well
	gitproxy = netcatter for kernel.org
	gitproxy = netscatter for sample.xz
	gitproxy = none for mydomain.xz
	gitproxy = netcatter-default
   The values are command names, followed by an optional " for "
   and domainname; the first tail-match of the domainname
   determines which proxy command is used.  An entry without "
   for " matches any domain and can be used as the default.
   The command name "none" is special -- it tells the mechanism
   not to use any proxy command and use the native git://
   connection.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 connect.c |   52 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 45 insertions(+), 7 deletions(-)

applies-to: d4a5ace05fd892cb455f330d379cdaa69dc6005c c1d7ac7b4680202d3549a72188f372367ac8837c

diff --git a/connect.c b/connect.c
index 43eec67..11a804f 100644
--- a/connect.c
+++ b/connect.c
@@ -449,25 +449,63 @@ static int git_tcp_connect(int fd[2], co
 #endif /* NO_IPV6 */
 
 static char *git_proxy_command = NULL;
+static const char *rhost_name = NULL;
+static int rhost_len;
 
 static int git_proxy_command_options(const char *var, const char *value)
 {
-	if (git_proxy_command == NULL) {
-		if (!strcmp(var, "git.proxycommand")) {
-			git_proxy_command = xmalloc(strlen(value) + 1);
-			strcpy(git_proxy_command, value);
+	if (!strcmp(var, "core.gitproxy")) {
+		if (git_proxy_command)
 			return 0;
+		/* [core]
+		 * ;# matches www.kernel.org as well
+		 * gitproxy = netcatter-1 for kernel.org
+		 * gitproxy = netcatter-2 for sample.xz
+		 * gitproxy = netcatter-default
+		 */
+		const char *for_pos = strstr(value, " for ");
+		int matchlen = -1;
+		int hostlen;
+
+		if (!for_pos)
+			/* matches everybody */
+			matchlen = strlen(value);
+		else {
+			hostlen = strlen(for_pos + 5);
+			if (rhost_len < hostlen)
+				matchlen = -1;
+			else if (!strncmp(for_pos + 5,
+					  rhost_name + rhost_len - hostlen,
+					  hostlen) &&
+				 ((rhost_len == hostlen) ||
+				  rhost_name[rhost_len - hostlen -1] == '.'))
+				matchlen = for_pos - value;
+			else
+				matchlen = -1;
+		}
+		if (0 <= matchlen) {
+			/* core.gitproxy = none for kernel.org */
+			if (matchlen == 4 && 
+			    !memcmp(value, "none", 4))
+				matchlen = 0;
+			git_proxy_command = xmalloc(matchlen + 1);
+			memcpy(git_proxy_command, value, matchlen);
+			git_proxy_command[matchlen] = 0;
 		}
+		return 0;
 	}
 
 	return git_default_config(var, value);
 }
 
-static int git_use_proxy(void)
+static int git_use_proxy(const char *host)
 {
+	rhost_name = host;
+	rhost_len = strlen(host);
 	git_proxy_command = getenv("GIT_PROXY_COMMAND");
 	git_config(git_proxy_command_options);
-	return git_proxy_command != NULL;
+	rhost_name = NULL;
+	return (git_proxy_command && *git_proxy_command);
 }
 
 static int git_proxy_connect(int fd[2], const char *prog, char *host, char *path)
@@ -550,7 +588,7 @@ int git_connect(int fd[2], char *url, co
 	}
 
 	if (protocol == PROTO_GIT) {
-		if (git_use_proxy())
+		if (git_use_proxy(host))
 			return git_proxy_connect(fd, prog, host, path);
 		return git_tcp_connect(fd, prog, host, path);
 	}
---
0.99.9.GIT
 
Previous: Linus Torvalds
Message 13 of 13 in “RFC: proxy-command support for git://”
  1. RFC: proxy-command support for git://Paul Collins, Nov 3, 2005
  2. Junio C HamanoNov 3, 2005
  3. Linus TorvaldsNov 3, 2005
  4. Carl BaldwinNov 3, 2005
  5. Junio C HamanoNov 3, 2005
  6. Paul CollinsNov 4, 2005
  7. Junio C HamanoNov 4, 2005
  8. Junio C HamanoNov 4, 2005
  9. Paul CollinsNov 4, 2005
  10. Junio C HamanoNov 4, 2005
  11. Paul CollinsNov 4, 2005
  12. Linus TorvaldsNov 4, 2005
  13. git-proxy updates.Junio C Hamano, Nov 19, 2005

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.