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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 9, 2012 at 08:19 UTC
4c58f13ba67f9dbe67a351de61703a2db20712cc
2 files changed
+2
-15
builtin/fetch-pack.c
+1
-14
@@ -858,19 +858,6 @@ static struct ref *do_fetch_pack(int fd[2],
858
return ref;
859
}
860
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
-
861
static int fetch_pack_config(const char *var, const char *value, void *cb)
862
{
863
if (strcmp(var, "fetch.unpacklimit") == 0) {
@@ -1090,7 +1077,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
1077
1078
if (sought->nr) {
1079
sort_string_list(sought);
1093
- remove_duplicates(sought);
1080
+ string_list_remove_duplicates(sought, 0);
1081
}
1082
1083
if (!ref) {
t/t5500-fetch-pack.sh
+1
-1
@@ -391,7 +391,7 @@ test_expect_success 'fetch mixed refs from cmdline and stdin' '
391
test_expect_success 'test duplicate refs from stdin' '
392
(
393
cd client &&
394
- test_must_fail git fetch-pack --stdin --no-progress .. <../input.dup
394
+ git fetch-pack --stdin --no-progress .. <../input.dup
395
) >output &&
396
cut -d " " -f 2 <output | sort >actual &&
397
test_cmp expect actual