Skip to content

Commit 4ba1599

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c58f13 commit 4ba1599

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

builtin/fetch-pack.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,16 @@ static void mark_recent_complete_commits(unsigned long cutoff)
525525
}
526526
}
527527

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+
528538
static void filter_refs(struct ref **refs, struct string_list *sought)
529539
{
530540
struct ref **return_refs;
@@ -566,7 +576,7 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
566576
break;
567577
else if (cmp == 0) { /* definitely have it */
568578
return_refs[sought_pos] = ref;
569-
sought->items[sought_pos++].string[0] = '\0';
579+
sought->items[sought_pos++].util = "matched";
570580
break;
571581
}
572582
else /* might have it; keep looking */
@@ -590,6 +600,7 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
590600
}
591601
if (return_refs != fastarray)
592602
free(return_refs);
603+
filter_string_list(sought, 0, non_matching_ref, NULL);
593604
}
594605
*refs = newlist;
595606
}
@@ -1040,13 +1051,9 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
10401051
* Otherwise, 'git fetch remote no-such-ref' would
10411052
* silently succeed without issuing an error.
10421053
*/
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;
10501057
}
10511058
while (ref) {
10521059
printf("%s %s\n",

fetch-pack.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ struct fetch_pack_args {
1919
stateless_rpc:1;
2020
};
2121

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+
*/
2229
struct ref *fetch_pack(struct fetch_pack_args *args,
2330
int fd[], struct child_process *conn,
2431
const struct ref *ref,

transport.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ static int fetch_refs_via_pack(struct transport *transport,
518518
int nr_heads, struct ref **to_fetch)
519519
{
520520
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;
523522
const struct ref *refs;
524523
char *dest = xstrdup(transport->url);
525524
struct fetch_pack_args args;
@@ -537,10 +536,8 @@ static int fetch_refs_via_pack(struct transport *transport,
537536
args.no_progress = !transport->progress;
538537
args.depth = data->options.depth;
539538

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);
544541

545542
if (!data->got_remote_heads) {
546543
connect_setup(transport, 0, 0);
@@ -561,7 +558,6 @@ static int fetch_refs_via_pack(struct transport *transport,
561558
free_refs(refs_tmp);
562559

563560
string_list_clear(&sought, 0);
564-
string_list_clear(&orig_sought, 0);
565561
free(dest);
566562
return (refs ? 0 : -1);
567563
}

0 commit comments

Comments
 (0)