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)
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
}