From fd440f0e6b812eb97b7b43688cda6ef3c4747bc6 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Sun, 20 Jan 2008 09:55:12 +0100 Subject: [PATCH] Find the merge parent faster. * svn-merge2git.sh (find_merge_parent): Generate an ERE that intelligently matches the possible merge parents so that the first commit found by rev-list is the merge parent (instead of finding all the commits in the merged branch and piping this all through a Perl script that finds the good parent). (rewrite_history): Make sure that filter-branch does not fail. (top-level aka `main'): Count the total number of commits processed. Signed-off-by: Benoit Sigoure --- svn-merge2git.sh | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/svn-merge2git.sh b/svn-merge2git.sh index bab7ee4..cdea480 100755 --- a/svn-merge2git.sh +++ b/svn-merge2git.sh @@ -139,16 +139,39 @@ find_merge_parent() merge_parent='unknown' return 0 fi - svn_merge_parent=`git rev-list --all --header \ - --grep="^ *git-svn-id: .*/$svn_branch_name@[0-9]* [-0-9a-f]*\\$" | - perl -we 'my $rev = 0; my $t = 0; - while(<>) { - m{^ *git-svn-id: .*/\Q'"$svn_branch_name"'\E@([0-9]+) [-0-9a-f]+$} - or next; - $t = int($1); - $rev = $t if $rev < $t and $t <= '"$svn_merge_to"'; - } - print $rev'` + # Create a range to intelligently limit the match of rev-list. This will + # produce a RE that rules out all the impossible revision numbers (that is, + # the revisions >TO). e.g: + # 7 -> ([0-7]) + # 42 -> (4[0-2]|[0-3][0-9]|[1-9]) + # 123 -> (12[0-3]|1[0-1][0-9]|0[0-9][0-9]|[1-9][0-9]{0,1}) + # 6951 -> (695[0-1]|69[0-4][0-9]|6[0-8][0-9][0-9]|[0-5][0-9][0-9][0-9]|[1-9][0-9]{0,2}) + perl_tmp='$_ = "'"$svn_merge_to"'"; + my $l = length($_); + my @r; + foreach my $i (0 .. $l - 1) { + /^(\d*)(\d)(\d{$i})$/; + my ($a, $b, $c) = ($1, int($2), $3); + if ($i != 0) { + # Avoid pitfalls e.g. 10[0-9] or 0[0-9][0-9] for 101 + next if $b == 0 or ($b == 1 and $a eq ""); + --$b; + } + $b = "[0-$b]" if $b; + $c =~ s/./[0-9]/g; + push(@r, "$a$b$c"); + } + push(@r, "[1-9]" . ($l - 2 ? "[0-9]{0," . ($l - 2) . "}" : "")) + if $l > 1; + print "(" . join("|", @r) . ")";' + rev_range=`perl -we "$perl_tmp"` + sed_tmp='s/^ *git-svn-id: .*@\([0-9]*\) [-0-9a-f]*$/\1/p' + svn_merge_parent=`git rev-list --all -1 --header -E \ + --grep="^ *git-svn-id: .*/$svn_branch_name@$rev_range [-0-9a-f]*\\$" \ + | sed -n "$sed_tmp"` + case $svn_merge_parent in #( + '' | *[^0-9]*) fatal "invalid svn_merge_parent: '$svn_merge_parent'";; + esac rv=$? test $rv -eq 0 || fatal "perl returned $rv" if $opt_verbose; then @@ -206,7 +229,8 @@ create_graft() rewrite_history() { $opt_dryrun && return 0 - git filter-branch --parent-filter cat -- --all + git filter-branch --parent-filter cat -- --all \ + || fatal "git filter-branch returned $?" } # doit @@ -361,14 +385,19 @@ else has_log_exclude=: fi +totalmerge=0 +totalconverted=0 for refspec do nconverted=0 nmerge=0 doit "$refspec" echo ">>> processed $nconverted/$nmerge merges in $refspec" + totalmerge=$(($totalmerge + $nmerge)) + totalconverted=$(($totalconverted + $nconverted)) done rewrite_history +echo "Done. Processed $totalconverted/$totalmerge merges" test $warnings -eq 0 || warn "job completed with $warnings warnings" -- 2.11.4.GIT