git-svn: add the 'dcommit' command
This is a high-level wrapper around the 'commit-diff' command and used to produce cleaner history against the mirrored repository through rebase/reset usage. It's basically a more polished version of this: for i in `git rev-list --no-merges remotes/git-svn..HEAD | tac`; do git-svn commit-diff $i~1 $i done git reset --hard remotes/git-svn Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
Aug 26, 2006 at 00:01 UTC
b22d449721b22f6ec090f22c418ae6b0a560f78d
2 files changed
+61
-1
Documentation/git-svn.txt
+27
@@ -54,6 +54,15 @@ remotes/git-svn.
54
See '<<fetch-args,Additional Fetch Arguments>>' if you are interested in
55
manually joining branches on commit.
56
57
+'dcommit'::
58
+ Commit all diffs from the current HEAD directly to the SVN
59
+ repository, and then rebase or reset (depending on whether or
60
+ not there is a diff between SVN and HEAD). It is recommended
61
+ that you run git-svn fetch and rebase (not pull) your commits
62
+ against the latest changes in the SVN repository.
63
+ This is advantageous over 'commit' (below) because it produces
64
+ cleaner, more linear history.
65
+
66
'commit'::
67
Commit specified commit or tree objects to SVN. This relies on
68
your imported fetch data being up-to-date. This makes
@@ -157,6 +166,24 @@ after the authors-file is modified should continue operation.
166
167
repo-config key: svn.authors-file
168
169
+-m::
170
+--merge::
171
+-s<strategy>::
172
+--strategy=<strategy>::
173
+
174
+These are only used with the 'dcommit' command.
175
+
176
+Passed directly to git-rebase when using 'dcommit' if a
177
+'git-reset' cannot be used (see dcommit).
178
+
179
+-n::
180
+--dry-run::
181
+
182
+This is only used with the 'dcommit' command.
183
+
184
+Print out the series of git arguments that would show
185
+which diffs would be committed to SVN.
186
+
187
--
188
189
ADVANCED OPTIONS
git-svn.perl
+34
-1
@@ -51,7 +51,8 @@ my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
51
$_message, $_file, $_follow_parent, $_no_metadata,
52
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
53
$_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
54
- $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m);
54
+ $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
55
+ $_merge, $_strategy, $_dry_run);
56
my (@_branch_from, %tree_map, %users, %rusers, %equiv);
57
my ($_svn_co_url_revs, $_svn_pg_peg_revs);
58
my @repo_path_split_cache;
@@ -118,6 +119,11 @@ my %cmd = (
119
{ 'message|m=s' => \$_message,
120
'file|F=s' => \$_file,
121
%cmt_opts } ],
122
+ dcommit => [ \&dcommit, 'Commit several diffs to merge with upstream',
123
+ { 'merge|m|M' => \$_merge,
124
+ 'strategy|s=s' => \$_strategy,
125
+ 'dry-run|n' => \$_dry_run,
126
+ %cmt_opts } ],
127
);
128
129
my $cmd;
@@ -561,6 +567,33 @@ sub commit_lib {
567
unlink $commit_msg;
568
}
569
570
+sub dcommit {
571
+ my $gs = "refs/remotes/$GIT_SVN";
572
+ chomp(my @refs = safe_qx(qw/git-rev-list --no-merges/, "$gs..HEAD"));
573
+ foreach my $d (reverse @refs) {
574
+ if ($_dry_run) {
575
+ print "diff-tree $d~1 $d\n";
576
+ } else {
577
+ commit_diff("$d~1", $d);
578
+ }
579
+ }
580
+ return if $_dry_run;
581
+ fetch();
582
+ my @diff = safe_qx(qw/git-diff-tree HEAD/, $gs);
583
+ my @finish;
584
+ if (@diff) {
585
+ @finish = qw/rebase/;
586
+ push @finish, qw/--merge/ if $_merge;
587
+ push @finish, "--strategy=$_strategy" if $_strategy;
588
+ print STDERR "W: HEAD and $gs differ, using @finish:\n", @diff;
589
+ } else {
590
+ print "No changes between current HEAD and $gs\n",
591
+ "Hard resetting to the latest $gs\n";
592
+ @finish = qw/reset --hard/;
593
+ }
594
+ sys('git', @finish, $gs);
595
+}
596
+
597
sub show_ignore {
598
$SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
599
$_use_lib ? show_ignore_lib() : show_ignore_cmd();