Merge branch 'cb/match_refs_internal_tail'

* cb/match_refs_internal_tail:
  match_refs: search ref list tail internally
This commit is contained in:
Junio C Hamano 2009-06-13 12:47:52 -07:00
Родитель 49c7e4643b 6d2bf96e55
Коммит 57c57a97e1
6 изменённых файлов: 23 добавлений и 29 удалений

Просмотреть файл

@ -295,17 +295,14 @@ static int get_push_ref_states(const struct ref *remote_refs,
struct ref_states *states) struct ref_states *states)
{ {
struct remote *remote = states->remote; struct remote *remote = states->remote;
struct ref *ref, *local_refs, *push_map, **push_tail; struct ref *ref, *local_refs, *push_map;
if (remote->mirror) if (remote->mirror)
return 0; return 0;
local_refs = get_local_heads(); local_refs = get_local_heads();
push_map = copy_ref_list(remote_refs); push_map = copy_ref_list(remote_refs);
push_tail = &push_map; match_refs(local_refs, &push_map, remote->push_refspec_nr,
while (*push_tail)
push_tail = &((*push_tail)->next);
match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr,
remote->push_refspec, MATCH_REFS_NONE); remote->push_refspec, MATCH_REFS_NONE);
states->push.strdup_strings = 1; states->push.strdup_strings = 1;

Просмотреть файл

@ -473,7 +473,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
int fd[2]; int fd[2];
struct child_process *conn; struct child_process *conn;
struct extra_have_objects extra_have; struct extra_have_objects extra_have;
struct ref *remote_refs, **remote_tail, *local_refs; struct ref *remote_refs, *local_refs;
int ret; int ret;
int send_all = 0; int send_all = 0;
const char *receivepack = "git-receive-pack"; const char *receivepack = "git-receive-pack";
@ -567,13 +567,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
flags |= MATCH_REFS_MIRROR; flags |= MATCH_REFS_MIRROR;
/* match them up */ /* match them up */
remote_tail = &remote_refs; if (match_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags))
while (*remote_tail)
remote_tail = &((*remote_tail)->next);
if (match_refs(local_refs, remote_refs, &remote_tail,
nr_refspecs, refspecs, flags)) {
return -1; return -1;
}
ret = send_pack(&args, fd, conn, remote_refs, &extra_have); ret = send_pack(&args, fd, conn, remote_refs, &extra_have);

Просмотреть файл

