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

git-svn: fix log with single revision against a non-HEAD branch

Running git-svn log <ref> -r<rev> against a <ref> other than the current HEAD did not work if the <rev> was exclusive to the other branch. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Aug 15, 2007 at 09:55 UTC 6ed77266c6e85130920ef30cd290d36ad4464695
2 files changed +63 -9
git-svn.perl
+15 -9
@@ -3501,11 +3501,17 @@ sub log_use_color {
3501 sub git_svn_log_cmd {
3502 my ($r_min, $r_max, @args) = @_;
3503 my $head = 'HEAD';
3504 + my (@files, @log_opts);
3505 foreach my $x (@args) {
3505 - last if $x eq '--';
3506 - next unless ::verify_ref("$x^0");
3507 - $head = $x;
3508 - last;
3506 + if ($x eq '--' || @files) {
3507 + push @files, $x;
3508 + } else {
3509 + if (::verify_ref("$x^0")) {
3510 + $head = $x;
3511 + } else {
3512 + push @log_opts, $x;
3513 + }
3514 + }
3515 }
3516
3517 my ($url, $rev, $uuid, $gs) = ::working_head_info($head);
@@ -3515,13 +3521,13 @@ sub git_svn_log_cmd {
3521 push @cmd, '-r' unless $non_recursive;
3522 push @cmd, qw/--raw --name-status/ if $verbose;
3523 push @cmd, '--color' if log_use_color();
3518 - return @cmd unless defined $r_max;
3519 - if ($r_max == $r_min) {
3524 + push @cmd, @log_opts;
3525 + if (defined $r_max && $r_max == $r_min) {
3526 push @cmd, '--max-count=1';
3527 if (my $c = $gs->rev_db_get($r_max)) {
3528 push @cmd, $c;
3529 }
3524 - } else {
3530 + } elsif (defined $r_max) {
3531 my ($c_min, $c_max);
3532 $c_max = $gs->rev_db_get($r_max);
3533 $c_min = $gs->rev_db_get($r_min);
@@ -3537,7 +3543,7 @@ sub git_svn_log_cmd {
3543 push @cmd, $c_min;
3544 }
3545 }
3540 - return @cmd;
3546 + return (@cmd, @files);
3547 }
3548
3549 # adapted from pager.c
@@ -3702,7 +3708,7 @@ sub cmd_show_log {
3708 }
3709
3710 config_pager();
3705 - @args = (git_svn_log_cmd($r_min, $r_max, @args), @args);
3711 + @args = git_svn_log_cmd($r_min, $r_max, @args);
3712 my $log = command_output_pipe(@args);
3713 run_pager();
3714 my (@k, $c, $d, $stat);
t/t9116-git-svn-log.sh new
+48
@@ -0,0 +1,48 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Eric Wong
4 +#
5 +
6 +test_description='git-svn log tests'
7 +. ./lib-git-svn.sh
8 +
9 +test_expect_success 'setup repository and import' "
10 + mkdir import &&
11 + cd import &&
12 + for i in trunk branches/a branches/b \
13 + tags/0.1 tags/0.2 tags/0.3; do
14 + mkdir -p \$i && \
15 + echo hello >> \$i/README || exit 1
16 + done && \
17 + svn import -m test . $svnrepo
18 + cd .. &&
19 + git-svn init $svnrepo -T trunk -b branches -t tags &&
20 + git-svn fetch &&
21 + git reset --hard trunk &&
22 + echo bye >> README &&
23 + git commit -a -m bye &&
24 + git svn dcommit &&
25 + git reset --hard a &&
26 + echo why >> FEEDME &&
27 + git update-index --add FEEDME &&
28 + git commit -m feedme &&
29 + git svn dcommit &&
30 + git reset --hard trunk &&
31 + echo aye >> README &&
32 + git commit -a -m aye &&
33 + git svn dcommit
34 + "
35 +
36 +test_expect_success 'run log' "
37 + git reset --hard a &&
38 + git svn log -r2 trunk | grep ^r2 &&
39 + git svn log -r4 trunk | grep ^r4 &&
40 + git svn log -r3 | grep ^r3
41 + "
42 +
43 +test_expect_success 'run log against a from trunk' "
44 + git reset --hard trunk &&
45 + git svn log -r3 a | grep ^r3
46 + "
47 +
48 +test_done