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

git-svn: bugfix and optimize the 'log' command

Revisions with long commit messages were being skipped, since the 'git-svn-id' metadata line was at the end and git-log uses a 32k buffer to print the commits. Also the last 'git-svn-id' metadata line in a commit is always the valid one, so make sure we use that, as well. Made the verbose flag work by passing the correct option switch ('--summary') to git-log. Finally, optimize -r/--revision argument handling by passing the appropriate limits to revision Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jun 15, 2006 at 18:48 UTC c0d4822268d30b1668e94986a845b8bb5441e8b3
1 file changed +52 -8
contrib/git-svn/git-svn.perl
+52 -8
@@ -663,17 +663,15 @@ sub show_log {
663 my $pid = open(my $log,'-|');
664 defined $pid or croak $!;
665 if (!$pid) {
666 - my @rl = (qw/git-log --abbrev-commit --pretty=raw
667 - --default/, "remotes/$GIT_SVN");
668 - push @rl, '--raw' if $_verbose;
669 - exec(@rl, @args) or croak $!;
666 + exec(git_svn_log_cmd($r_min,$r_max), @args) or croak $!;
667 }
668 setup_pager();
669 my (@k, $c, $d);
670 +
671 while (<$log>) {
672 if (/^commit ($sha1_short)/o) {
673 my $cmt = $1;
676 - if ($c && defined $c->{r} && $c->{r} != $r_last) {
674 + if ($c && cmt_showable($c) && $c->{r} != $r_last) {
675 $r_last = $c->{r};
676 process_commit($c, $r_min, $r_max, \@k) or
677 goto out;
@@ -692,8 +690,7 @@ sub show_log {
690 } elsif ($d) {
691 push @{$c->{diff}}, $_;
692 } elsif (/^ (git-svn-id:.+)$/) {
695 - my ($url, $rev, $uuid) = extract_metadata($1);
696 - $c->{r} = $rev;
693 + (undef, $c->{r}, undef) = extract_metadata($1);
694 } elsif (s/^ //) {
695 push @{$c->{l}}, $_;
696 }
@@ -715,6 +712,52 @@ out:
712
713 ########################### utility functions #########################
714
715 +sub cmt_showable {
716 + my ($c) = @_;
717 + return 1 if defined $c->{r};
718 + if ($c->{l} && $c->{l}->[-1] eq "...\n" &&
719 + $c->{a_raw} =~ /\@([a-f\d\-]+)>$/) {
720 + my @msg = safe_qx(qw/git-cat-file commit/, $c->{c});
721 + shift @msg while ($msg[0] ne "\n");
722 + shift @msg;
723 + @{$c->{l}} = grep !/^git-svn-id: /, @msg;
724 +
725 + (undef, $c->{r}, undef) = extract_metadata(
726 + (grep(/^git-svn-id: /, @msg))[-1]);
727 + }
728 + return defined $c->{r};
729 +}
730 +
731 +sub git_svn_log_cmd {
732 + my ($r_min, $r_max) = @_;
733 + my @cmd = (qw/git-log --abbrev-commit --pretty=raw
734 + --default/, "refs/remotes/$GIT_SVN");
735 + push @cmd, '--summary' if $_verbose;
736 + return @cmd unless defined $r_max;
737 + if ($r_max == $r_min) {
738 + push @cmd, '--max-count=1';
739 + if (my $c = revdb_get($REVDB, $r_max)) {
740 + push @cmd, $c;
741 + }
742 + } else {
743 + my ($c_min, $c_max);
744 + $c_max = revdb_get($REVDB, $r_max);
745 + $c_min = revdb_get($REVDB, $r_min);
746 + if ($c_min && $c_max) {
747 + if ($r_max > $r_max) {
748 + push @cmd, "$c_min..$c_max";
749 + } else {
750 + push @cmd, "$c_max..$c_min";
751 + }
752 + } elsif ($r_max > $r_min) {
753 + push @cmd, $c_max;
754 + } else {
755 + push @cmd, $c_min;
756 + }
757 + }
758 + return @cmd;
759 +}
760 +
761 sub fetch_child_id {
762 my $id = shift;
763 print "Fetching $id\n";
@@ -2206,6 +2249,7 @@ sub setup_pager { # translated to Perl from pager.c
2249 sub get_author_info {
2250 my ($dest, $author, $t, $tz) = @_;
2251 $author =~ s/(?:^\s*|\s*$)//g;
2252 + $dest->{a_raw} = $author;
2253 my $_a;
2254 if ($_authors) {
2255 $_a = $rusers{$author} || undef;
@@ -2440,7 +2484,7 @@ sub svn_grab_base_rev {
2484 close $fh;
2485 if (defined $c && length $c) {
2486 my ($url, $rev, $uuid) = extract_metadata((grep(/^git-svn-id: /,
2443 - safe_qx(qw/git-cat-file commit/, $c)))[0]);
2487 + safe_qx(qw/git-cat-file commit/, $c)))[-1]);
2488 return ($rev, $c);
2489 }
2490 return (undef, undef);