@ -1844,7 +1844,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
return 1; return 1;
} }
static struct ref *remote_refs, **remote_tail; static struct ref *remote_refs;
static void one_remote_ref(char *refname) static void one_remote_ref(char *refname)
{ {
@ -1874,13 +1874,12 @@ static void one_remote_ref(char *refname)
} }
} }
*remote_tail = ref; ref->next = remote_refs;
remote_tail = &ref->next; remote_refs = ref;
} }
static void get_dav_remote_heads(void) static void get_dav_remote_heads(void)
{ {
remote_tail = &remote_refs;
remote_ls("refs/", (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL); remote_ls("refs/", (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL);
} }
@ -2300,9 +2299,7 @@ int main(int argc, char **argv)
} }
/* match them up */ /* match them up */
if (!remote_tail) if (match_refs(local_refs, &remote_refs,
remote_tail = &remote_refs;
if (match_refs(local_refs, remote_refs, &remote_tail,
nr_refspec, (const char **) refspec, push_all)) { nr_refspec, (const char **) refspec, push_all)) {
rc = -1; rc = -1;
goto cleanup; goto cleanup;

Просмотреть файл

@ -1085,12 +1085,20 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,
return NULL; return NULL;
} }
static struct ref **tail_ref(struct ref **head)
{
struct ref **tail = head;
while (*tail)
tail = &((*tail)->next);
return tail;
}
/* /*
* Note. This is used only by "push"; refspec matching rules for * Note. This is used only by "push"; refspec matching rules for
* push and fetch are subtly different, so do not try to reuse it * push and fetch are subtly different, so do not try to reuse it
* without thinking. * without thinking.
*/ */
int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, int match_refs(struct ref *src, struct ref **dst,
int nr_refspec, const char **refspec, int flags) int nr_refspec, const char **refspec, int flags)
{ {
struct refspec *rs; struct refspec *rs;
@ -1098,13 +1106,14 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
int send_mirror = flags & MATCH_REFS_MIRROR; int send_mirror = flags & MATCH_REFS_MIRROR;
int errs; int errs;
static const char *default_refspec[] = { ":", 0 }; static const char *default_refspec[] = { ":", 0 };
struct ref **dst_tail = tail_ref(dst);
if (!nr_refspec) { if (!nr_refspec) {
nr_refspec = 1; nr_refspec = 1;
refspec = default_refspec; refspec = default_refspec;
} }
rs = parse_push_refspec(nr_refspec, (const char **) refspec); rs = parse_push_refspec(nr_refspec, (const char **) refspec);
errs = match_explicit_refs(src, dst, dst_tail, rs, nr_refspec); errs = match_explicit_refs(src, *dst, &dst_tail, rs, nr_refspec);
/* pick the remainder */ /* pick the remainder */
for ( ; src; src = src->next) { for ( ; src; src = src->next) {
@ -1134,7 +1143,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
dst_side, &dst_name)) dst_side, &dst_name))
die("Didn't think it matches any more"); die("Didn't think it matches any more");
} }
dst_peer = find_ref_by_name(dst, dst_name); dst_peer = find_ref_by_name(*dst, dst_name);
if (dst_peer) { if (dst_peer) {
if (dst_peer->peer_ref) if (dst_peer->peer_ref)
/* We're already sending something to this ref. */ /* We're already sending something to this ref. */
@ -1150,7 +1159,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
goto free_name; goto free_name;
/* Create a new one and link it */ /* Create a new one and link it */
dst_peer = make_linked_ref(dst_name, dst_tail); dst_peer = make_linked_ref(dst_name, &dst_tail);
hashcpy(dst_peer->new_sha1, src->new_sha1); hashcpy(dst_peer->new_sha1, src->new_sha1);
} }
dst_peer->peer_ref = copy_ref(src); dst_peer->peer_ref = copy_ref(src);

Просмотреть файл

@ -85,7 +85,7 @@ void ref_remove_duplicates(struct ref *ref_map);
int valid_fetch_refspec(const char *refspec); int valid_fetch_refspec(const char *refspec);
struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec); struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, int match_refs(struct ref *src, struct ref **dst,
int nr_refspec, const char **refspec, int all); int nr_refspec, const char **refspec, int all);
/* /*

Просмотреть файл

@ -1003,7 +1003,6 @@ int transport_push(struct transport *transport,
if (transport->push_refs) { if (transport->push_refs) {
struct ref *remote_refs = struct ref *remote_refs =
transport->get_refs_list(transport, 1); transport->get_refs_list(transport, 1);
struct ref **remote_tail;
struct ref *local_refs = get_local_heads(); struct ref *local_refs = get_local_heads();
int match_flags = MATCH_REFS_NONE; int match_flags = MATCH_REFS_NONE;
int verbose = flags & TRANSPORT_PUSH_VERBOSE; int verbose = flags & TRANSPORT_PUSH_VERBOSE;
@ -1014,10 +1013,7 @@ int transport_push(struct transport *transport,
if (flags & TRANSPORT_PUSH_MIRROR) if (flags & TRANSPORT_PUSH_MIRROR)
match_flags |= MATCH_REFS_MIRROR; match_flags |= MATCH_REFS_MIRROR;
remote_tail = &remote_refs; if (match_refs(local_refs, &remote_refs,
while (*remote_tail)
remote_tail = &((*remote_tail)->next);
if (match_refs(local_refs, remote_refs, &remote_tail,
refspec_nr, refspec, match_flags)) { refspec_nr, refspec, match_flags)) {
return -1; return -1;
} }