[ANNOUNCE] git-svn - bidirection operations between svn and git

6 messages, 2 authors, 2016-06-15 · open the first message on its own page

[ANNOUNCE] git-svn - bidirection operations between svn and git

From: Eric Wong <hidden>
Date: 2016-06-15 22:42:19

Hello, I've written a simple tool for interoperating between git and
svn.  I wrote this so I could use git to work on projects where other
developers use Subversion.  I really hate using svn, but some projects I
work on require it, and svk isn't nearly as fast nor simple as git.

git-svn does not replace git-svnimport, git-svnimport handles branches
and tags automatically, but is too inflexible about repository layouts
to be useful for a good number of projects I follow, and of course
git-svnimport can't commit to Subversion repositories :)

git-svn only cares about a single branch/trunk in SVN[1], but you can
use as many branches in git as you want.  This makes it much easier to
use and allows it to handle just about any repository layout, not just
those recommended in the SVN book/developers.

Although importing changesets from SVN is mostly a linear affair,
committing to SVN is the opposite.  You may commit git tree objects in
any order you want.  It simply clobbers the existing svn tree as
'git-checkout -f' would, but tags file renames/copies carefully so users
on the SVN side can see them.  You can even do some wacky things with
patch reordering.

Basic day-to-day usage is pretty simple, and is designed to work with
and also work like normal git commands:

# Initialize a tree (like git init-db)::
	git-svn init http://svn.foo.org/project/trunk

# Fetch remote revisions::
	git-svn fetch

# Create your own branch to hack on::
	git checkout -b my-branch git-svn-HEAD

# Commit only the git commits you want to SVN::
	git-svn commit <tree-ish> [<tree-ish_2> ...] 

# Commit all the git commits from my-branch that don't exist in SVN::
	git rev-list --pretty=oneline git-svn-HEAD..my-branch | git-svn commit

# Something is committed to SVN, pull the latest into your branch::
	git-svn fetch && git pull . git-svn-HEAD

@ Junio: Is there room for this in the git distribution alongside
git-svnimport?

Thanks for reading,

[1] - there are some a hacks that lets you handle branches and tags, but
it's not automated in any way, requires a bit of imagination to use to
its full potential, and is very much a hack.  See the man page :)

-- 
Eric Wong

Re: [ANNOUNCE] git-svn - bidirection operations between svn and git

From: Eduardo Pereira Habkost <hidden>
Date: 2016-06-15 22:42:19

On Wed, Feb 15, 2006 at 11:38:26PM -0800, Eric Wong wrote:
Hello, I've written a simple tool for interoperating between git and
svn.  I wrote this so I could use git to work on projects where other
developers use Subversion.  I really hate using svn, but some projects I
work on require it, and svk isn't nearly as fast nor simple as git.
Great, I was doing some testing with git-svnimport for this, but I missed
a tool to automatically commit to svn what I have in my GIT tree.
git-svn does not replace git-svnimport, git-svnimport handles branches
and tags automatically, but is too inflexible about repository layouts
to be useful for a good number of projects I follow, and of course
git-svnimport can't commit to Subversion repositories :)
I am already using git-svnimport to keep a "mirror" of some subversion
repositories, here (automatically udpated on crontab). Do you plan to
allow "integration" with repositories that are just clones of
git-svnimport'ed repositories?

I plan to keep using git-svnimport and the standard git tools to work
using the "svn mirror on git" as the main repository, but I plan to use
"git-svn commit" to commit to the SVN repositories. I want this "commit
tool" to not affect the current repository in any way, just like git-push:
only send the commits to the remote repository and don't change anything
in the local repository.

However, it seems that "git-svn commit" does some tasks assuming we
are on a "git-svn aware" repository (e.g. the "resyncing" just after
the commit). Would you accept patches to allow using "git-svn commit"
to commit changes from any GIT repository (i.e. not "svn-git aware"
repositories) to any SVN repository, just like "git-push" would work
for a GIT repository?

