fetch-pack: do not barf when duplicate re patterns are given
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 25, 2006 at 01:33 UTC
310b86d48091ebb6a71782678769b2cb8fe2ecd5
1 file changed
+25
fetch-pack.c
+25
@@ -566,6 +566,29 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
566
return 0;
567
}
568
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
+
592
int main(int argc, char **argv)
593
{
594
int i, ret, nr_heads;
@@ -617,6 +640,8 @@ int main(int argc, char **argv)
640
pid = git_connect(fd, dest, exec);
641
if (pid < 0)
642
return 1;
643
+ if (heads && nr_heads)
644
+ nr_heads = remove_duplicates(nr_heads, heads);
645
ret = fetch_pack(fd, nr_heads, heads);
646
close(fd[0]);
647
close(fd[1]);