From 75bd7e374ef35265dfd7c3c1896f4fb91450e50d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 4 Nov 2006 21:51:10 -0800 Subject: [PATCH 1/4] git-svn: avoid printing filenames of files we're not tracking This is purely an aesthetic change, we already skip importing of files that don't affect the subdirectory we import. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 37ecc51787..cc3335a53f 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -2662,11 +2662,12 @@ sub libsvn_connect { } sub libsvn_get_file { - my ($gui, $f, $rev) = @_; + my ($gui, $f, $rev, $chg) = @_; my $p = $f; if (length $SVN_PATH > 0) { return unless ($p =~ s#^\Q$SVN_PATH\E/##); } + print "\t$chg\t$f\n" unless $_q; my ($hash, $pid, $in, $out); my $pool = SVN::Pool->new; @@ -2769,8 +2770,7 @@ sub libsvn_fetch { $pool->clear; } foreach (@amr) { - print "\t$_->[0]\t$_->[1]\n" unless $_q; - libsvn_get_file($gui, $_->[1], $rev) + libsvn_get_file($gui, $_->[1], $rev, $_->[0]); } close $gui or croak $?; return libsvn_log_entry($rev, $author, $date, $msg, [$last_commit]); @@ -2848,8 +2848,7 @@ sub libsvn_traverse { if (defined $files) { push @$files, $file; } else { - print "\tA\t$file\n" unless $_q; - libsvn_get_file($gui, $file, $rev); + libsvn_get_file($gui, $file, $rev, 'A'); } } } From a35a045874379467395e0909958827ad89afc03d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 4 Nov 2006 21:51:11 -0800 Subject: [PATCH 2/4] git-svn: don't die on rebuild when --upgrade is specified --copy-remote and --upgrade are rarely (never?) used together, so if --copy-remote is specified, that means the user really wanted to copy the remote ref, and we should fail if that fails. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index cc3335a53f..4a56f1871a 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -3139,7 +3139,7 @@ sub copy_remote_ref { my $ref = "refs/remotes/$GIT_SVN"; if (safe_qx('git-ls-remote', $origin, $ref)) { sys(qw/git fetch/, $origin, "$ref:$ref"); - } else { + } elsif ($_cp_remote && !$_upgrade) { die "Unable to find remote reference: ", "refs/remotes/$GIT_SVN on $origin\n"; } From 45bf473a7bc2c40c8aea3d34a0eab7a41e77a8ff Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 9 Nov 2006 01:19:37 -0800 Subject: [PATCH 3/4] git-svn: fix dcommit losing changes when out-of-date from svn There was a bug in dcommit (and commit-diff) which caused deltas to be generated against the latest version of the changed file in a repository, and not the revision we are diffing (the tree) against locally. This bug can cause recent changes to the svn repository to be silently clobbered by git-svn if our repository is out-of-date. Thanks to Steven Grimm for noticing the bug. The (few) people using the commit-diff command are now required to use the -r/--revision argument. dcommit usage is unchanged. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 1 + git-svn.perl | 29 ++++++++-- t/t9105-git-svn-commit-diff.sh | 2 +- t/t9106-git-svn-commit-diff-clobber.sh | 74 ++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100755 t/t9106-git-svn-commit-diff-clobber.sh diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 450ff1f85b..a764d1f8ee 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -120,6 +120,7 @@ manually joining branches on commit. URL of the target Subversion repository. The final argument (URL) may be omitted if you are working from a git-svn-aware repository (that has been init-ed with git-svn). + The -r option is required for this. 'graft-branches':: This command attempts to detect merges/branches from already diff --git a/git-svn.perl b/git-svn.perl index 4a56f1871a..80b7b87f0f 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -134,6 +134,7 @@ my %cmd = ( 'commit-diff' => [ \&commit_diff, 'Commit a diff between two trees', { 'message|m=s' => \$_message, 'file|F=s' => \$_file, + 'revision|r=s' => \$_revision, %cmt_opts } ], dcommit => [ \&dcommit, 'Commit several diffs to merge with upstream', { 'merge|m|M' => \$_merge, @@ -586,11 +587,21 @@ sub commit_lib { sub dcommit { my $gs = "refs/remotes/$GIT_SVN"; chomp(my @refs = safe_qx(qw/git-rev-list --no-merges/, "$gs..HEAD")); + my $last_rev; foreach my $d (reverse @refs) { + unless (defined $last_rev) { + (undef, $last_rev, undef) = cmt_metadata("$d~1"); + unless (defined $last_rev) { + die "Unable to extract revision information ", + "from commit $d~1\n"; + } + } if ($_dry_run) { print "diff-tree $d~1 $d\n"; } else { - commit_diff("$d~1", $d); + if (my $r = commit_diff("$d~1", $d, undef, $last_rev)) { + $last_rev = $r; + } # else: no changes, same $last_rev } } return if $_dry_run; @@ -814,6 +825,8 @@ sub commit_diff { print STDERR "Needed URL or usable git-svn id command-line\n"; commit_diff_usage(); } + my $r = shift || $_revision; + die "-r|--revision is a required argument\n" unless (defined $r); if (defined $_message && defined $_file) { print STDERR "Both --message/-m and --file/-F specified ", "for the commit message.\n", @@ -830,13 +843,22 @@ sub commit_diff { ($repo, $SVN_PATH) = repo_path_split($SVN_URL); $SVN_LOG ||= libsvn_connect($repo); $SVN ||= libsvn_connect($repo); + if ($r eq 'HEAD') { + $r = $SVN->get_latest_revnum; + } elsif ($r !~ /^\d+$/) { + die "revision argument: $r not understood by git-svn\n"; + } my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : (); - my $ed = SVN::Git::Editor->new({ r => $SVN->get_latest_revnum, + my $rev_committed; + my $ed = SVN::Git::Editor->new({ r => $r, ra => $SVN_LOG, c => $tb, svn_path => $SVN_PATH }, $SVN->get_commit_editor($_message, - sub {print "Committed $_[0]\n"},@lock) + sub { + $rev_committed = $_[0]; + print "Committed $_[0]\n"; + }, @lock) ); my $mods = libsvn_checkout_tree($ta, $tb, $ed); if (@$mods == 0) { @@ -846,6 +868,7 @@ sub commit_diff { $ed->close_edit; } $_message = $_file = undef; + return $rev_committed; } ########################### utility functions ######################### diff --git a/t/t9105-git-svn-commit-diff.sh b/t/t9105-git-svn-commit-diff.sh index f994b72f80..746c8277d0 100755 --- a/t/t9105-git-svn-commit-diff.sh +++ b/t/t9105-git-svn-commit-diff.sh @@ -33,7 +33,7 @@ prev=`git rev-parse --verify HEAD^1` test_expect_success 'test the commit-diff command' " test -n '$prev' && test -n '$head' && - git-svn commit-diff '$prev' '$head' '$svnrepo' && + git-svn commit-diff -r1 '$prev' '$head' '$svnrepo' && svn co $svnrepo wc && cmp readme wc/readme " diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh new file mode 100755 index 0000000000..58698b3f29 --- /dev/null +++ b/t/t9106-git-svn-commit-diff-clobber.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# +# Copyright (c) 2006 Eric Wong +test_description='git-svn commit-diff clobber' +. ./lib-git-svn.sh + +if test -n "$GIT_SVN_NO_LIB" && test "$GIT_SVN_NO_LIB" -ne 0 +then + echo 'Skipping: commit-diff clobber needs SVN libraries' + test_done + exit 0 +fi + +test_expect_success 'initialize repo' " + mkdir import && + cd import && + echo initial > file && + svn import -m 'initial' . $svnrepo && + cd .. && + echo initial > file && + git update-index --add file && + git commit -a -m 'initial' + " +test_expect_success 'commit change from svn side' " + svn co $svnrepo t.svn && + cd t.svn && + echo second line from svn >> file && + svn commit -m 'second line from svn' && + cd .. && + rm -rf t.svn + " + +test_expect_failure 'commit conflicting change from git' " + echo second line from git >> file && + git commit -a -m 'second line from git' && + git-svn commit-diff -r1 HEAD~1 HEAD $svnrepo + " || true + +test_expect_success 'commit complementing change from git' " + git reset --hard HEAD~1 && + echo second line from svn >> file && + git commit -a -m 'second line from svn' && + echo third line from git >> file && + git commit -a -m 'third line from git' && + git-svn commit-diff -r2 HEAD~1 HEAD $svnrepo + " + +test_expect_failure 'dcommit fails to commit because of conflict' " + git-svn init $svnrepo && + git-svn fetch && + git reset --hard refs/remotes/git-svn && + svn co $svnrepo t.svn && + cd t.svn && + echo fourth line from svn >> file && + svn commit -m 'fourth line from svn' && + cd .. && + rm -rf t.svn && + echo 'fourth line from git' >> file && + git commit -a -m 'fourth line from git' && + git-svn dcommit + " || true + +test_expect_success 'dcommit does the svn equivalent of an index merge' " + git reset --hard refs/remotes/git-svn && + echo 'index merge' > file2 && + git update-index --add file2 && + git commit -a -m 'index merge' && + echo 'more changes' >> file2 && + git update-index file2 && + git commit -a -m 'more changes' && + git-svn dcommit + " + +test_done From a6ec3c1599f990b4f2f3dab2606688639f74d844 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Tue, 3 Oct 2006 17:29:26 +0100 Subject: [PATCH 4/4] git-rebase: Use --ignore-if-in-upstream option when executing git-format-patch. This reduces the number of conflicts when rebasing after a series of patches to the same piece of code is committed upstream. Signed-off-by: Robert Shearman Signed-off-by: Junio C Hamano --- git-rebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-rebase.sh b/git-rebase.sh index a7373c0532..413636e208 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -286,7 +286,7 @@ fi if test -z "$do_merge" then - git-format-patch -k --stdout --full-index "$upstream"..ORIG_HEAD | + git-format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD | git am --binary -3 -k --resolvemsg="$RESOLVEMSG" \ --reflog-action=rebase exit $?