However, I am not sure if the easier way would be changing git-svn to
do this for me or writing a different script just for this task.
git-svn only cares about a single branch/trunk in SVN[1], but you can
use as many branches in git as you want.  This makes it much easier to
use and allows it to handle just about any repository layout, not just
those recommended in the SVN book/developers.

Although importing changesets from SVN is mostly a linear affair,
committing to SVN is the opposite.  You may commit git tree objects in
any order you want.  It simply clobbers the existing svn tree as
'git-checkout -f' would, but tags file renames/copies carefully so users
on the SVN side can see them.  You can even do some wacky things with
patch reordering.
Good, this is what I expect to be able to do when commiting to svn.

-- 
Eduardo

Re: [ANNOUNCE] git-svn - bidirection operations between svn and git

From: Eric Wong <hidden>
Date: 2016-06-15 22:42:19

Eduardo Pereira Habkost [off-list ref] wrote:
On Wed, Feb 15, 2006 at 11:38:26PM -0800, Eric Wong wrote:
quoted
Hello, I've written a simple tool for interoperating between git and
svn.  I wrote this so I could use git to work on projects where other
developers use Subversion.  I really hate using svn, but some projects I
work on require it, and svk isn't nearly as fast nor simple as git.
Great, I was doing some testing with git-svnimport for this, but I missed
a tool to automatically commit to svn what I have in my GIT tree.
quoted
git-svn does not replace git-svnimport, git-svnimport handles branches
and tags automatically, but is too inflexible about repository layouts
to be useful for a good number of projects I follow, and of course
git-svnimport can't commit to Subversion repositories :)
I am already using git-svnimport to keep a "mirror" of some subversion
repositories, here (automatically udpated on crontab). Do you plan to
allow "integration" with repositories that are just clones of
git-svnimport'ed repositories?
It's possible, just not very obvious at the moment.  git-svn was written
as quickly as possible without regard to svnimport compatibility since I
had some repos that didn't work with svnimport to begin with.

The 'ADDITIONAL FETCH ARGUMENTS' part of the manpage is worth reading
for you.  Basically, you can define equalities
"(svn revision number)=(git commit)" as arguments to git-svn fetch to 
add parents for all the revisions it imports.

If I were you, I'd only want git-svn to care about partial history,
since you already have the rest of it from git-svnimport.  You can do
this:

	svn_revno=<last svn revision number you imported from git-svnimport>
	git_commit=<equivalent commit sha1 name of svn_revno above>
	git-svn fetch --revision $svn_revno:HEAD $svn_revno=$git_commit
I plan to keep using git-svnimport and the standard git tools to work
using the "svn mirror on git" as the main repository, but I plan to use
"git-svn commit" to commit to the SVN repositories. I want this "commit
tool" to not affect the current repository in any way, just like git-push:
only send the commits to the remote repository and don't change anything
in the local repository.
 
However, it seems that "git-svn commit" does some tasks assuming we
are on a "git-svn aware" repository (e.g. the "resyncing" just after
the commit). Would you accept patches to allow using "git-svn commit"
to commit changes from any GIT repository (i.e. not "svn-git aware"
repositories) to any SVN repository, just like "git-push" would work
for a GIT repository?

However, I am not sure if the easier way would be changing git-svn to
do this for me or writing a different script just for this task.
You should be 95% there just by exporting the svn_checkout_tree()
function to the command-line.  Perhaps automating reading of the
$svn_rev variable can be in order.

-- 
Eric Wong

[PATCH] git-svn: fix revision order when XML::Simple is not loaded

From: Eric Wong <hidden>
Date: 2016-06-15 22:42:19

Thanks to Emmanuel Guerin for finding the bug.

Signed-off-by: Eric Wong <redacted>

---

 contrib/git-svn/git-svn |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

