Merge branch 'jk/fetch-no-tail-match-refs'

* 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
This commit is contained in:
Junio C Hamano 2011-12-19 16:05:55 -08:00
commit b3ae9d8e57
8 changed files with 48 additions and 41 deletions

View File

@ -556,11 +556,16 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
continue;
}
else {
int order = path_match(ref->name, nr_match, match);
if (order) {
return_refs[order-1] = ref;
continue; /* we will link it later */
int i;
for (i = 0; i < nr_match; i++) {
if (!strcmp(ref->name, match[i])) {
match[i][0] = '\0';
return_refs[i] = ref;
break;
}
}
if (i < nr_match)
continue; /* we will link it later */
}
free(ref);
}
@ -976,7 +981,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
args.verbose ? CONNECT_VERBOSE : 0);
}
get_remote_heads(fd[0], &ref, 0, NULL, 0, NULL);
get_remote_heads(fd[0], &ref, 0, NULL);
ref = fetch_pack(&args, fd, conn, ref, dest,
nr_heads, heads, pack_lockfile_ptr);

View File

@ -494,8 +494,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
memset(&extra_have, 0, sizeof(extra_have));
get_remote_heads(fd[0], &remote_refs, 0, NULL, REF_NORMAL,
&extra_have);
get_remote_heads(fd[0], &remote_refs, REF_NORMAL, &extra_have);
transport_verify_remote_names(nr_refspecs, refspecs);

View File

@ -1032,12 +1032,11 @@ extern char *git_getpass(const char *prompt);
extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
extern int finish_connect(struct child_process *conn);
extern int git_connection_is_socket(struct child_process *conn);
extern int path_match(const char *path, int nr, char **match);
struct extra_have_objects {
int nr, alloc;
unsigned char (*array)[20];
};
extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags, struct extra_have_objects *);
extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *);
extern int server_supports(const char *feature);
extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);

View File

@ -53,7 +53,6 @@ static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1
* Read all the refs from the other end
*/
struct ref **get_remote_heads(int in, struct ref **list,
int nr_match, char **match,
unsigned int flags,
struct extra_have_objects *extra_have)
{
@ -92,8 +91,6 @@ struct ref **get_remote_heads(int in, struct ref **list,
if (!check_ref(name, name_len, flags))
continue;
if (nr_match && !path_match(name, nr_match, match))
continue;
ref = alloc_ref(buffer + 41);
hashcpy(ref->old_sha1, old_sha1);
*list = ref;
@ -108,27 +105,6 @@ int server_supports(const char *feature)
strstr(server_capabilities, feature) != NULL;
}
int path_match(const char *path, int nr, char **match)
{
int i;
int pathlen = strlen(path);
for (i = 0; i < nr; i++) {
char *s = match[i];
int len = strlen(s);
if (!len || len > pathlen)
continue;
if (memcmp(path + pathlen - len, s, len))
continue;
if (pathlen > len && path[pathlen - len - 1] != '/')
continue;
*s = 0;
return (i + 1);
}
return 0;
}
enum protocol {
PROTO_LOCAL = 1,
PROTO_SSH,

View File

@ -200,7 +200,7 @@ static struct ref *parse_git_refs(struct discovery *heads)
if (start_async(&async))
die("cannot start thread to parse advertised refs");
get_remote_heads(async.out, &list, 0, NULL, 0, NULL);
get_remote_heads(async.out, &list, 0, NULL);
close(async.out);
if (finish_async(&async))
die("ref parsing thread failed");

View File

@ -97,7 +97,7 @@ test_expect_success 'setup' '
git symbolic-ref HEAD refs/heads/B
'
pull_to_client 1st "B A" $((11*3))
pull_to_client 1st "refs/heads/B refs/heads/A" $((11*3))
test_expect_success 'post 1st pull setup' '
add A11 $A10 &&
@ -110,9 +110,9 @@ test_expect_success 'post 1st pull setup' '
done
'
pull_to_client 2nd "B" $((64*3))
pull_to_client 2nd "refs/heads/B" $((64*3))
pull_to_client 3rd "A" $((1*3))
pull_to_client 3rd "refs/heads/A" $((1*3))
test_expect_success 'clone shallow' '
git clone --depth 2 "file://$(pwd)/." shallow

29
t/t5527-fetch-odd-refs.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
test_description='test fetching of oddly-named refs'
. ./test-lib.sh
# afterwards we will have:
# HEAD - two
# refs/for/refs/heads/master - one
# refs/heads/master - three
test_expect_success 'setup repo with odd suffix ref' '
echo content >file &&
git add . &&
git commit -m one &&
git update-ref refs/for/refs/heads/master HEAD &&
echo content >>file &&
git commit -a -m two &&
echo content >>file &&
git commit -a -m three &&
git checkout HEAD^
'
test_expect_success 'suffix ref is ignored during fetch' '
git clone --bare file://"$PWD" suffix &&
echo three >expect &&
git --git-dir=suffix log -1 --format=%s refs/heads/master >actual &&
test_cmp expect actual
'
test_done

View File

@ -502,7 +502,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
struct ref *refs;
connect_setup(transport, for_push, 0);
get_remote_heads(data->fd[0], &refs, 0, NULL,
get_remote_heads(data->fd[0], &refs,
for_push ? REF_NORMAL : 0, &data->extra_have);
data->got_remote_heads = 1;
@ -537,7 +537,7 @@ static int fetch_refs_via_pack(struct transport *transport,
if (!data->got_remote_heads) {
connect_setup(transport, 0, 0);
get_remote_heads(data->fd[0], &refs_tmp, 0, NULL, 0, NULL);
get_remote_heads(data->fd[0], &refs_tmp, 0, NULL);
data->got_remote_heads = 1;
}
@ -772,8 +772,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
struct ref *tmp_refs;
connect_setup(transport, 1, 0);
get_remote_heads(data->fd[0], &tmp_refs, 0, NULL, REF_NORMAL,
NULL);
get_remote_heads(data->fd[0], &tmp_refs, REF_NORMAL, NULL);
data->got_remote_heads = 1;
}