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>
Michael Haggerty committed
Sep 9, 2012 at 08:19 UTC
4ba159996f6c1b0d6dd0a2a8bd9d6f5b342a4aa5
3 files changed
+25
-15
builtin/fetch-pack.c
+15
-8
@@ -525,6 +525,16 @@ static void mark_recent_complete_commits(unsigned long cutoff)
525
}
526
}
527
528
+static int non_matching_ref(struct string_list_item *item, void *unused)
529
+{
530
+ if (item->util) {
531
+ item->util = NULL;
532
+ return 0;
533
+ }
534
+ else
535
+ return 1;
536
+}
537
+
538
static void filter_refs(struct ref **refs, struct string_list *sought)
539
{
540
struct ref **return_refs;
@@ -566,7 +576,7 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
576
break;
577
else if (cmp == 0) { /* definitely have it */
578
return_refs[sought_pos] = ref;
569
- sought->items[sought_pos++].string[0] = '\0';
579
+ sought->items[sought_pos++].util = "matched";
580
break;
581
}
582
else /* might have it; keep looking */
@@ -590,6 +600,7 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
600
}
601
if (return_refs != fastarray)
602
free(return_refs);
603
+ filter_string_list(sought, 0, non_matching_ref, NULL);
604
}
605
*refs = newlist;
606
}
@@ -1040,13 +1051,9 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
1051
* Otherwise, 'git fetch remote no-such-ref' would
1052
* silently succeed without issuing an error.
1053
*/
1043
- for (i = 0; i < sought.nr; i++) {
1044
- char *s = sought.items[i].string;
1045
- if (s && s[0]) {
1046
- error("no such remote ref %s", s);
1047
- ret = 1;
1048
- }
1049
- }
1054
+ for (i = 0; i < sought.nr; i++)
1055
+ error("no such remote ref %s", sought.items[i].string);
1056
+ ret = 1;
1057
}
1058
while (ref) {
1059
printf("%s %s\n",
fetch-pack.h
+7
@@ -19,6 +19,13 @@ struct fetch_pack_args {
19
stateless_rpc:1;
20
};
21
22
+/*
23
+ * sought contains the full names of remote references that should be
24
+ * updated from. On return, the names that were found on the remote
25
+ * will have been removed from the list. The util members of the
26
+ * string_list_items are used internally; they must be NULL on entry
27
+ * (and will be NULL on exit).
28
+ */
29
struct ref *fetch_pack(struct fetch_pack_args *args,
30
int fd[], struct child_process *conn,
31
const struct ref *ref,
transport.c
+3
-7
@@ -518,8 +518,7 @@ static int fetch_refs_via_pack(struct transport *transport,
518
int nr_heads, struct ref **to_fetch)
519
{
520
struct git_transport_data *data = transport->data;
521
- struct string_list orig_sought = STRING_LIST_INIT_DUP;
522
- struct string_list sought = STRING_LIST_INIT_NODUP;
521
+ struct string_list sought = STRING_LIST_INIT_DUP;
522
const struct ref *refs;
523
char *dest = xstrdup(transport->url);
524
struct fetch_pack_args args;
@@ -537,10 +536,8 @@ static int fetch_refs_via_pack(struct transport *transport,
536
args.no_progress = !transport->progress;
537
args.depth = data->options.depth;
538
540
- for (i = 0; i < nr_heads; i++) {
541
- string_list_append(&orig_sought, to_fetch[i]->name);
542
- string_list_append(&sought, orig_sought.items[orig_sought.nr - 1].string);
543
- }
539
+ for (i = 0; i < nr_heads; i++)
540
+ string_list_append(&sought, to_fetch[i]->name);
541
542
if (!data->got_remote_heads) {
543
connect_setup(transport, 0, 0);
@@ -561,7 +558,6 @@ static int fetch_refs_via_pack(struct transport *transport,
558
free_refs(refs_tmp);
559
560
string_list_clear(&sought, 0);
564
- string_list_clear(&orig_sought, 0);
561
free(dest);
562
return (refs ? 0 : -1);
563
}