4 use Git
::SVN
::Utils
qw(fatal);
10 use POSIX qw
/strftime/;
11 use constant commit_log_separator
=> ('-' x
72) . "\n";
12 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
13 %rusers $show_commit $incremental/;
15 # Option set in git-svn
20 return 1 if defined $c->{r
};
22 # big commit message got truncated by the 16k pretty buffer in rev-list
23 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
24 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
26 my @log = command
(qw
/cat-file commit/, $c->{c
});
28 # shift off the headers
29 shift @log while ($log[0] ne '');
32 # TODO: make $c->{l} not have a trailing newline in the future
33 @
{$c->{l
}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
35 (undef, $c->{r
}, undef) = ::extract_metadata
(
36 (grep(/^git-svn-id: /, @log))[-1]);
38 return defined $c->{r
};
42 return $color || Git
->repository->get_colorbool('color.diff');
46 my ($r_min, $r_max, @args) = @_;
48 my (@files, @log_opts);
49 foreach my $x (@args) {
50 if ($x eq '--' || @files) {
53 if (::verify_ref
("$x^0")) {
61 my ($url, $rev, $uuid, $gs) = ::working_head_info
($head);
64 $gs ||= Git
::SVN
->_new;
65 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
67 push @cmd, '-r' unless $non_recursive;
68 push @cmd, qw
/--raw --name-status/ if $verbose;
69 push @cmd, '--color' if log_use_color
();
71 if (defined $r_max && $r_max == $r_min) {
72 push @cmd, '--max-count=1';
73 if (my $c = $gs->rev_map_get($r_max)) {
76 } elsif (defined $r_max) {
77 if ($r_max < $r_min) {
78 ($r_min, $r_max) = ($r_max, $r_min);
80 my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min);
81 my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max);
82 # If there are no commits in the range, both $c_max and $c_min
83 # will be undefined. If there is at least 1 commit in the
84 # range, both will be defined.
85 return () if !defined $c_min || !defined $c_max;
86 if ($c_min eq $c_max) {
87 push @cmd, '--max-count=1', $c_min;
89 push @cmd, '--boundary', "$c_min..$c_max";
92 return (@cmd, @files);
95 # adapted from pager.c
98 $ENV{GIT_PAGER_IN_USE
} = 'false';
102 chomp($pager = command_oneline
(qw(var GIT_PAGER)));
103 if ($pager eq 'cat') {
106 $ENV{GIT_PAGER_IN_USE
} = defined($pager);
110 return unless defined $pager;
111 pipe my ($rfd, $wfd) or return;
112 defined(my $pid = fork) or fatal
"Can't fork: $!";
114 open STDOUT
, '>&', $wfd or
115 fatal
"Can't redirect to stdout: $!";
118 open STDIN
, '<&', $rfd or fatal
"Can't redirect stdin: $!";
119 $ENV{LESS
} ||= 'FRSX';
121 exec $pager or fatal
"Can't run pager: $! ($pager)";
124 sub format_svn_date
{
125 my $t = shift || time;
127 my $gmoff = get_tz_offset
($t);
128 return strftime
("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
133 # Date::Parse isn't in the standard Perl distro :(
134 if ($tz =~ s/^\+//) {
135 $t += tz_to_s_offset
($tz);
136 } elsif ($tz =~ s/^\-//) {
137 $t -= tz_to_s_offset
($tz);
142 sub set_local_timezone
{
153 return ($1 * 60) + ($tz * 3600);
156 sub get_author_info
{
157 my ($dest, $author, $t, $tz) = @_;
158 $author =~ s/(?:^\s*|\s*$)//g;
159 $dest->{a_raw
} = $author;
162 $au = $rusers{$author} || undef;
165 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
170 $dest->{t_utc
} = parse_git_date
($t, $tz);
174 my ($c, $r_min, $r_max, $defer) = @_;
175 if (defined $r_min && defined $r_max) {
176 if ($r_min == $c->{r
} && $r_min == $r_max) {
180 return 1 if $r_min == $r_max;
181 if ($r_min < $r_max) {
182 # we need to reverse the print order
183 return 0 if (defined $limit && --$limit < 0);
187 if ($r_min != $r_max) {
188 return 1 if ($r_min < $c->{r
});
189 return 1 if ($r_max > $c->{r
});
192 return 0 if (defined $limit && --$limit < 0);
202 if (my $l = $c->{l
}) {
203 while ($l->[0] =~ /^\s*$/) { shift @
$l }
206 $l_fmt ||= 'A' . length($c->{r
});
207 print 'r',pack($l_fmt, $c->{r
}),' | ';
208 print "$c->{c} | " if $show_commit;
211 show_commit_normal
($c);
215 sub show_commit_changed_paths
{
217 return unless $c->{changed
};
218 print "Changed paths:\n", @
{$c->{changed
}};
221 sub show_commit_normal
{
223 print commit_log_separator
, "r$c->{r} | ";
224 print "$c->{c} | " if $show_commit;
225 print "$c->{a} | ", format_svn_date
($c->{t_utc
}), ' | ';
228 if (my $l = $c->{l
}) {
229 while ($l->[$#$l] eq "\n" && $#$l > 0
230 && $l->[($#$l - 1)] eq "\n") {
233 $nr_line = scalar @
$l;
235 print "1 line\n\n\n";
240 $nr_line .= ' lines';
242 print $nr_line, "\n";
243 show_commit_changed_paths
($c);
245 print $_ foreach @
$l;
249 show_commit_changed_paths
($c);
253 foreach my $x (qw
/raw stat diff/) {
256 print $_ foreach @
{$c->{$x}}
264 my $r_last = -1; # prevent dupes
265 set_local_timezone
();
266 if (defined $::_revision
) {
267 if ($::_revision
=~ /^(\d+):(\d+)$/) {
268 ($r_min, $r_max) = ($1, $2);
269 } elsif ($::_revision
=~ /^\d+$/) {
270 $r_min = $r_max = $::_revision
;
272 fatal
"-r$::_revision is not supported, use ",
273 "standard 'git log' arguments instead";
278 @args = git_svn_log_cmd
($r_min, $r_max, @args);
280 print commit_log_separator
unless $incremental || $oneline;
283 my $log = command_output_pipe
(@args);
285 my (@k, $c, $d, $stat);
286 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
288 if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
290 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
292 process_commit
($c, $r_min, $r_max, \
@k) or
297 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
298 get_author_info
($c, $1, $2, $3);
299 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
301 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
302 push @
{$c->{raw
}}, $_;
303 } elsif (/^${esc_color}[ACRMDT]\t/) {
304 # we could add $SVN->{svn_path} here, but that requires
305 # remote access at the moment (repo_path_split)...
306 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
307 push @
{$c->{changed
}}, $_;
308 } elsif (/^${esc_color}diff /o) {
310 push @
{$c->{diff
}}, $_;
312 push @
{$c->{diff
}}, $_;
313 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
314 $esc_color*[\
+\
-]*$esc_color$/x
) {
316 push @
{$c->{stat}}, $_;
317 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
318 push @
{$c->{stat}}, $_;
320 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
321 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
322 } elsif (s/^${esc_color} //o) {
326 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
328 process_commit
($c, $r_min, $r_max, \
@k);
331 ($r_min, $r_max) = ($r_max, $r_min);
332 process_commit
($_, $r_min, $r_max) foreach reverse @k;
336 print commit_log_separator
unless $incremental || $oneline;
345 my ($fh, $ctx, $rev);
348 ($fh, $ctx) = command_output_pipe
('blame', @_, $path);
349 while (my $line = <$fh>) {
350 if ($line =~ /^\^?([[:xdigit:]]+)\s/) {
351 # Uncommitted edits show up as a rev ID of
352 # all zeros, which we can't look up with
355 (undef, $rev, undef) =
357 $rev = '0' if (!$rev);
361 $rev = sprintf('%-10s', $rev);
362 $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/;
367 ($fh, $ctx) = command_output_pipe
('blame', '-p', @_, 'HEAD',
372 my %dsha; #distinct sha keys
374 while (my $line = <$fh>) {
376 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
381 my $s2r = ::cmt_sha2rev_batch
([keys %dsha]);
383 foreach my $line (@buffer) {
384 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
386 $rev = '0' if (!$rev)
388 elsif ($line =~ /^author (.*)/) {
390 $authors{$rev} =~ s/\s/_/g;
392 elsif ($line =~ /^\t(.*)$/) {
393 printf("%6s %10s %s\n", $rev, $authors{$rev}, $1);
397 command_close_pipe
($fh, $ctx);