@matheusbsbs / matheus-bagliano / commits / 6a1871e174
Fork 0

cvsimport: use git-update-index --index-info

This should reduce the number of git-update-index forks required per commit. We now do adds/removes in one call, and we are no longer forced to deal with argv limitations. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jeff King committed May 23, 2006 at 03:27 UTC 6a1871e174fee1757713df7a3d776dd3813e7ad8
1 file changed +13 -23
git-cvsimport.perl
+13 -23
@@ -565,29 +565,19 @@ my($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
565 my(@old,@new,@skipped);
566 sub commit {
567 my $pid;
568 - while(@old) {
569 - my @o2;
570 - if(@old > 55) {
571 - @o2 = splice(@old,0,50);
572 - } else {
573 - @o2 = @old;
574 - @old = ();
575 - }
576 - system("git-update-index","--force-remove","--",@o2);
577 - die "Cannot remove files: $?\n" if $?;
578 - }
579 - while(@new) {
580 - my @n2;
581 - if(@new > 12) {
582 - @n2 = splice(@new,0,10);
583 - } else {
584 - @n2 = @new;
585 - @new = ();
586 - }
587 - system("git-update-index","--add",
588 - (map { ('--cacheinfo', @$_) } @n2));
589 - die "Cannot add files: $?\n" if $?;
590 - }
568 +
569 + open(my $fh, '|-', qw(git-update-index -z --index-info))
570 + or die "unable to open git-update-index: $!";
571 + print $fh
572 + (map { "0 0000000000000000000000000000000000000000\t$_\0" }
573 + @old),
574 + (map { '100' . sprintf('%o', $_->[0]) . " $_->[1]\t$_->[2]\0" }
575 + @new)
576 + or die "unable to write to git-update-index: $!";
577 + close $fh
578 + or die "unable to write to git-update-index: $!";
579 + $? and die "git-update-index reported error: $?";
580 + @old = @new = ();
581
582 $pid = open(C,"-|");
583 die "Cannot fork: $!" unless defined $pid;