98de7584b4991ab9c4025e36bfbfc10eacd17b8d
diff --git a/contrib/git-svn/git-svn b/contrib/git-svn/git-svn
index 62fc14f..ddd9579 100755
--- a/contrib/git-svn/git-svn
+++ b/contrib/git-svn/git-svn
@@ -523,7 +523,7 @@ sub svn_log_raw {
 
 			# if we have an empty log message, put something there:
 			if (@svn_log) {
-				$svn_log[0]->{msg} ||= "\n";
+				$svn_log[$#svn_log]->{msg} ||= "\n";
 			}
 			next;
 		}
@@ -538,7 +538,7 @@ sub svn_log_raw {
 					date => "$tz $Y-$m-$d $H:$M:$S",
 					author => $author,
 					msg => '' );
-			unshift @svn_log, \%log_msg;
+			push @svn_log, \%log_msg;
 			$state = 'msg_start';
 			next;
 		}
@@ -546,7 +546,7 @@ sub svn_log_raw {
 		if ($state eq 'msg_start' && /^$/) {
 			$state = 'msg';
 		} elsif ($state eq 'msg') {
-			$svn_log[0]->{msg} .= $_."\n";
+			$svn_log[$#svn_log]->{msg} .= $_."\n";
 		}
 	}
 	close $log_fh or croak $?;
-- 
1.2.0.gdee6

Re: [PATCH] git-svn: fix revision order when XML::Simple is not loaded

From: Eric Wong <hidden>
Date: 2016-06-15 22:42:19

Just to add, XML::Simple is a recommended dependency.  git-svn will work
fine without it (after this patch) as long as the repository doesn't
have any log messages that regurgitate or otherwise look like svn log
output (most svn repositories are sane in this regard :)

I may add support for the SVN:: perl libraries in the future, but I'll
always git-svn compatible with the command-line svn client and lazy load
any non-standard libraries.

-- 
Eric Wong

[PATCH] git-svn: ensure fetch always works chronologically.

From: Eric Wong <hidden>
Date: 2016-06-15 22:42:19

We run svn log against a URL without a working copy for the first fetch,
so we end up a log that's sorted from highest to lowest.  That's bad, we
always want lowest to highest.  Just default to --revision 0:HEAD now if
-r isn't specified for the first fetch.

Also sort the revisions after we get them just in case somebody
accidentally reverses the argument to --revision for whatever reason.

Thanks again to Emmanuel Guerin for helping me find this.

Signed-off-by: Eric Wong <redacted>

---

 contrib/git-svn/git-svn |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

2ec4f205eaa3914a64205ea224292b9e27e06cdf
diff --git a/contrib/git-svn/git-svn b/contrib/git-svn/git-svn
index ddd9579..2caf057 100755
--- a/contrib/git-svn/git-svn
+++ b/contrib/git-svn/git-svn
@@ -168,14 +168,15 @@ sub fetch {
 	my (@parents) = @_;
 	$SVN_URL ||= file_to_s("$GIT_DIR/$GIT_SVN/info/url");
 	my @log_args = -d $SVN_WC ? ($SVN_WC) : ($SVN_URL);
-	if (-d $SVN_WC && !$_revision) {
-		$_revision = 'BASE:HEAD';
+	unless ($_revision) {
+		$_revision = -d $SVN_WC ? 'BASE:HEAD' : '0:HEAD';
 	}
-	push @log_args, "-r$_revision" if $_revision;
+	push @log_args, "-r$_revision";
 	push @log_args, '--stop-on-copy' unless $_no_stop_copy;
 
 	eval { require XML::Simple or croak $! };
 	my $svn_log = $@ ? svn_log_raw(@log_args) : svn_log_xml(@log_args);
+	@$svn_log = sort { $a->{revision} <=> $b->{revision} } @$svn_log;
 
 	my $base = shift @$svn_log or croak "No base revision!\n";
 	my $last_commit = undef;
-- 
1.2.0.gdee6
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help