Skip to content

Commit 4c58f13

Browse files
mhaggergitster
authored andcommitted
fetch_pack(): update sought->nr to reflect number of unique entries
fetch_pack() removes duplicates from the "sought" list, thereby shrinking the list. But previously, the caller was not informed about the shrinkage. This would cause a spurious error message to be emitted by cmd_fetch_pack() if "git fetch-pack" is called with duplicate refnames. Instead, remove duplicates using string_list_remove_duplicates(), which adjusts sought->nr to reflect the new length of the list. The last test of t5500 inexplicably *required* "git fetch-pack" to fail when fetching a list of references that contains duplicates; i.e., it insisted on the buggy behavior. So change the test to expect the correct behavior. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 382a967 commit 4c58f13

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

builtin/fetch-pack.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -858,19 +858,6 @@ static struct ref *do_fetch_pack(int fd[2],
858858
return ref;
859859
}
860860

861-
static int remove_duplicates(struct string_list *sought)
862-
{
863-
int src, dst;
864-
865-
if (!sought->nr)
866-
return 0;
867-
868-
for (src = dst = 1; src < sought->nr; src++)
869-
if (strcmp(sought->items[src].string, sought->items[dst-1].string))
870-
sought->items[dst++] = sought->items[src];
871-
return dst;
872-
}
873-
874861
static int fetch_pack_config(const char *var, const char *value, void *cb)
875862
{
876863
if (strcmp(var, "fetch.unpacklimit") == 0) {
@@ -1090,7 +1077,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
10901077

10911078
if (sought->nr) {
10921079
sort_string_list(sought);
1093-
remove_duplicates(sought);
1080+
string_list_remove_duplicates(sought, 0);
10941081
}
10951082

10961083
if (!ref) {

t/t5500-fetch-pack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ test_expect_success 'fetch mixed refs from cmdline and stdin' '
391391
test_expect_success 'test duplicate refs from stdin' '
392392
(
393393
cd client &&
394-
test_must_fail git fetch-pack --stdin --no-progress .. <../input.dup
394+
git fetch-pack --stdin --no-progress .. <../input.dup
395395
) >output &&
396396
cut -d " " -f 2 <output | sort >actual &&
397397
test_cmp expect actual

0 commit comments

Comments
 (0)