filter_refs(): delete matched refs from sought list

Remove any references that are available from the remote from the
sought list (rather than overwriting their names with NUL characters,
as previously).  Mark matching entries by writing a non-NULL pointer
to string_list_item::util during the iteration, then use
filter_string_list() later to filter out the entries that have been
marked.

Document this aspect of fetch_pack() in a comment in the header file.
(More documentation is obviously still needed.)

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2012-09-09 08:19:43 +02:00 коммит произвёл Junio C Hamano
Родитель 4c58f13ba6
Коммит 4ba159996f
3 изменённых файлов: 25 добавлений и 15 удалений

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

@ -525,6 +525,16 @@ static void mark_recent_complete_commits(unsigned long cutoff)
} }
} }
static int non_matching_ref(struct string_list_item *item, void *unused)
{
if (item->util) {
item->util = NULL;
return 0;
}
else
return 1;
}
static void filter_refs(struct ref **refs, struct string_list *sought) static void filter_refs(struct ref **refs, struct string_list *sought)
{ {
struct ref **return_refs; struct ref **return_refs;
@ -566,7 +576,7 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
break; break;
else if (cmp == 0) { /* definitely have it */ else if (cmp == 0) { /* definitely have it */
return_refs[sought_pos] = ref; return_refs[sought_pos] = ref;
sought->items[sought_pos++].string[0] = '\0'; sought->items[sought_pos++].util = "matched";
break; break;
} }
else /* might have it; keep looking */ else /* might have it; keep looking */
@ -590,6 +600,7 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
} }
if (return_refs != fastarray) if (return_refs != fastarray)
free(return_refs); free(return_refs);
filter_string_list(sought, 0, non_matching_ref, NULL);
} }
*refs = newlist; *refs = newlist;
} }
@ -1040,14 +1051,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
* Otherwise, 'git fetch remote no-such-ref' would * Otherwise, 'git fetch remote no-such-ref' would
* silently succeed without issuing an error. * silently succeed without issuing an error.
*/ */
for (i = 0; i < sought.nr; i++) { for (i = 0; i < sought.nr; i++)
char *s = sought.items[i].string; error("no such remote ref %s", sought.items[i].string);
if (s && s[0]) {
error("no such remote ref %s", s);
ret = 1; ret = 1;
} }
}
}
while (ref) { while (ref) {
printf("%s %s\n", printf("%s %s\n",
sha1_to_hex(ref->old_sha1), ref->name); sha1_to_hex(ref->old_sha1), ref->name);

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

@ -19,6 +19,13 @@ struct fetch_pack_args {
stateless_rpc:1; stateless_rpc:1;
}; };
/*
* sought contains the full names of remote references that should be
* updated from. On return, the names that were found on the remote
* will have been removed from the list. The util members of the
* string_list_items are used internally; they must be NULL on entry
* (and will be NULL on exit).
*/
struct ref *fetch_pack(struct fetch_pack_args *args, struct ref *fetch_pack(struct fetch_pack_args *args,
int fd[], struct child_process *conn, int fd[], struct child_process *conn,
const struct ref *ref, const struct ref *ref,

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

@ -518,8 +518,7 @@ static int fetch_refs_via_pack(struct transport *transport,
int nr_heads, struct ref **to_fetch) int nr_heads, struct ref **to_fetch)
{ {
struct git_transport_data *data = transport->data; struct git_transport_data *data = transport->data;
struct string_list orig_sought = STRING_LIST_INIT_DUP; struct string_list sought = STRING_LIST_INIT_DUP;
struct string_list sought = STRING_LIST_INIT_NODUP;
const struct ref *refs; const struct ref *refs;
char *dest = xstrdup(transport->url); char *dest = xstrdup(transport->url);
struct fetch_pack_args args; struct fetch_pack_args args;
@ -537,10 +536,8 @@ static int fetch_refs_via_pack(struct transport *transport,
args.no_progress = !transport->progress; args.no_progress = !transport->progress;
args.depth = data->options.depth; args.depth = data->options.depth;
for (i = 0; i < nr_heads; i++) { for (i = 0; i < nr_heads; i++)
string_list_append(&orig_sought, to_fetch[i]->name); string_list_append(&sought, to_fetch[i]->name);
string_list_append(&sought, orig_sought.items[orig_sought.nr - 1].string);
}
if (!data->got_remote_heads) { if (!data->got_remote_heads) {
connect_setup(transport, 0, 0); connect_setup(transport, 0, 0);
@ -561,7 +558,6 @@ static int fetch_refs_via_pack(struct transport *transport,
free_refs(refs_tmp); free_refs(refs_tmp);
string_list_clear(&sought, 0); string_list_clear(&sought, 0);
string_list_clear(&orig_sought, 0);
free(dest); free(dest);
return (refs ? 0 : -1); return (refs ? 0 : -1);
} }