Skip to content

Commit 7a5638a

Browse files
committed
Merge branch 'jk/fetch-no-tail-match-refs' into maint
* jk/fetch-no-tail-match-refs: connect.c: drop path_match function fetch-pack: match refs exactly t5500: give fully-qualified refs to fetch-pack drop "match" parameter from get_remote_heads
2 parents 2cb1ff9 + bab8d28 commit 7a5638a

File tree

8 files changed

+48
-41
lines changed

8 files changed

+48
-41
lines changed

builtin/fetch-pack.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,16 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
556556
continue;
557557
}
558558
else {
559-
int order = path_match(ref->name, nr_match, match);
560-
if (order) {
561-
return_refs[order-1] = ref;
562-
continue; /* we will link it later */
559+
int i;
560+
for (i = 0; i < nr_match; i++) {
561+
if (!strcmp(ref->name, match[i])) {
562+
match[i][0] = '\0';
563+
return_refs[i] = ref;
564+
break;
565+
}
563566
}
567+
if (i < nr_match)
568+
continue; /* we will link it later */
564569
}
565570
free(ref);
566571
}
@@ -976,7 +981,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
976981
args.verbose ? CONNECT_VERBOSE : 0);
977982
}
978983

979-
get_remote_heads(fd[0], &ref, 0, NULL, 0, NULL);
984+
get_remote_heads(fd[0], &ref, 0, NULL);
980985

981986
ref = fetch_pack(&args, fd, conn, ref, dest,
982987
nr_heads, heads, pack_lockfile_ptr);

builtin/send-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
494494

495495
memset(&extra_have, 0, sizeof(extra_have));
496496

497-
get_remote_heads(fd[0], &remote_refs, 0, NULL, REF_NORMAL,
498-
&extra_have);
497+
get_remote_heads(fd[0], &remote_refs, REF_NORMAL, &extra_have);
499498

500499
transport_verify_remote_names(nr_refspecs, refspecs);
501500

cache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,11 @@ extern char *git_getpass(const char *prompt);
10281028
extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
10291029
extern int finish_connect(struct child_process *conn);
10301030
extern int git_connection_is_socket(struct child_process *conn);
1031-
extern int path_match(const char *path, int nr, char **match);
10321031
struct extra_have_objects {
10331032
int nr, alloc;
10341033
unsigned char (*array)[20];
10351034
};
1036-
extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags, struct extra_have_objects *);
1035+
extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *);
10371036
extern int server_supports(const char *feature);
10381037

10391038
extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);

connect.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1
5353
* Read all the refs from the other end
5454
*/
5555
struct ref **get_remote_heads(int in, struct ref **list,
56-
int nr_match, char **match,
5756
unsigned int flags,
5857
struct extra_have_objects *extra_have)
5958
{
@@ -92,8 +91,6 @@ struct ref **get_remote_heads(int in, struct ref **list,
9291

9392
if (!check_ref(name, name_len, flags))
9493
continue;
95-
if (nr_match && !path_match(name, nr_match, match))
96-
continue;
9794
ref = alloc_ref(buffer + 41);
9895
hashcpy(ref->old_sha1, old_sha1);
9996
*list = ref;
@@ -108,27 +105,6 @@ int server_supports(const char *feature)
108105
strstr(server_capabilities, feature) != NULL;
109106
}
110107

111-
int path_match(const char *path, int nr, char **match)
112-
{
113-
int i;
114-
int pathlen = strlen(path);
115-
116-
for (i = 0; i < nr; i++) {
117-
char *s = match[i];
118-
int len = strlen(s);
119-
120-
if (!len || len > pathlen)
121-
continue;
122-
if (memcmp(path + pathlen - len, s, len))
123-
continue;
124-
if (pathlen > len && path[pathlen - len - 1] != '/')
125-
continue;
126-
*s = 0;
127-
return (i + 1);
128-
}
129-
return 0;
130-
}
131-
132108
enum protocol {
133109
PROTO_LOCAL = 1,
134110
PROTO_SSH,

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static struct ref *parse_git_refs(struct discovery *heads)
200200

201201
if (start_async(&async))
202202
die("cannot start thread to parse advertised refs");
203-
get_remote_heads(async.out, &list, 0, NULL, 0, NULL);
203+
get_remote_heads(async.out, &list, 0, NULL);
204204
close(async.out);
205205
if (finish_async(&async))
206206
die("ref parsing thread failed");

t/t5500-fetch-pack.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ test_expect_success 'setup' '
9797
git symbolic-ref HEAD refs/heads/B
9898
'
9999

100-
pull_to_client 1st "B A" $((11*3))
100+
pull_to_client 1st "refs/heads/B refs/heads/A" $((11*3))
101101

102102
test_expect_success 'post 1st pull setup' '
103103
add A11 $A10 &&
@@ -110,9 +110,9 @@ test_expect_success 'post 1st pull setup' '
110110
done
111111
'
112112

113-
pull_to_client 2nd "B" $((64*3))
113+
pull_to_client 2nd "refs/heads/B" $((64*3))
114114

115-
pull_to_client 3rd "A" $((1*3))
115+
pull_to_client 3rd "refs/heads/A" $((1*3))
116116

117117
test_expect_success 'clone shallow' '
118118
git clone --depth 2 "file://$(pwd)/." shallow

t/t5527-fetch-odd-refs.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
test_description='test fetching of oddly-named refs'
4+
. ./test-lib.sh
5+
6+
# afterwards we will have:
7+
# HEAD - two
8+
# refs/for/refs/heads/master - one
9+
# refs/heads/master - three
10+
test_expect_success 'setup repo with odd suffix ref' '
11+
echo content >file &&
12+
git add . &&
13+
git commit -m one &&
14+
git update-ref refs/for/refs/heads/master HEAD &&
15+
echo content >>file &&
16+
git commit -a -m two &&
17+
echo content >>file &&
18+
git commit -a -m three &&
19+
git checkout HEAD^
20+
'
21+
22+
test_expect_success 'suffix ref is ignored during fetch' '
23+
git clone --bare file://"$PWD" suffix &&
24+
echo three >expect &&
25+
git --git-dir=suffix log -1 --format=%s refs/heads/master >actual &&
26+
test_cmp expect actual
27+
'
28+
29+
test_done

transport.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
502502
struct ref *refs;
503503

504504
connect_setup(transport, for_push, 0);
505-
get_remote_heads(data->fd[0], &refs, 0, NULL,
505+
get_remote_heads(data->fd[0], &refs,
506506
for_push ? REF_NORMAL : 0, &data->extra_have);
507507
data->got_remote_heads = 1;
508508

@@ -537,7 +537,7 @@ static int fetch_refs_via_pack(struct transport *transport,
537537

538538
if (!data->got_remote_heads) {
539539
connect_setup(transport, 0, 0);
540-
get_remote_heads(data->fd[0], &refs_tmp, 0, NULL, 0, NULL);
540+
get_remote_heads(data->fd[0], &refs_tmp, 0, NULL);
541541
data->got_remote_heads = 1;
542542
}
543543

@@ -772,8 +772,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
772772
struct ref *tmp_refs;
773773
connect_setup(transport, 1, 0);
774774

775-
get_remote_heads(data->fd[0], &tmp_refs, 0, NULL, REF_NORMAL,
776-
NULL);
775+
get_remote_heads(data->fd[0], &tmp_refs, REF_NORMAL, NULL);
777776
data->got_remote_heads = 1;
778777
}
779778

0 commit comments

Comments
 (0)