git-svn: moved the 'log' command into its own namespace
More cleanup to separate out functionality and make things nicer to hack on. While we're at it, centralize loading of the authors into one place and correctly handle '(no author)' cases in when showing logs after-the-fact; and not just at commit time. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 12, 2007 at 02:35 UTC
f8c9d1d27f250a7fe13d4d33a1a94604ad355529
1 file changed
+325
-327
git-svn.perl
+325
-327
@@ -6,7 +6,8 @@ use strict;
6
use vars qw/ $AUTHOR $VERSION
7
$SVN_URL
8
$GIT_SVN_INDEX $GIT_SVN
9
- $GIT_DIR $GIT_SVN_DIR $REVDB/;
9
+ $GIT_DIR $GIT_SVN_DIR $REVDB
10
+ $_follow_parent $sha1 $sha1_short/;
11
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
12
$VERSION = '@@GIT_VERSION@@';
13
@@ -15,7 +16,7 @@ $GIT_DIR = abs_path($ENV{GIT_DIR} || '.git');
16
$ENV{GIT_DIR} = $GIT_DIR;
17
18
my $LC_ALL = $ENV{LC_ALL};
18
-my $TZ = $ENV{TZ};
19
+$Git::SVN::Log::TZ = $ENV{TZ};
20
# make sure the svn binary gives consistent output between locales and TZs:
21
$ENV{TZ} = 'UTC';
22
$ENV{LC_ALL} = 'C';
@@ -46,7 +47,6 @@ use IO::File qw//;
47
use File::Basename qw/dirname basename/;
48
use File::Path qw/mkpath/;
49
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
49
-use POSIX qw/strftime/;
50
use IPC::Open3;
51
use Memoize;
52
use Git;
@@ -59,7 +59,7 @@ BEGIN {
59
foreach (qw/command command_oneline command_noisy command_output_pipe
60
command_input_pipe command_close_pipe/) {
61
$s .= "*SVN::Git::Editor::$_ = *SVN::Git::Fetcher::$_ = ".
62
- "*$_ = *Git::$_; ";
62
+ "*Git::SVN::Log::$_ = *Git::SVN::$_ = *$_ = *Git::$_; ";
63
}
64
eval $s;
65
}
@@ -67,21 +67,18 @@ BEGIN {
67
my ($SVN);
68
69
my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS};
70
-my $sha1 = qr/[a-f\d]{40}/;
71
-my $sha1_short = qr/[a-f\d]{4,40}/;
72
-my $_esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
70
+$sha1 = qr/[a-f\d]{40}/;
71
+$sha1_short = qr/[a-f\d]{4,40}/;
72
my ($_revision,$_stdin,$_help,$_rmdir,$_edit,
73
$_find_copies_harder, $_l, $_cp_similarity, $_cp_remote,
74
$_repack, $_repack_nr, $_repack_flags, $_q,
75
$_message, $_file, $_no_metadata,
76
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
78
- $_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
77
$_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
80
- $_merge, $_strategy, $_dry_run, $_ignore_nodate, $_non_recursive,
81
- $_pager, $_color, $_prefix);
82
-my (@_branch_from, %tree_map, %users, %rusers);
78
+ $_merge, $_strategy, $_dry_run,
79
+ $_prefix);
80
+my (@_branch_from, %tree_map, %users);
81
my @repo_path_split_cache;
84
-use vars qw/$_follow_parent/;
82
83
my %fc_opts = ( 'branch|b=s' => \@_branch_from,
84
'follow-parent|follow' => \$_follow_parent,
@@ -93,7 +90,6 @@ my %fc_opts = ( 'branch|b=s' => \@_branch_from,
90
'username=s' => \$Git::SVN::Prompt::_username,
91
'config-dir=s' => \$Git::SVN::Ra::config_dir,
92
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
96
- 'ignore-nodate' => \$_ignore_nodate,
93
'repack-flags|repack-args|repack-opts=s' => \$_repack_flags);
94
95
my ($_trunk, $_tags, $_branches);
@@ -145,17 +141,17 @@ my %cmd = (
141
'multi-fetch' => [ \&multi_fetch,
142
'Fetch multiple trees (like git-svnimport)',
143
\%fc_opts ],
148
- 'log' => [ \&show_log, 'Show commit logs',
149
- { 'limit=i' => \$_limit,
144
+ 'log' => [ \&Git::SVN::Log::cmd_show_log, 'Show commit logs',
145
+ { 'limit=i' => \$Git::SVN::Log::limit,
146
'revision|r=s' => \$_revision,
151
- 'verbose|v' => \$_verbose,
152
- 'incremental' => \$_incremental,
153
- 'oneline' => \$_oneline,
154
- 'show-commit' => \$_show_commit,
155
- 'non-recursive' => \$_non_recursive,
147
+ 'verbose|v' => \$Git::SVN::Log::verbose,
148
+ 'incremental' => \$Git::SVN::Log::incremental,
149
+ 'oneline' => \$Git::SVN::Log::oneline,
150
+ 'show-commit' => \$Git::SVN::Log::show_commit,
151
+ 'non-recursive' => \$Git::SVN::Log::non_recursive,
152
'authors-file|A=s' => \$_authors,
157
- 'color' => \$_color,
158
- 'pager=s' => \$_pager,
153
+ 'color' => \$Git::SVN::Log::color,
154
+ 'pager=s' => \$Git::SVN::Log::pager,
155
} ],
156
'commit-diff' => [ \&commit_diff, 'Commit a diff between two trees',
157
{ 'message|m=s' => \$_message,
@@ -607,81 +603,6 @@ sub multi_fetch {
603
rec_fetch('', "$GIT_DIR/svn", @_);
604
}
605
610
-sub show_log {
611
- my (@args) = @_;
612
- my ($r_min, $r_max);
613
- my $r_last = -1; # prevent dupes
614
- rload_authors() if $_authors;
615
- if (defined $TZ) {
616
- $ENV{TZ} = $TZ;
617
- } else {
618
- delete $ENV{TZ};
619
- }
620
- if (defined $_revision) {
621
- if ($_revision =~ /^(\d+):(\d+)$/) {
622
- ($r_min, $r_max) = ($1, $2);
623
- } elsif ($_revision =~ /^\d+$/) {
624
- $r_min = $r_max = $_revision;
625
- } else {
626
- print STDERR "-r$_revision is not supported, use ",
627
- "standard \'git log\' arguments instead\n";
628
- exit 1;
629
- }
630
- }
631
-
632
- config_pager();
633
- @args = (git_svn_log_cmd($r_min, $r_max), @args);
634
- my $log = command_output_pipe(@args);
635
- run_pager();
636
- my (@k, $c, $d);
637
-
638
- while (<$log>) {
639
- if (/^${_esc_color}commit ($sha1_short)/o) {
640
- my $cmt = $1;
641
- if ($c && cmt_showable($c) && $c->{r} != $r_last) {
642
- $r_last = $c->{r};
643
- process_commit($c, $r_min, $r_max, \@k) or
644
- goto out;
645
- }
646
- $d = undef;
647
- $c = { c => $cmt };
648
- } elsif (/^${_esc_color}author (.+) (\d+) ([\-\+]?\d+)$/) {
649
- get_author_info($c, $1, $2, $3);
650
- } elsif (/^${_esc_color}(?:tree|parent|committer) /) {
651
- # ignore
652
- } elsif (/^${_esc_color}:\d{6} \d{6} $sha1_short/o) {
653
- push @{$c->{raw}}, $_;
654
- } elsif (/^${_esc_color}[ACRMDT]\t/) {
655
- # we could add $SVN->{svn_path} here, but that requires
656
- # remote access at the moment (repo_path_split)...
657
- s#^(${_esc_color})([ACRMDT])\t#$1 $2 #;
658
- push @{$c->{changed}}, $_;
659
- } elsif (/^${_esc_color}diff /) {
660
- $d = 1;
661
- push @{$c->{diff}}, $_;
662
- } elsif ($d) {
663
- push @{$c->{diff}}, $_;
664
- } elsif (/^${_esc_color} (git-svn-id:.+)$/) {
665
- ($c->{url}, $c->{r}, undef) = extract_metadata($1);
666
- } elsif (s/^${_esc_color} //) {
667
- push @{$c->{l}}, $_;
668
- }
669
- }
670
- if ($c && defined $c->{r} && $c->{r} != $r_last) {
671
- $r_last = $c->{r};
672
- process_commit($c, $r_min, $r_max, \@k);
673
- }
674
- if (@k) {
675
- my $swap = $r_max;
676
- $r_max = $r_min;
677
- $r_min = $swap;
678
- process_commit($_, $r_min, $r_max) foreach reverse @k;
679
- }
680
-out:
681
- close $log;
682
- print '-' x72,"\n" unless $_incremental || $_oneline;
683
-}
684
-
606
sub commit_diff_usage {
607
print STDERR "Usage: $0 commit-diff <tree-ish> <tree-ish> [<URL>]\n";
608
exit 1
@@ -751,90 +672,6 @@ sub commit_diff {
672
673
########################### utility functions #########################
674
754
-sub cmt_showable {
755
- my ($c) = @_;
756
- return 1 if defined $c->{r};
757
- if ($c->{l} && $c->{l}->[-1] eq "...\n" &&
758
- $c->{a_raw} =~ /\@([a-f\d\-]+)>$/) {
759
- my @msg = command(qw/cat-file commit/, $c->{c});
760
- shift @msg while ($msg[0] ne "\n");
761
- shift @msg;
762
- @{$c->{l}} = grep !/^git-svn-id: /, @msg;
763
-
764
- (undef, $c->{r}, undef) = extract_metadata(
765
- (grep(/^git-svn-id: /, @msg))[-1]);
766
- }
767
- return defined $c->{r};
768
-}
769
-
770
-sub log_use_color {
771
- return 1 if $_color;
772
- my ($dc, $dcvar);
773
- $dcvar = 'color.diff';
774
- $dc = `git-config --get $dcvar`;
775
- if ($dc eq '') {
776
- # nothing at all; fallback to "diff.color"
777
- $dcvar = 'diff.color';
778
- $dc = `git-config --get $dcvar`;
779
- }
780
- chomp($dc);
781
- if ($dc eq 'auto') {
782
- my $pc;
783
- $pc = `git-config --get color.pager`;
784
- if ($pc eq '') {
785
- # does not have it -- fallback to pager.color
786
- $pc = `git-config --bool --get pager.color`;
787
- }
788
- else {
789
- $pc = `git-config --bool --get color.pager`;
790
- if ($?) {
791
- $pc = 'false';
792
- }
793
- }
794
- chomp($pc);
795
- if (-t *STDOUT || (defined $_pager && $pc eq 'true')) {
796
- return ($ENV{TERM} && $ENV{TERM} ne 'dumb');
797
- }
798
- return 0;
799
- }
800
- return 0 if $dc eq 'never';
801
- return 1 if $dc eq 'always';
802
- chomp($dc = `git-config --bool --get $dcvar`);
803
- return ($dc eq 'true');
804
-}
805
-
806
-sub git_svn_log_cmd {
807
- my ($r_min, $r_max) = @_;
808
- my @cmd = (qw/log --abbrev-commit --pretty=raw
809
- --default/, "refs/remotes/$GIT_SVN");
810
- push @cmd, '-r' unless $_non_recursive;
811
- push @cmd, qw/--raw --name-status/ if $_verbose;
812
- push @cmd, '--color' if log_use_color();
813
- return @cmd unless defined $r_max;
814
- if ($r_max == $r_min) {
815
- push @cmd, '--max-count=1';
816
- if (my $c = revdb_get($REVDB, $r_max)) {
817
- push @cmd, $c;
818
- }
819
- } else {
820
- my ($c_min, $c_max);
821
- $c_max = revdb_get($REVDB, $r_max);
822
- $c_min = revdb_get($REVDB, $r_min);
823
- if (defined $c_min && defined $c_max) {
824
- if ($r_max > $r_max) {
825
- push @cmd, "$c_min..$c_max";
826
- } else {
827
- push @cmd, "$c_max..$c_min";
828
- }
829
- } elsif ($r_max > $r_min) {
830
- push @cmd, $c_max;
831
- } else {
832
- push @cmd, $c_min;
833
- }
834
- }
835
- return @cmd;
836
-}
837
-
675
sub fetch_child_id {
676
my $id = shift;
677
print "Fetching $id\n";
@@ -1484,22 +1321,16 @@ sub load_all_refs {
1321
# '<svn username> = real-name <email address>' mapping based on git-svnimport:
1322
sub load_authors {
1323
open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1324
+ my $log = $cmd eq 'log';
1325
while (<$authors>) {
1326
chomp;
1327
next unless /^(\S+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
1328
my ($user, $name, $email) = ($1, $2, $3);
1491
- $users{$user} = [$name, $email];
1492
- }
1493
- close $authors or croak $!;
1494
-}
1495
-
1496
-sub rload_authors {
1497
- open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1498
- while (<$authors>) {
1499
- chomp;
1500
- next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
1501
- my ($user, $name, $email) = ($1, $2, $3);
1502
- $rusers{"$name <$email>"} = $user;
1329
+ if ($log) {
1330
+ $Git::SVN::Log::rusers{"$name <$email>"} = $user;
1331
+ } else {
1332
+ $users{$user} = [$name, $email];
1333
+ }
1334
}
1335
close $authors or croak $!;
1336
}
@@ -1769,140 +1600,6 @@ sub tz_to_s_offset {
1600
return ($1 * 60) + ($tz * 3600);
1601
}
1602
1772
-# adapted from pager.c
1773
-sub config_pager {
1774
- $_pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};
1775
- if (!defined $_pager) {
1776
- $_pager = 'less';
1777
- } elsif (length $_pager == 0 || $_pager eq 'cat') {
1778
- $_pager = undef;
1779
- }
1780
-}
1781
-
1782
-sub run_pager {
1783
- return unless -t *STDOUT;
1784
- pipe my $rfd, my $wfd or return;
1785
- defined(my $pid = fork) or croak $!;
1786
- if (!$pid) {
1787
- open STDOUT, '>&', $wfd or croak $!;
1788
- return;
1789
- }
1790
- open STDIN, '<&', $rfd or croak $!;
1791
- $ENV{LESS} ||= 'FRSX';
1792
- exec $_pager or croak "Can't run pager: $! ($_pager)\n";
1793
-}
1794
-
1795
-sub get_author_info {
1796
- my ($dest, $author, $t, $tz) = @_;
1797
- $author =~ s/(?:^\s*|\s*$)//g;
1798
- $dest->{a_raw} = $author;
1799
- my $_a;
1800
- if ($_authors) {
1801
- $_a = $rusers{$author} || undef;
1802
- }
1803
- if (!$_a) {
1804
- ($_a) = ($author =~ /<([^>]+)\@[^>]+>$/);
1805
- }
1806
- $dest->{t} = $t;
1807
- $dest->{tz} = $tz;
1808
- $dest->{a} = $_a;
1809
- # Date::Parse isn't in the standard Perl distro :(
1810
- if ($tz =~ s/^\+//) {
1811
- $t += tz_to_s_offset($tz);
1812
- } elsif ($tz =~ s/^\-//) {
1813
- $t -= tz_to_s_offset($tz);
1814
- }
1815
- $dest->{t_utc} = $t;
1816
-}
1817
-
1818
-sub process_commit {
1819
- my ($c, $r_min, $r_max, $defer) = @_;
1820
- if (defined $r_min && defined $r_max) {
1821
- if ($r_min == $c->{r} && $r_min == $r_max) {
1822
- show_commit($c);
1823
- return 0;
1824
- }
1825
- return 1 if $r_min == $r_max;
1826
- if ($r_min < $r_max) {
1827
- # we need to reverse the print order
1828
- return 0 if (defined $_limit && --$_limit < 0);
1829
- push @$defer, $c;
1830
- return 1;
1831
- }
1832
- if ($r_min != $r_max) {
1833
- return 1 if ($r_min < $c->{r});
1834
- return 1 if ($r_max > $c->{r});
1835
- }
1836
- }
1837
- return 0 if (defined $_limit && --$_limit < 0);
1838
- show_commit($c);
1839
- return 1;
1840
-}
1841
-
1842
-sub show_commit {
1843
- my $c = shift;
1844
- if ($_oneline) {
1845
- my $x = "\n";
1846
- if (my $l = $c->{l}) {
1847
- while ($l->[0] =~ /^\s*$/) { shift @$l }
1848
- $x = $l->[0];
1849
- }
1850
- $_l_fmt ||= 'A' . length($c->{r});
1851
- print 'r',pack($_l_fmt, $c->{r}),' | ';
1852
- print "$c->{c} | " if $_show_commit;
1853
- print $x;
1854
- } else {
1855
- show_commit_normal($c);
1856
- }
1857
-}
1858
-
1859
-sub show_commit_changed_paths {
1860
- my ($c) = @_;
1861
- return unless $c->{changed};
1862
- print "Changed paths:\n", @{$c->{changed}};
1863
-}
1864
-
1865
-sub show_commit_normal {
1866
- my ($c) = @_;
1867
- print '-' x72, "\nr$c->{r} | ";
1868
- print "$c->{c} | " if $_show_commit;
1869
- print "$c->{a} | ", strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
1870
- localtime($c->{t_utc})), ' | ';
1871
- my $nr_line = 0;
1872
-
1873
- if (my $l = $c->{l}) {
1874
- while ($l->[$#$l] eq "\n" && $#$l > 0
1875
- && $l->[($#$l - 1)] eq "\n") {
1876
- pop @$l;
1877
- }
1878
- $nr_line = scalar @$l;
1879
- if (!$nr_line) {
1880
- print "1 line\n\n\n";
1881
- } else {
1882
- if ($nr_line == 1) {
1883
- $nr_line = '1 line';
1884
- } else {
1885
- $nr_line .= ' lines';
1886
- }
1887
- print $nr_line, "\n";
1888
- show_commit_changed_paths($c);
1889
- print "\n";
1890
- print $_ foreach @$l;
1891
- }
1892
- } else {
1893
- print "1 line\n";
1894
- show_commit_changed_paths($c);
1895
- print "\n";
1896
-
1897
- }
1898
- foreach my $x (qw/raw diff/) {
1899
- if ($c->{$x}) {
1900
- print "\n";
1901
- print $_ foreach @{$c->{$x}}
1902
- }
1903
- }
1904
-}
1905
-
1603
package Git::SVN;
1604
use strict;
1605
use warnings;
@@ -3516,6 +3213,307 @@ sub can_do_switch {
3213
$can_do_switch;
3214
}
3215
3216
+package Git::SVN::Log;
3217
+use strict;
3218
+use warnings;
3219
+use POSIX qw/strftime/;
3220
+use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
3221
+ %rusers $show_commit $incremental/;
3222
+my $l_fmt;
3223
+
3224
+sub cmt_showable {
3225
+ my ($c) = @_;
3226
+ return 1 if defined $c->{r};
3227
+ if ($c->{l} && $c->{l}->[-1] eq "...\n" &&
3228
+ $c->{a_raw} =~ /\@([a-f\d\-]+)>$/) {
3229
+ my @msg = command(qw/cat-file commit/, $c->{c});
3230
+ shift @msg while ($msg[0] ne "\n");
3231
+ shift @msg;
3232
+ @{$c->{l}} = grep !/^git-svn-id: /, @msg;
3233
+
3234
+ (undef, $c->{r}, undef) = ::extract_metadata(
3235
+ (grep(/^git-svn-id: /, @msg))[-1]);
3236
+ }
3237
+ return defined $c->{r};
3238
+}
3239
+
3240
+sub log_use_color {
3241
+ return 1 if $color;
3242
+ my ($dc, $dcvar);
3243
+ $dcvar = 'color.diff';
3244
+ $dc = `git-config --get $dcvar`;
3245
+ if ($dc eq '') {
3246
+ # nothing at all; fallback to "diff.color"
3247
+ $dcvar = 'diff.color';
3248
+ $dc = `git-config --get $dcvar`;
3249
+ }
3250
+ chomp($dc);
3251
+ if ($dc eq 'auto') {
3252
+ my $pc;
3253
+ $pc = `git-config --get color.pager`;
3254
+ if ($pc eq '') {
3255
+ # does not have it -- fallback to pager.color
3256
+ $pc = `git-config --bool --get pager.color`;
3257
+ }
3258
+ else {
3259
+ $pc = `git-config --bool --get color.pager`;
3260
+ if ($?) {
3261
+ $pc = 'false';
3262
+ }
3263
+ }
3264
+ chomp($pc);
3265
+ if (-t *STDOUT || (defined $pager && $pc eq 'true')) {
3266
+ return ($ENV{TERM} && $ENV{TERM} ne 'dumb');
3267
+ }
3268
+ return 0;
3269
+ }
3270
+ return 0 if $dc eq 'never';
3271
+ return 1 if $dc eq 'always';
3272
+ chomp($dc = `git-config --bool --get $dcvar`);
3273
+ return ($dc eq 'true');
3274
+}
3275
+
3276
+sub git_svn_log_cmd {
3277
+ my ($r_min, $r_max) = @_;
3278
+ my $gs = Git::SVN->_new;
3279
+ my @cmd = (qw/log --abbrev-commit --pretty=raw --default/,
3280
+ $gs->refname);
3281
+ push @cmd, '-r' unless $non_recursive;
3282
+ push @cmd, qw/--raw --name-status/ if $verbose;
3283
+ push @cmd, '--color' if log_use_color();
3284
+ return @cmd unless defined $r_max;
3285
+ if ($r_max == $r_min) {
3286
+ push @cmd, '--max-count=1';
3287
+ if (my $c = $gs->rev_db_get($r_max)) {
3288
+ push @cmd, $c;
3289
+ }
3290
+ } else {
3291
+ my ($c_min, $c_max);
3292
+ $c_max = $gs->rev_db_get($r_max);
3293
+ $c_min = $gs->rev_db_get($r_min);
3294
+ if (defined $c_min && defined $c_max) {
3295
+ if ($r_max > $r_max) {
3296
+ push @cmd, "$c_min..$c_max";
3297
+ } else {
3298
+ push @cmd, "$c_max..$c_min";
3299
+ }
3300
+ } elsif ($r_max > $r_min) {
3301
+ push @cmd, $c_max;
3302
+ } else {
3303
+ push @cmd, $c_min;
3304
+ }
3305
+ }
3306
+ return @cmd;
3307
+}
3308
+
3309
+# adapted from pager.c
3310
+sub config_pager {
3311
+ $pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};
3312
+ if (!defined $pager) {
3313
+ $pager = 'less';
3314
+ } elsif (length $pager == 0 || $pager eq 'cat') {
3315
+ $pager = undef;
3316
+ }
3317
+}
3318
+
3319
+sub run_pager {
3320
+ return unless -t *STDOUT;
3321
+ pipe my $rfd, my $wfd or return;
3322
+ defined(my $pid = fork) or ::fatal "Can't fork: $!\n";
3323
+ if (!$pid) {
3324
+ open STDOUT, '>&', $wfd or
3325
+ ::fatal "Can't redirect to stdout: $!\n";
3326
+ return;
3327
+ }
3328
+ open STDIN, '<&', $rfd or ::fatal "Can't redirect stdin: $!\n";
3329
+ $ENV{LESS} ||= 'FRSX';
3330
+ exec $pager or ::fatal "Can't run pager: $! ($pager)\n";
3331
+}
3332
+
3333
+sub get_author_info {
3334
+ my ($dest, $author, $t, $tz) = @_;
3335
+ $author =~ s/(?:^\s*|\s*$)//g;
3336
+ $dest->{a_raw} = $author;
3337
+ my $au;
3338
+ if ($_authors) {
3339
+ $au = $rusers{$author} || undef;
3340
+ }
3341
+ if (!$au) {
3342
+ ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
3343
+ }
3344
+ $dest->{t} = $t;
3345
+ $dest->{tz} = $tz;
3346
+ $dest->{a} = $au;
3347
+ # Date::Parse isn't in the standard Perl distro :(
3348
+ if ($tz =~ s/^\+//) {
3349
+ $t += ::tz_to_s_offset($tz);
3350
+ } elsif ($tz =~ s/^\-//) {
3351
+ $t -= ::tz_to_s_offset($tz);
3352
+ }
3353
+ $dest->{t_utc} = $t;
3354
+}
3355
+
3356
+sub process_commit {
3357
+ my ($c, $r_min, $r_max, $defer) = @_;
3358
+ if (defined $r_min && defined $r_max) {
3359
+ if ($r_min == $c->{r} && $r_min == $r_max) {
3360
+ show_commit($c);
3361
+ return 0;
3362
+ }
3363
+ return 1 if $r_min == $r_max;
3364
+ if ($r_min < $r_max) {
3365
+ # we need to reverse the print order
3366
+ return 0 if (defined $limit && --$limit < 0);
3367
+ push @$defer, $c;
3368
+ return 1;
3369
+ }
3370
+ if ($r_min != $r_max) {
3371
+ return 1 if ($r_min < $c->{r});
3372
+ return 1 if ($r_max > $c->{r});
3373
+ }
3374
+ }
3375
+ return 0 if (defined $limit && --$limit < 0);
3376
+ show_commit($c);
3377
+ return 1;
3378
+}
3379
+
3380
+sub show_commit {
3381
+ my $c = shift;
3382
+ if ($oneline) {
3383
+ my $x = "\n";
3384
+ if (my $l = $c->{l}) {
3385
+ while ($l->[0] =~ /^\s*$/) { shift @$l }
3386
+ $x = $l->[0];
3387
+ }
3388
+ $l_fmt ||= 'A' . length($c->{r});
3389
+ print 'r',pack($l_fmt, $c->{r}),' | ';
3390
+ print "$c->{c} | " if $show_commit;
3391
+ print $x;
3392
+ } else {
3393
+ show_commit_normal($c);
3394
+ }
3395
+}
3396
+
3397
+sub show_commit_changed_paths {
3398
+ my ($c) = @_;
3399
+ return unless $c->{changed};
3400
+ print "Changed paths:\n", @{$c->{changed}};
3401
+}
3402
+
3403
+sub show_commit_normal {
3404
+ my ($c) = @_;
3405
+ print '-' x72, "\nr$c->{r} | ";
3406
+ print "$c->{c} | " if $show_commit;
3407
+ print "$c->{a} | ", strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
3408
+ localtime($c->{t_utc})), ' | ';
3409
+ my $nr_line = 0;
3410
+
3411
+ if (my $l = $c->{l}) {
3412
+ while ($l->[$#$l] eq "\n" && $#$l > 0
3413
+ && $l->[($#$l - 1)] eq "\n") {
3414
+ pop @$l;
3415
+ }
3416
+ $nr_line = scalar @$l;
3417
+ if (!$nr_line) {
3418
+ print "1 line\n\n\n";
3419
+ } else {
3420
+ if ($nr_line == 1) {
3421
+ $nr_line = '1 line';
3422
+ } else {
3423
+ $nr_line .= ' lines';
3424
+ }
3425
+ print $nr_line, "\n";
3426
+ show_commit_changed_paths($c);
3427
+ print "\n";
3428
+ print $_ foreach @$l;
3429
+ }
3430
+ } else {
3431
+ print "1 line\n";
3432
+ show_commit_changed_paths($c);
3433
+ print "\n";
3434
+
3435
+ }
3436
+ foreach my $x (qw/raw diff/) {
3437
+ if ($c->{$x}) {
3438
+ print "\n";
3439
+ print $_ foreach @{$c->{$x}}
3440
+ }
3441
+ }
3442
+}
3443
+
3444
+sub cmd_show_log {
3445
+ my (@args) = @_;
3446
+ my ($r_min, $r_max);
3447
+ my $r_last = -1; # prevent dupes
3448
+ if (defined $TZ) {
3449
+ $ENV{TZ} = $TZ;
3450
+ } else {
3451
+ delete $ENV{TZ};
3452
+ }
3453
+ if (defined $::_revision) {
3454
+ if ($::_revision =~ /^(\d+):(\d+)$/) {
3455
+ ($r_min, $r_max) = ($1, $2);
3456
+ } elsif ($::_revision =~ /^\d+$/) {
3457
+ $r_min = $r_max = $::_revision;
3458
+ } else {
3459
+ ::fatal "-r$::_revision is not supported, use ",
3460
+ "standard \'git log\' arguments instead\n";
3461
+ }
3462
+ }
3463
+
3464
+ config_pager();
3465
+ @args = (git_svn_log_cmd($r_min, $r_max), @args);
3466
+ my $log = command_output_pipe(@args);
3467
+ run_pager();
3468
+ my (@k, $c, $d);
3469
+ my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
3470
+ while (<$log>) {
3471
+ if (/^${esc_color}commit ($::sha1_short)/o) {
3472
+ my $cmt = $1;
3473
+ if ($c && cmt_showable($c) && $c->{r} != $r_last) {
3474
+ $r_last = $c->{r};
3475
+ process_commit($c, $r_min, $r_max, \@k) or
3476
+ goto out;
3477
+ }
3478
+ $d = undef;
3479
+ $c = { c => $cmt };
3480
+ } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
3481
+ get_author_info($c, $1, $2, $3);
3482
+ } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
3483
+ # ignore
3484
+ } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
3485
+ push @{$c->{raw}}, $_;
3486
+ } elsif (/^${esc_color}[ACRMDT]\t/) {
3487
+ # we could add $SVN->{svn_path} here, but that requires
3488
+ # remote access at the moment (repo_path_split)...
3489
+ s#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
3490
+ push @{$c->{changed}}, $_;
3491
+ } elsif (/^${esc_color}diff /o) {
3492
+ $d = 1;
3493
+ push @{$c->{diff}}, $_;
3494
+ } elsif ($d) {
3495
+ push @{$c->{diff}}, $_;
3496
+ } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
3497
+ ($c->{url}, $c->{r}, undef) = ::extract_metadata($1);
3498
+ } elsif (s/^${esc_color} //o) {
3499
+ push @{$c->{l}}, $_;
3500
+ }
3501
+ }
3502
+ if ($c && defined $c->{r} && $c->{r} != $r_last) {
3503
+ $r_last = $c->{r};
3504
+ process_commit($c, $r_min, $r_max, \@k);
3505
+ }
3506
+ if (@k) {
3507
+ my $swap = $r_max;
3508
+ $r_max = $r_min;
3509
+ $r_min = $swap;
3510
+ process_commit($_, $r_min, $r_max) foreach reverse @k;
3511
+ }
3512
+out:
3513
+ eval { command_close_pipe($log) };
3514
+ print '-' x72,"\n" unless $incremental || $oneline;
3515
+}
3516
+
3517
__END__
3518
3519
Data structures: