Skip to content

Commit 3d3c4f5

Browse files
committed
Re-fix ls-remote
An earlier attempt in 2ea7fe0 (ls-remote: resurrect pattern limit support) forgot that the user string can also be a glob. This should finally fix it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cc3530e commit 3d3c4f5

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

builtin-ls-remote.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@ static const char ls_remote_usage[] =
77
"git-ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
88

99
/*
10-
* pattern is a list of tail-part of accepted refnames. Is there one
11-
* among them that is a suffix of the path? Directory boundary must
12-
* be honored when checking this match. IOW, patterns "master" and
13-
* "sa/master" both match path "refs/hold/sa/master". On the other
14-
* hand, path "refs/hold/foosa/master" is matched by "master" but not
15-
* by "sa/master".
10+
* Is there one among the list of patterns that match the tail part
11+
* of the path?
1612
*/
17-
1813
static int tail_match(const char **pattern, const char *path)
1914
{
20-
int pathlen;
2115
const char *p;
16+
char pathbuf[PATH_MAX];
2217

23-
if (!*pattern)
18+
if (!pattern)
2419
return 1; /* no restriction */
2520

26-
for (pathlen = strlen(path); (p = *pattern); pattern++) {
27-
int pfxlen = pathlen - strlen(p);
28-
if (pfxlen < 0)
29-
continue; /* pattern is longer, will never match */
30-
if (strcmp(path + pfxlen, p))
31-
continue; /* no tail match */
32-
if (!pfxlen || path[pfxlen - 1] == '/')
33-
return 1; /* fully match at directory boundary */
21+
if (snprintf(pathbuf, sizeof(pathbuf), "/%s", path) > sizeof(pathbuf))
22+
return error("insanely long ref %.*s...", 20, path);
23+
while ((p = *(pattern++)) != NULL) {
24+
if (!fnmatch(p, pathbuf, 0))
25+
return 1;
3426
}
3527
return 0;
3628
}
@@ -77,12 +69,23 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
7769
usage(ls_remote_usage);
7870
}
7971
dest = arg;
72+
i++;
8073
break;
8174
}
8275

8376
if (!dest)
8477
usage(ls_remote_usage);
85-
pattern = argv + i + 1;
78+
79+
if (argv[i]) {
80+
int j;
81+
pattern = xcalloc(sizeof(const char *), argc - i + 1);
82+
for (j = i; j < argc; j++) {
83+
int len = strlen(argv[j]);
84+
char *p = xmalloc(len + 3);
85+
sprintf(p, "*/%s", argv[j]);
86+
pattern[j - i] = p;
87+
}
88+
}
8689
remote = nongit ? NULL : remote_get(dest);
8790
if (remote && !remote->url_nr)
8891
die("remote %s has no configured URL", dest);

0 commit comments

Comments
 (0)