@matheusbsbs / matheus-bagliano / commits / bf267d99e8
Fork 0

svn import: Do not create empty tags

If a tag is "clean", do not create a commit for it. Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>

Matthias Urlichs committed Oct 10, 2005 at 14:51 UTC bf267d99e88410a31452d4d1ccae0b9b4432b11e
1 file changed +125 -120
git-svnimport.perl
+125 -120
@@ -407,141 +407,146 @@ sub commit {
407 $last_rev = $rev;
408 }
409
410 - while(my($path,$action) = each %$changed_paths) {
411 - if ($action->[0] eq "A") {
412 - my $f = get_file($revision,$branch,$path);
413 - push(@new,$f) if $f;
414 - } elsif ($action->[0] eq "D") {
415 - push(@old,$path);
416 - } elsif ($action->[0] eq "M") {
417 - my $f = get_file($revision,$branch,$path);
418 - push(@new,$f) if $f;
419 - } elsif ($action->[0] eq "R") {
420 - # refer to a file/tree in an earlier commit
421 - push(@old,$path); # remove any old stuff
422 -
423 - # ... and add any new stuff
424 - my($b,$p) = split_path($revision,$action->[1]);
425 - open my $F,"-|","git-ls-tree","-r","-z", $branches{$b}{$action->[2]}, $p;
410 + my $cid;
411 + if($tag and not %$changed_paths) {
412 + $cid = $rev;
413 + } else {
414 + while(my($path,$action) = each %$changed_paths) {
415 + if ($action->[0] eq "A") {
416 + my $f = get_file($revision,$branch,$path);
417 + push(@new,$f) if $f;
418 + } elsif ($action->[0] eq "D") {
419 + push(@old,$path);
420 + } elsif ($action->[0] eq "M") {
421 + my $f = get_file($revision,$branch,$path);
422 + push(@new,$f) if $f;
423 + } elsif ($action->[0] eq "R") {
424 + # refer to a file/tree in an earlier commit
425 + push(@old,$path); # remove any old stuff
426 +
427 + # ... and add any new stuff
428 + my($b,$p) = split_path($revision,$action->[1]);
429 + open my $F,"-|","git-ls-tree","-r","-z", $branches{$b}{$action->[2]}, $p;
430 + local $/ = '\0';
431 + while(<$F>) {
432 + chomp;
433 + my($m,$p) = split(/\t/,$_,2);
434 + my($mode,$type,$sha1) = split(/ /,$m);
435 + next if $type ne "blob";
436 + push(@new,[$mode,$sha1,$p]);
437 + }
438 + } else {
439 + die "$revision: unknown action '".$action->[0]."' for $path\n";
440 + }
441 + }
442 +
443 + if(@old) {
444 + open my $F, "-|", "git-ls-files", "-z", @old or die $!;
445 + @old = ();
446 local $/ = '\0';
447 while(<$F>) {
448 chomp;
429 - my($m,$p) = split(/\t/,$_,2);
430 - my($mode,$type,$sha1) = split(/ /,$m);
431 - next if $type ne "blob";
432 - push(@new,[$mode,$sha1,$p]);
449 + push(@old,$_);
450 + }
451 + close($F);
452 +
453 + while(@old) {
454 + my @o2;
455 + if(@old > 55) {
456 + @o2 = splice(@old,0,50);
457 + } else {
458 + @o2 = @old;
459 + @old = ();
460 + }
461 + system("git-update-index","--force-remove","--",@o2);
462 + die "Cannot remove files: $?\n" if $?;
463 }
434 - } else {
435 - die "$revision: unknown action '".$action->[0]."' for $path\n";
436 - }
437 - }
438 -
439 - if(@old) {
440 - open my $F, "-|", "git-ls-files", "-z", @old or die $!;
441 - @old = ();
442 - local $/ = '\0';
443 - while(<$F>) {
444 - chomp;
445 - push(@old,$_);
464 }
447 - close($F);
448 -
449 - while(@old) {
450 - my @o2;
451 - if(@old > 55) {
452 - @o2 = splice(@old,0,50);
465 + while(@new) {
466 + my @n2;
467 + if(@new > 12) {
468 + @n2 = splice(@new,0,10);
469 } else {
454 - @o2 = @old;
455 - @old = ();
470 + @n2 = @new;
471 + @new = ();
472 }
457 - system("git-update-index","--force-remove","--",@o2);
458 - die "Cannot remove files: $?\n" if $?;
459 - }
460 - }
461 - while(@new) {
462 - my @n2;
463 - if(@new > 12) {
464 - @n2 = splice(@new,0,10);
465 - } else {
466 - @n2 = @new;
467 - @new = ();
473 + system("git-update-index","--add",
474 + (map { ('--cacheinfo', @$_) } @n2));
475 + die "Cannot add files: $?\n" if $?;
476 }
469 - system("git-update-index","--add",
470 - (map { ('--cacheinfo', @$_) } @n2));
471 - die "Cannot add files: $?\n" if $?;
472 - }
473 -
474 - my $pid = open(C,"-|");
475 - die "Cannot fork: $!" unless defined $pid;
476 - unless($pid) {
477 - exec("git-write-tree");
478 - die "Cannot exec git-write-tree: $!\n";
479 - }
480 - chomp(my $tree = <C>);
481 - length($tree) == 40
482 - or die "Cannot get tree id ($tree): $!\n";
483 - close(C)
484 - or die "Error running git-write-tree: $?\n";
485 - print "Tree ID $tree\n" if $opt_v;
486 -
487 - my $pr = IO::Pipe->new() or die "Cannot open pipe: $!\n";
488 - my $pw = IO::Pipe->new() or die "Cannot open pipe: $!\n";
489 - $pid = fork();
490 - die "Fork: $!\n" unless defined $pid;
491 - unless($pid) {
492 - $pr->writer();
493 - $pw->reader();
494 - open(OUT,">&STDOUT");
495 - dup2($pw->fileno(),0);
496 - dup2($pr->fileno(),1);
497 - $pr->close();
498 - $pw->close();
477
500 - my @par = ();
501 - @par = ("-p",$rev) if defined $rev;
502 -
503 - # loose detection of merges
504 - # based on the commit msg
505 - foreach my $rx (@mergerx) {
506 - if ($message =~ $rx) {
507 - my $mparent = $1;
508 - if ($mparent eq 'HEAD') { $mparent = $opt_o };
509 - if ( -e "$git_dir/refs/heads/$mparent") {
510 - $mparent = get_headref($mparent, $git_dir);
511 - push @par, '-p', $mparent;
512 - print OUT "Merge parent branch: $mparent\n" if $opt_v;
513 - }
514 - }
478 + my $pid = open(C,"-|");
479 + die "Cannot fork: $!" unless defined $pid;
480 + unless($pid) {
481 + exec("git-write-tree");
482 + die "Cannot exec git-write-tree: $!\n";
483 }
484 + chomp(my $tree = <C>);
485 + length($tree) == 40
486 + or die "Cannot get tree id ($tree): $!\n";
487 + close(C)
488 + or die "Error running git-write-tree: $?\n";
489 + print "Tree ID $tree\n" if $opt_v;
490 +
491 + my $pr = IO::Pipe->new() or die "Cannot open pipe: $!\n";
492 + my $pw = IO::Pipe->new() or die "Cannot open pipe: $!\n";
493 + $pid = fork();
494 + die "Fork: $!\n" unless defined $pid;
495 + unless($pid) {
496 + $pr->writer();
497 + $pw->reader();
498 + open(OUT,">&STDOUT");
499 + dup2($pw->fileno(),0);
500 + dup2($pr->fileno(),1);
501 + $pr->close();
502 + $pw->close();
503 +
504 + my @par = ();
505 + @par = ("-p",$rev) if defined $rev;
506 +
507 + # loose detection of merges
508 + # based on the commit msg
509 + foreach my $rx (@mergerx) {
510 + if ($message =~ $rx) {
511 + my $mparent = $1;
512 + if ($mparent eq 'HEAD') { $mparent = $opt_o };
513 + if ( -e "$git_dir/refs/heads/$mparent") {
514 + $mparent = get_headref($mparent, $git_dir);
515 + push @par, '-p', $mparent;
516 + print OUT "Merge parent branch: $mparent\n" if $opt_v;
517 + }
518 + }
519 + }
520
517 - exec("env",
518 - "GIT_AUTHOR_NAME=$author_name",
519 - "GIT_AUTHOR_EMAIL=$author_email",
520 - "GIT_AUTHOR_DATE=".strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
521 - "GIT_COMMITTER_NAME=$author_name",
522 - "GIT_COMMITTER_EMAIL=$author_email",
523 - "GIT_COMMITTER_DATE=".strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
524 - "git-commit-tree", $tree,@par);
525 - die "Cannot exec git-commit-tree: $!\n";
526 - }
527 - $pw->writer();
528 - $pr->reader();
521 + exec("env",
522 + "GIT_AUTHOR_NAME=$author_name",
523 + "GIT_AUTHOR_EMAIL=$author_email",
524 + "GIT_AUTHOR_DATE=".strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
525 + "GIT_COMMITTER_NAME=$author_name",
526 + "GIT_COMMITTER_EMAIL=$author_email",
527 + "GIT_COMMITTER_DATE=".strftime("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
528 + "git-commit-tree", $tree,@par);
529 + die "Cannot exec git-commit-tree: $!\n";
530 + }
531 + $pw->writer();
532 + $pr->reader();
533
530 - $message =~ s/[\s\n]+\z//;
534 + $message =~ s/[\s\n]+\z//;
535
532 - print $pw "$message\n"
533 - or die "Error writing to git-commit-tree: $!\n";
534 - $pw->close();
536 + print $pw "$message\n"
537 + or die "Error writing to git-commit-tree: $!\n";
538 + $pw->close();
539
536 - print "Committed change $revision:$branch ".strftime("%Y-%m-%d %H:%M:%S",gmtime($date)).")\n" if $opt_v;
537 - chomp(my $cid = <$pr>);
538 - length($cid) == 40
539 - or die "Cannot get commit id ($cid): $!\n";
540 - print "Commit ID $cid\n" if $opt_v;
541 - $pr->close();
540 + print "Committed change $revision:$branch ".strftime("%Y-%m-%d %H:%M:%S",gmtime($date)).")\n" if $opt_v;
541 + chomp($cid = <$pr>);
542 + length($cid) == 40
543 + or die "Cannot get commit id ($cid): $!\n";
544 + print "Commit ID $cid\n" if $opt_v;
545 + $pr->close();
546
543 - waitpid($pid,0);
544 - die "Error running git-commit-tree: $?\n" if $?;
547 + waitpid($pid,0);
548 + die "Error running git-commit-tree: $?\n" if $?;
549 + }
550
551 if(not defined $dest) {
552 print "... no known parent\n" if $opt_v;