From: Eric Wong <normalperson@yhbt.net>
To: Seth Falcon <sethfalcon@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH] git-svn: add the 'dcommit' command
Date: Sat, 26 Aug 2006 00:01:23 -0700 [thread overview]
Message-ID: <20060826070123.GA10801@localdomain> (raw)
In-Reply-To: <20060825191516.GA8957@localdomain>
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>
---
Documentation/git-svn.txt | 25 +++++++++++++++++++++++++
git-svn.perl | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 9fce4d3..38e73ba 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -53,6 +53,15 @@ fetch::
See 'Additional Fetch Arguments' if you are interested in
manually joining branches on commit.
+dcommit::
+ Commit all diffs from the current HEAD directly to the SVN
+ repository, and then rebase or reset (depending on whether or
+ not there is a diff between SVN and HEAD). It is recommended
+ that you run git-svn fetch and rebase (not pull) your commits
+ against the latest changes in the SVN repository.
+ This is advantageous over 'commit' (below) because it produces
+ cleaner, more linear history.
+
commit::
Commit specified commit or tree objects to SVN. This relies on
your imported fetch data being up-to-date. This makes
@@ -146,6 +155,22 @@ loginname = Joe User <user@example.com>
repo-config key: svn.authors-file
+-m::
+--merge::
+-s<strategy>::
+--strategy=<strategy>::
+ These are only used with the 'dcommit' command.
+
+ Passed directly to git-rebase when using 'dcommit' if a
+ 'git-reset' cannot be used (see dcommit).
+
+-n::
+--dry-run::
+ This is only used with the 'dcommit' command.
+
+ Print out the series of git arguments that would show
+ which diffs would be committed to SVN.
+
ADVANCED OPTIONS
----------------
-b<refname>::
diff --git a/git-svn.perl b/git-svn.perl
index b311c3d..9382a15 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -51,7 +51,8 @@ my ($_revision,$_stdin,$_no_ignore_ext,$
$_message, $_file, $_follow_parent, $_no_metadata,
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
$_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
- $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m);
+ $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
+ $_merge, $_strategy, $_dry_run);
my (@_branch_from, %tree_map, %users, %rusers, %equiv);
my ($_svn_co_url_revs, $_svn_pg_peg_revs);
my @repo_path_split_cache;
@@ -118,6 +119,11 @@ my %cmd = (
{ 'message|m=s' => \$_message,
'file|F=s' => \$_file,
%cmt_opts } ],
+ dcommit => [ \&dcommit, 'Commit several diffs to merge with upstream',
+ { 'merge|m|M' => \$_merge,
+ 'strategy|s=s' => \$_strategy,
+ 'dry-run|n' => \$_dry_run,
+ %cmt_opts } ],
);
my $cmd;
@@ -561,6 +567,33 @@ sub commit_lib {
unlink $commit_msg;
}
+sub dcommit {
+ my $gs = "refs/remotes/$GIT_SVN";
+ chomp(my @refs = safe_qx(qw/git-rev-list --no-merges/, "$gs..HEAD"));
+ foreach my $d (reverse @refs) {
+ if ($_dry_run) {
+ print "diff-tree $d~1 $d\n";
+ } else {
+ commit_diff("$d~1", $d);
+ }
+ }
+ return if $_dry_run;
+ fetch();
+ my @diff = safe_qx(qw/git-diff-tree HEAD/, $gs);
+ my @finish;
+ if (@diff) {
+ @finish = qw/rebase/;
+ push @finish, qw/--merge/ if $_merge;
+ push @finish, "--strategy=$_strategy" if $_strategy;
+ print STDERR "W: HEAD and $gs differ, using @finish:\n", @diff;
+ } else {
+ print "No changes between current HEAD and $gs\n",
+ "Hard resetting to the latest $gs\n";
+ @finish = qw/reset --hard/;
+ }
+ sys('git', @finish, $gs);
+}
+
sub show_ignore {
$SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
$_use_lib ? show_ignore_lib() : show_ignore_cmd();
--
1.4.2.g7c9b
next prev parent reply other threads:[~2006-08-26 7:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-25 16:31 git-svn problem: unexpected files/diffs in commit Seth Falcon
2006-08-25 19:15 ` Eric Wong
2006-08-25 19:28 ` [PATCH] git-svn: establish new connections on commit after fork Eric Wong
2006-08-25 19:48 ` [PATCH] git-svn: recommend rebase for syncing against an SVN repo Eric Wong
2006-08-26 0:46 ` git-svn problem: unexpected files/diffs in commit Seth Falcon
2006-08-26 7:33 ` Eric Wong
2006-08-26 7:01 ` Eric Wong [this message]
2006-08-26 16:52 ` [PATCH] git-svn: stop repeatedly reusing the first commit message with dcommit Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060826070123.GA10801@localdomain \
--to=normalperson@yhbt.net \
--cc=git@vger.kernel.org \
--cc=sethfalcon@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).