git-svnimport: added explicit merge graph option -G
Junio,
Below is what I got with
git-format-patch -p -M -s --stdout origin
I hope this is acceptable. I checked, I do not have a MUA which preserves whitespaces such that the result is suitable for applying the patch. So I am pasting the patch below for discussion and also attaching to be suitable for applying.
Stas.
Quoted 1 line
From
fd83a4e003802b6cb4dc8a2d058310f235f65e17Mon Sep 17 00:00:00 2001
From: Stas Maximov <[email protected]>
Date: Sat, 23 Jun 2007 09:06:30 -0700
Subject: [PATCH] git-svnimport: added explicit merge graph option -G
Allows explicit merge graph information to be provided. Each line of merge graph file must contain a pair of SVN revision numbers separated by space. The first number is child (merged to) SVN rev number and the second is the parent (merged from) SVN rev number. Comments can be started with '#' and continue to the end of line. Empty and space-only lines are allowed and will be ignored.
Documentation/git-svnimport.txt +10 -1
@@ -13,7 +13,8 @@ SYNOPSIS 'git-svnimport' [ -o <branch-for-HEAD> ] [ -h ] [ -v ] [ -d | -D ] [ -C <GIT_repository> ] [ -i ] [ -u ] [-l limit_rev] [ -b branch_subdir ] [ -T trunk_subdir ] [ -t tag_subdir ] - [ -s start_chg ] [ -m ] [ -r ] [ -M regex ] + [ -s start_chg ] [ -r ] + [ -m ] [ -M regex ] [-G merge_graph_file ] [ -I <ignorefile_name> ] [ -A <author_file> ] [ -R <repack_each_revs>] [ -P <path_from_trunk> ] <SVN_repository_URL> [ <path> ]
@@ -102,6 +103,14 @@ repository without -A. regex. It can be used with -m to also see the default regexes. You must escape forward slashes. +-G <merge_graph_file>:: + Allows explicit merge graph information to be provided. Each line + of merge graph file must contain a pair of SVN revision numbers + separated by space. The first number is child (merged to) SVN rev + number and the second is the parent (merged from) SVN rev number. + Comments can be started with '#' and continue to the end of line. + Empty and space-only lines are allowed and will be ignored. + -l <max_rev>:: Specify a maximum revision number to pull. +
git-svnimport.perl +68 -3
105 lines not on this page · raw message
Signature · 1 line
1.5.1.3
Quoted 1 line
From
7008a13f1fe00fdbd90be6a12ad1197dceedaebbMon Sep 17 00:00:00 2001
From: Stas Maximov <[email protected]>
Date: Sun, 24 Jun 2007 14:23:29 -0700
Subject: [PATCH] Fixed permissions of Documentation/git-svnimport.txt
Documentation/git-svnimport.txt +0 -0
Signature · 12 lines
1.5.1.3 ----- Original Message ---- From: Junio C Hamano <[email protected]> To: Stas Maximov <[email protected]> Cc: [email protected]; Peter Baumann <[email protected]> Sent: Sunday, June 24, 2007 3:17:05 PM Subject: Re: [PATCH] git-svnimport: added explicit merge graph option -G
Quoted 4 lines · Stas Maximov
Attached are two patches:
1. resubmission of the original patch with proper sign-off; and
2. patch with permissions fix (thanks to Alex Reisen for pointing out);
As you are assuming that the original patch was rejected (by resending that as the first one here), I do not think these changes should be in two separate commits. Please redo them as a single patch.
Also please do not "Attach". When you have N patches to send, send N e-mail messages, numbered from [PATCH 1/N] to [PATCH N/N], each with one patch in the message itself.
Please see Documentation/SubmittingPatches.
From fd83a4e003802b6cb4dc8a2d058310f235f65e17 Mon Sep 17 00:00:00 2001
From: Stas Maximov <[email protected]>
Date: Sat, 23 Jun 2007 09:06:30 -0700
Subject: [PATCH] git-svnimport: added explicit merge graph option -G
Allows explicit merge graph information to be provided. Each line of merge graph file must contain a pair of SVN revision numbers separated by space. The first number is child (merged to) SVN rev number and the second is the parent (merged from) SVN rev number. Comments can be started with '#' and continue to the end of line. Empty and space-only lines are allowed and will be ignored.
Documentation/git-svnimport.txt +10 -1
@@ -13,7 +13,8 @@ SYNOPSIS 'git-svnimport' [ -o <branch-for-HEAD> ] [ -h ] [ -v ] [ -d | -D ] [ -C <GIT_repository> ] [ -i ] [ -u ] [-l limit_rev] [ -b branch_subdir ] [ -T trunk_subdir ] [ -t tag_subdir ] - [ -s start_chg ] [ -m ] [ -r ] [ -M regex ] + [ -s start_chg ] [ -r ] + [ -m ] [ -M regex ] [-G merge_graph_file ] [ -I <ignorefile_name> ] [ -A <author_file> ] [ -R <repack_each_revs>] [ -P <path_from_trunk> ] <SVN_repository_URL> [ <path> ]
@@ -102,6 +103,14 @@ repository without -A. regex. It can be used with -m to also see the default regexes. You must escape forward slashes. +-G <merge_graph_file>:: + Allows explicit merge graph information to be provided. Each line + of merge graph file must contain a pair of SVN revision numbers + separated by space. The first number is child (merged to) SVN rev + number and the second is the parent (merged from) SVN rev number. + Comments can be started with '#' and continue to the end of line. + Empty and space-only lines are allowed and will be ignored. + -l <max_rev>:: Specify a maximum revision number to pull. +
git-svnimport.perl +68 -3
105 lines not on this page · raw message
Signature · 10 lines
1.5.1.3 From 7008a13f1fe00fdbd90be6a12ad1197dceedaebb Mon Sep 17 00:00:00 2001 From: Stas Maximov <[email protected]> Date: Sun, 24 Jun 2007 14:23:29 -0700 Subject: [PATCH] Fixed permissions of Documentation/git-svnimport.txt Signed-off-by: Stas Maximov <[email protected]>
Documentation/git-svnimport.txt +0 -0
Signature · 1 line
1.5.1.3
Documentation/git-svnimport.txt
Quoted 18 lines · Stas Maximov
From
fd83a4e003802b6cb4dc8a2d058310f235f65e17Mon Sep 17 00:00:00 2001
From: Stas Maximov <[email protected]>
Date: Sat, 23 Jun 2007 09:06:30 -0700
Subject: [PATCH] git-svnimport: added explicit merge graph option -GAllows explicit merge graph information to be provided. Each line of merge graph file must contain a pair of SVN revision numbers separated by space. The first number is child (merged to) SVN rev number and the second is the parent (merged from) SVN rev number. Comments can be started with '#' and continue to the end of line. Empty and space-only lines are allowed and will be ignored.
Signed-off-by Stas Maximov <[email protected]>Documentation/git-svnimport.txt +0
-0
Executable documentation ;-)?
Quoted 18 lines
git-svnimport.perl +9
-0@@ -80,6 +81,39 @@ if ($opt_M) { unshift (@mergerx, qr/$opt_M/); } + +# merge_graph will be used for finding all parent SVN revisions for a given SVN +# revision. It will be implemented as a hash of hashes. First level hash will +# be keyed with the child SVN rev and contain a hash keyed with the parent SVN +# revisions. Values of the second level hash are not important (1 will be +# used). The keys will be used to store the parent revs for uniqueness. +our %merge_graph; + +
git-svnimport.perl if ($opt_M) { · line 102
Quoted 10 lines
git-svnimport.perl +10
-0+# read-in the explicit merge graph specified with -G option +if ($opt_G) { + open(F,"cat $opt_G | sed -e 's/#.*\$//' -e '/^\$/d' |") or + die("Can not open $opt_G"); + while(<F>) { + chomp; + die "ERROR: invalid line in $opt_G: $_" unless /^\s*(\d+)\s+(\d+)\s*$/; + # $merge_graph{child_rev}{parent_rev} = 1; + $merge_graph{$1}{$2} = 1; + }
Many issues here.
* Don't cat a single file into a pipe;
* Don't invoke "sed" when you are writing in Perl;
* Statement modifier with side effects is extremely hard to read;
* Does the order of parents for a single child matter? Do you ever have a look-up that says "I have a SVN child Id, and another commit Id. Check quickly if the latter is one of the parents of the child"? Otherwise nested hash is probably not the right data structure to use.
How about...
open F, '<', $opt_G
or die("Cannot open '$opt_G'");
while (<F>) {
chomp;
s/#.*//;
next if ($_ eq '');
if (/^\s*(\d+)\s+(\d+)\s*$/) {
$merge_graph{$1} ||= [];
push @{$merge_graph{$1}}, $2;
} else {
die "$opt_G:$. :malformed input $_\n";
}
}You would need to change merge_graph_get_parents() as well, if you do this; see below.
git-svnimport.perl if ($opt_M) { · line 114
Quoted 12 lines
git-svnimport.perl +12
-0+ close(F); +} + + +# Given an SVN revision (string), finds all its parent SVN revisions in the +# merge graph. +sub merge_graph_get_parents($) +{ + my $child_svnrev = shift; + my @parents = keys(%{$merge_graph{$child_svnrev}}); + return @parents; +}
Can the caller ever call this with a svnrev not in $opt_G file? Do we want to protect ourselves against it?
sub merge_graph_get_parents {
my $child_svnrev = shift;
if (exists $merge_graph{$child_svnrev}) {
return @{$merge_graph{$child_svnrev}};
}
return ();
}Quoted 15 lines
git-svnimport.perl +8
-0+ + # Absolutize filename now, since we will have chdir'ed by the time we # get around to opening it. $opt_A = File::Spec->rel2abs($opt_A) if $opt_A;@@ -356,6 +390,24 @@ if ($opt_A) { open BRANCHES,">>", "$git_dir/svn2git"; + +# Given an SVN revision (string), returns all corresponding GIT revisions. +# +# Note that it is possible that one SVN revision needs to be split into two or +# more GIT commits (revision). For example, this will happen if SVN user +# commits two branches at once.
git-svnimport.perl if ($opt_A) { · line 408
Quoted 10 lines
git-svnimport.perl +10
-0+sub svnrev_to_gitrevs($) +{ + my $svnrev = shift; + my @gitrevs; + for my $b (keys(%branches)) { + push (@gitrevs, $branches{$b}{$svnrev}) + if defined($branches{$b}{$svnrev}); + } + return @gitrevs; +}
Hmph. The computation cost for this is proportional to the number of branches on the SVN side? Would that be a problem in real-life (not an objection, but am just wondering. "Not a problem, because..." is an acceptable answer).
Quoted 7 lines
git-svnimport.perl +3
-0@@ -815,6 +867,19 @@ sub commit { } } } + + # add parents from explicit merge graph (-G) + {
git-svnimport.perl sub commit { · line 882
Quoted 10 lines
git-svnimport.perl +10
-0+ my @svnpars = merge_graph_get_parents($revision); + foreach my $svnp (@svnpars) { + my @gitpars = svnrev_to_gitrevs($svnp); + foreach my $gitp (@gitpars) { + push (@parents, $gitp); + #print OUT "MG: $svnp -merge-> $revision\n"; + } + } + } +
Leftover debugging print?
Documentation/git-svnimport.txt
Quoted 11 lines
From
7008a13f1fe00fdbd90be6a12ad1197dceedaebbMon Sep 17 00:00:00 2001
From: Stas Maximov <[email protected]>
Date: Sun, 24 Jun 2007 14:23:29 -0700
Subject: [PATCH] Fixed permissions ofDocumentation/git-svnimport.txtSigned-off-by Stas Maximov <[email protected]>Documentation/git-svnimport.txt +0
-0
Nah. Fold this part to the previous commit and start the document as a nonexecutable file from the beginning.