@matheusbsbs / matheus-bagliano / commits / e814bc4d15
Fork 0

git-proxy updates.

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>

Junio C Hamano committed Nov 19, 2005 at 03:48 UTC e814bc4d159f62941fafe135c3008b3ff103444d
1 file changed +45 -7
connect.c
+45 -7
@@ -449,25 +449,63 @@ static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
449 #endif /* NO_IPV6 */
450
451 static char *git_proxy_command = NULL;
452 +static const char *rhost_name = NULL;
453 +static int rhost_len;
454
455 static int git_proxy_command_options(const char *var, const char *value)
456 {
455 - if (git_proxy_command == NULL) {
456 - if (!strcmp(var, "git.proxycommand")) {
457 - git_proxy_command = xmalloc(strlen(value) + 1);
458 - strcpy(git_proxy_command, value);
457 + if (!strcmp(var, "core.gitproxy")) {
458 + if (git_proxy_command)
459 return 0;
460 + /* [core]
461 + * ;# matches www.kernel.org as well
462 + * gitproxy = netcatter-1 for kernel.org
463 + * gitproxy = netcatter-2 for sample.xz
464 + * gitproxy = netcatter-default
465 + */
466 + const char *for_pos = strstr(value, " for ");
467 + int matchlen = -1;
468 + int hostlen;
469 +
470 + if (!for_pos)
471 + /* matches everybody */
472 + matchlen = strlen(value);
473 + else {
474 + hostlen = strlen(for_pos + 5);
475 + if (rhost_len < hostlen)
476 + matchlen = -1;
477 + else if (!strncmp(for_pos + 5,
478 + rhost_name + rhost_len - hostlen,
479 + hostlen) &&
480 + ((rhost_len == hostlen) ||
481 + rhost_name[rhost_len - hostlen -1] == '.'))
482 + matchlen = for_pos - value;
483 + else
484 + matchlen = -1;
485 }
486 + if (0 <= matchlen) {
487 + /* core.gitproxy = none for kernel.org */
488 + if (matchlen == 4 &&
489 + !memcmp(value, "none", 4))
490 + matchlen = 0;
491 + git_proxy_command = xmalloc(matchlen + 1);
492 + memcpy(git_proxy_command, value, matchlen);
493 + git_proxy_command[matchlen] = 0;
494 + }
495 + return 0;
496 }
497
498 return git_default_config(var, value);
499 }
500
466 -static int git_use_proxy(void)
501 +static int git_use_proxy(const char *host)
502 {
503 + rhost_name = host;
504 + rhost_len = strlen(host);
505 git_proxy_command = getenv("GIT_PROXY_COMMAND");
506 git_config(git_proxy_command_options);
470 - return git_proxy_command != NULL;
507 + rhost_name = NULL;
508 + return (git_proxy_command && *git_proxy_command);
509 }
510
511 static int git_proxy_connect(int fd[2], const char *prog, char *host, char *path)
@@ -561,7 +599,7 @@ int git_connect(int fd[2], char *url, const char *prog)
599 }
600
601 if (protocol == PROTO_GIT) {
564 - if (git_use_proxy())
602 + if (git_use_proxy(host))
603 return git_proxy_connect(fd, prog, host, path);
604 return git_tcp_connect(fd, prog, host, path);
605 }