From 41337e22f0513c8a0ed603e30feb1fecaeb1649e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Nov 2007 12:47:16 -0800 Subject: [PATCH 1/6] git-svn: add tests for command-line usage of init and clone commands Some patches broke these commands in certain cases and were only caught by manual testing. Signed-off-by: Eric Wong --- t/t9117-git-svn-init-clone.sh | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 t/t9117-git-svn-init-clone.sh diff --git a/t/t9117-git-svn-init-clone.sh b/t/t9117-git-svn-init-clone.sh new file mode 100755 index 00000000000000..d482b407f2ae17 --- /dev/null +++ b/t/t9117-git-svn-init-clone.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Copyright (c) 2007 Eric Wong +# + +test_description='git-svn init/clone tests' + +. ./lib-git-svn.sh + +# setup, run inside tmp so we don't have any conflicts with $svnrepo +set -e +rm -r .git +mkdir tmp +cd tmp + +test_expect_success 'setup svnrepo' " + mkdir project project/trunk project/branches project/tags && + echo foo > project/trunk/foo && + svn import -m '$test_description' project $svnrepo/project && + rm -rf project + " + +test_expect_success 'basic clone' " + test ! -d trunk && + git svn clone $svnrepo/project/trunk && + test -d trunk/.git/svn && + test -e trunk/foo && + rm -rf trunk + " + +test_expect_success 'clone to target directory' " + test ! -d target && + git svn clone $svnrepo/project/trunk target && + test -d target/.git/svn && + test -e target/foo && + rm -rf target + " + +test_expect_success 'clone with --stdlayout' " + test ! -d project && + git svn clone -s $svnrepo/project && + test -d project/.git/svn && + test -e project/foo && + rm -rf project + " + +test_expect_success 'clone to target directory with --stdlayout' " + test ! -d target && + git svn clone -s $svnrepo/project target && + test -d target/.git/svn && + test -e target/foo && + rm -rf target + " + +test_done From 3caf320ba8fc8277b5875fe306efbfa333b92487 Mon Sep 17 00:00:00 2001 From: "Konstantin V. Arkhipov" Date: Wed, 14 Nov 2007 03:52:02 +0300 Subject: [PATCH 2/6] git-svn's dcommit must use subversion's config When doing dcommit git-svn must use subversion's config or newly created files will not include svn's properties (defined in [auto-props] with 'enable-auto-props = yes'). Signed-off-by: Konstantin V. Arkhipov Acked-by: Eric Wong --- git-svn.perl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-svn.perl b/git-svn.perl index e3e00fdcc5f4b0..a5cf757cf605a0 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -425,6 +425,9 @@ sub cmd_dcommit { my %ed_opts = ( r => $last_rev, log => get_commit_entry($d)->{log}, ra => Git::SVN::Ra->new($gs->full_url), + config => SVN::Core::config_get_config( + $Git::SVN::Ra::config_dir + ), tree_a => "$d~1", tree_b => $d, editor_cb => sub { From fede44b2e18c1e5985197913e8dcf5753f4eb99e Mon Sep 17 00:00:00 2001 From: David D Kilzer Date: Sat, 10 Nov 2007 22:10:33 -0800 Subject: [PATCH 3/6] git-svn log: fix ascending revision ranges Fixed typo in Git::SVN::Log::git_svn_log_cmd(). Previously a command like "git-svn log -r1:4" would only show a commit log separator. Added tests for ascending and descending revision ranges. Signed-off-by: David D Kilzer Acked-by: Eric Wong --- git-svn.perl | 2 +- t/t9116-git-svn-log.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index a5cf757cf605a0..1872214dec51f7 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -3798,7 +3798,7 @@ sub git_svn_log_cmd { $c_max = $gs->rev_db_get($r_max); $c_min = $gs->rev_db_get($r_min); if (defined $c_min && defined $c_max) { - if ($r_max > $r_max) { + if ($r_max > $r_min) { push @cmd, "$c_min..$c_max"; } else { push @cmd, "$c_max..$c_min"; diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index 0d4e6b3f040a2c..618d7e9c003cc5 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -45,4 +45,18 @@ test_expect_success 'run log against a from trunk' " git svn log -r3 a | grep ^r3 " +printf 'r2 \nr4 \n' > expected-range-r2-r4 + +test_expect_success 'test ascending revision range' " + git reset --hard trunk && + git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2-r4 - + " + +printf 'r4 \nr2 \n' > expected-range-r4-r2 + +test_expect_success 'test descending revision range' " + git reset --hard trunk && + git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2 - + " + test_done From 60f3ff12573e411476f7a32ab13bbb9b8063c8f7 Mon Sep 17 00:00:00 2001 From: David D Kilzer Date: Sat, 10 Nov 2007 22:10:34 -0800 Subject: [PATCH 4/6] git-svn log: include commit log for the smallest revision in a range The "svn log -rM:N" command shows commit logs inclusive in the range [M,N]. Previously "git-svn log" always excluded the commit log for the smallest revision in a range, whether the range was ascending or descending. With this patch, the smallest revision in a range is always shown. Updated tests for ascending and descending revision ranges. Signed-off-by: David D Kilzer Acked-by: Eric Wong --- git-svn.perl | 6 +++--- t/t9116-git-svn-log.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 1872214dec51f7..506e1a605d7557 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -3799,9 +3799,9 @@ sub git_svn_log_cmd { $c_min = $gs->rev_db_get($r_min); if (defined $c_min && defined $c_max) { if ($r_max > $r_min) { - push @cmd, "$c_min..$c_max"; + push @cmd, "--boundary", "$c_min..$c_max"; } else { - push @cmd, "$c_max..$c_min"; + push @cmd, "--boundary", "$c_max..$c_min"; } } elsif ($r_max > $r_min) { push @cmd, $c_max; @@ -3980,7 +3980,7 @@ sub cmd_show_log { my (@k, $c, $d, $stat); my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/; while (<$log>) { - if (/^${esc_color}commit ($::sha1_short)/o) { + if (/^${esc_color}commit -?($::sha1_short)/o) { my $cmt = $1; if ($c && cmt_showable($c) && $c->{r} != $r_last) { $r_last = $c->{r}; diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index 618d7e9c003cc5..500089208da25d 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -45,18 +45,18 @@ test_expect_success 'run log against a from trunk' " git svn log -r3 a | grep ^r3 " -printf 'r2 \nr4 \n' > expected-range-r2-r4 +printf 'r1 \nr2 \nr4 \n' > expected-range-r1-r2-r4 test_expect_success 'test ascending revision range' " git reset --hard trunk && - git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2-r4 - + git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2-r4 - " -printf 'r4 \nr2 \n' > expected-range-r4-r2 +printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1 test_expect_success 'test descending revision range' " git reset --hard trunk && - git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2 - + git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2-r1 - " test_done From 111947ef8cd3071faadb527c20047efd4330138a Mon Sep 17 00:00:00 2001 From: David D Kilzer Date: Sun, 11 Nov 2007 22:56:52 -0800 Subject: [PATCH 5/6] git-svn log: handle unreachable revisions like "svn log" When unreachable revisions are given to "svn log", it displays all commit logs in the given range that exist in the current tree. (If no commit logs are found in the current tree, it simply prints a single commit log separator.) This patch makes "git-svn log" behave the same way. Ten tests added to t/t9116-git-svn-log.sh. Signed-off-by: David D Kilzer Acked-by: Eric Wong --- git-svn.perl | 63 ++++++++++++++++++++++++++++------------ t/t9116-git-svn-log.sh | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 19 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 506e1a605d7557..0ecf7a59234de9 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -2399,10 +2399,15 @@ sub rev_db_get { $ret; } +# Finds the first svn revision that exists on (if $eq_ok is true) or +# before $rev for the current branch. It will not search any lower +# than $min_rev. Returns the git commit hash and svn revision number +# if found, else (undef, undef). sub find_rev_before { - my ($self, $rev, $eq_ok) = @_; + my ($self, $rev, $eq_ok, $min_rev) = @_; --$rev unless $eq_ok; - while ($rev > 0) { + $min_rev ||= 1; + while ($rev >= $min_rev) { if (my $c = $self->rev_db_get($rev)) { return ($rev, $c); } @@ -2411,6 +2416,23 @@ sub find_rev_before { return (undef, undef); } +# Finds the first svn revision that exists on (if $eq_ok is true) or +# after $rev for the current branch. It will not search any higher +# than $max_rev. Returns the git commit hash and svn revision number +# if found, else (undef, undef). +sub find_rev_after { + my ($self, $rev, $eq_ok, $max_rev) = @_; + ++$rev unless $eq_ok; + $max_rev ||= $self->rev_db_max(); + while ($rev <= $max_rev) { + if (my $c = $self->rev_db_get($rev)) { + return ($rev, $c); + } + ++$rev; + } + return (undef, undef); +} + sub _new { my ($class, $repo_id, $ref_id, $path) = @_; unless (defined $repo_id && length $repo_id) { @@ -3701,6 +3723,7 @@ package Git::SVN::Log; use strict; use warnings; use POSIX qw/strftime/; +use constant commit_log_separator => ('-' x 72) . "\n"; use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline %rusers $show_commit $incremental/; my $l_fmt; @@ -3794,19 +3817,19 @@ sub git_svn_log_cmd { push @cmd, $c; } } elsif (defined $r_max) { - my ($c_min, $c_max); - $c_max = $gs->rev_db_get($r_max); - $c_min = $gs->rev_db_get($r_min); - if (defined $c_min && defined $c_max) { - if ($r_max > $r_min) { - push @cmd, "--boundary", "$c_min..$c_max"; - } else { - push @cmd, "--boundary", "$c_max..$c_min"; - } - } elsif ($r_max > $r_min) { - push @cmd, $c_max; + if ($r_max < $r_min) { + ($r_min, $r_max) = ($r_max, $r_min); + } + my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min); + my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max); + # If there are no commits in the range, both $c_max and $c_min + # will be undefined. If there is at least 1 commit in the + # range, both will be defined. + return () if !defined $c_min || !defined $c_max; + if ($c_min eq $c_max) { + push @cmd, '--max-count=1', $c_min; } else { - push @cmd, $c_min; + push @cmd, '--boundary', "$c_min..$c_max"; } } return (@cmd, @files); @@ -3914,7 +3937,7 @@ sub show_commit_changed_paths { sub show_commit_normal { my ($c) = @_; - print '-' x72, "\nr$c->{r} | "; + print commit_log_separator, "r$c->{r} | "; print "$c->{c} | " if $show_commit; print "$c->{a} | ", strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime($c->{t_utc})), ' | '; @@ -3975,6 +3998,10 @@ sub cmd_show_log { config_pager(); @args = git_svn_log_cmd($r_min, $r_max, @args); + if (!@args) { + print commit_log_separator unless $incremental || $oneline; + return; + } my $log = command_output_pipe(@args); run_pager(); my (@k, $c, $d, $stat); @@ -4023,14 +4050,12 @@ sub cmd_show_log { process_commit($c, $r_min, $r_max, \@k); } if (@k) { - my $swap = $r_max; - $r_max = $r_min; - $r_min = $swap; + ($r_min, $r_max) = ($r_max, $r_min); process_commit($_, $r_min, $r_max) foreach reverse @k; } out: close $log; - print '-' x72,"\n" unless $incremental || $oneline; + print commit_log_separator unless $incremental || $oneline; } package Git::SVN::Migration; diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index 500089208da25d..902ed4145de5f4 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -30,6 +30,12 @@ test_expect_success 'setup repository and import' " git reset --hard trunk && echo aye >> README && git commit -a -m aye && + git svn dcommit && + git reset --hard b && + echo spy >> README && + git commit -a -m spy && + echo try >> README && + git commit -a -m try && git svn dcommit " @@ -59,4 +65,64 @@ test_expect_success 'test descending revision range' " git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2-r1 - " +printf 'r1 \nr2 \n' > expected-range-r1-r2 + +test_expect_success 'test ascending revision range with unreachable revision' " + git reset --hard trunk && + git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2 - + " + +printf 'r2 \nr1 \n' > expected-range-r2-r1 + +test_expect_success 'test descending revision range with unreachable revision' " + git reset --hard trunk && + git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2-r1 - + " + +printf 'r2 \n' > expected-range-r2 + +test_expect_success 'test ascending revision range with unreachable upper boundary revision and 1 commit' " + git reset --hard trunk && + git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 - + " + +test_expect_success 'test descending revision range with unreachable upper boundary revision and 1 commit' " + git reset --hard trunk && + git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 - + " + +printf 'r4 \n' > expected-range-r4 + +test_expect_success 'test ascending revision range with unreachable lower boundary revision and 1 commit' " + git reset --hard trunk && + git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + " + +test_expect_success 'test descending revision range with unreachable lower boundary revision and 1 commit' " + git reset --hard trunk && + git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + " + +printf -- '------------------------------------------------------------------------\n' > expected-separator + +test_expect_success 'test ascending revision range with unreachable boundary revisions and no commits' " + git reset --hard trunk && + git svn log -r 5:6 | diff -u expected-separator - + " + +test_expect_success 'test descending revision range with unreachable boundary revisions and no commits' " + git reset --hard trunk && + git svn log -r 6:5 | diff -u expected-separator - + " + +test_expect_success 'test ascending revision range with unreachable boundary revisions and 1 commit' " + git reset --hard trunk && + git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + " + +test_expect_success 'test descending revision range with unreachable boundary revisions and 1 commit' " + git reset --hard trunk && + git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + " + test_done From 826a93398df54d4f3874f8851da29878c14b1a88 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 13 Nov 2007 13:47:26 -0800 Subject: [PATCH 6/6] git-svn: Fix a typo and add a comma in an error message in git-svn Signed-off-by: David Reiss Acked-by: Eric Wong --- git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index 0ecf7a59234de9..5b1deeab942aa2 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -391,7 +391,7 @@ sub cmd_set_tree { sub cmd_dcommit { my $head = shift; git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) } - 'Cannot dcommit with a dirty index. Commit your changes first' + 'Cannot dcommit with a dirty index. Commit your changes first, ' . "or stash them with `git stash'.\n"; $head ||= 'HEAD'; my @refs;