Skip to content

Commit 310b86d

Browse files
author
Junio C Hamano
committed
fetch-pack: do not barf when duplicate re patterns are given
Signed-off-by: Junio C Hamano <[email protected]>
1 parent d945d4b commit 310b86d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

fetch-pack.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,29 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
566566
return 0;
567567
}
568568

569+
static int remove_duplicates(int nr_heads, char **heads)
570+
{
571+
int src, dst;
572+
573+
for (src = dst = 0; src < nr_heads; src++) {
574+
/* If heads[src] is different from any of
575+
* heads[0..dst], push it in.
576+
*/
577+
int i;
578+
for (i = 0; i < dst; i++) {
579+
if (!strcmp(heads[i], heads[src]))
580+
break;
581+
}
582+
if (i < dst)
583+
continue;
584+
if (src != dst)
585+
heads[dst] = heads[src];
586+
dst++;
587+
}
588+
heads[dst] = 0;
589+
return dst;
590+
}
591+
569592
int main(int argc, char **argv)
570593
{
571594
int i, ret, nr_heads;
@@ -617,6 +640,8 @@ int main(int argc, char **argv)
617640
pid = git_connect(fd, dest, exec);
618641
if (pid < 0)
619642
return 1;
643+
if (heads && nr_heads)
644+
nr_heads = remove_duplicates(nr_heads, heads);
620645
ret = fetch_pack(fd, nr_heads, heads);
621646
close(fd[0]);
622647
close(fd[1]);

0 commit comments

Comments
 (0)