From: Stefan Sperling Date: Tue, 21 Aug 2007 17:08:58 GMT Subject: [PATCH] Allow multiple tag and branch directories in git-svnimport Message-ID: <20070821170858.GA1721@jack.stsp.lan> With this patch, users can specify colon-seperated lists of directories containing tags and branches, respectively. This makes git-svnimport much more usable in the real world because there are Subversion repositories that use a deeper tag and branch hierarchy than the recommended hierarchy of trunk/ tags/ branches/ The patch assumes my memleak fix patch from http://marc.info/?l=git&m=118554191513822&w=2 but applies cleanly to current vanilla git head as well. I'm not subscribed to the list so please Cc me in replies, thanks. diff --git a/Documentation/git-svnimport.txt b/Documentation/git-svnimport.txt index e97d15e..2cfc407 100644 --- a/Documentation/git-svnimport.txt +++ b/Documentation/git-svnimport.txt @@ -12,11 +12,11 @@ SYNOPSIS [verse] 'git-svnimport' [ -o ] [ -h ] [ -v ] [ -d | -D ] [ -C ] [ -i ] [ -u ] [-l limit_rev] - [ -b branch_subdir ] [ -T trunk_subdir ] [ -t tag_subdir ] - [ -s start_chg ] [ -m ] [ -r ] [ -M regex ] - [ -I ] [ -A ] - [ -R ] [ -P ] - [ ] + [ -b branch_subdir[:branch_subdir:...] ] [ -T trunk_subdir ] + [ -t tag_subdir[:tag_subdir:...] ] [ -s start_chg ] [ -m ] + [ -r ] [ -M regex ] [ -I ] + [ -A ] [ -R ] + [ -P ] [ ] DESCRIPTION @@ -26,11 +26,6 @@ repository, or incrementally import into an existing one. SVN access is done by the SVN::Perl module. -git-svnimport assumes that SVN repositories are organized into one -"trunk" directory where the main development happens, "branches/FOO" -directories for branches, and "/tags/FOO" directories for tags. -Other subdirectories are ignored. - git-svnimport creates a file ".git/svn2git", which is required for incremental SVN imports. @@ -53,11 +48,13 @@ When importing incrementally, you might need to edit the .git/svn2git file. -T :: Name the SVN trunk. Default "trunk". --t :: - Name the SVN subdirectory for tags. Default "tags". +-t :: + Colon-seperated list of names of subdirectories containing tags. + Default "tags". --b :: - Name the SVN subdirectory for branches. Default "branches". +-b :: + Colon-seperated list of names of subdirectories containing branches. + Default "branches". -o :: The 'trunk' branch from SVN is imported to the 'origin' branch within diff --git a/git-svnimport.perl b/git-svnimport.perl index fc9ea71..96f0926 100755 --- a/git-svnimport.perl +++ b/git-svnimport.perl @@ -38,9 +38,10 @@ sub usage() { print STDERR < 1, - "/$tag_name" => 1, - "/$branch_name" => 1 - ); - print STDERR "$rev: Unrecognized path: $path\n" unless (defined $no_error{$path}); - return () + if (! $dir) { + my %no_error = ( "/" => 1, "/tags" => 1, "/branches" => 1 ); + foreach (@tag_dirs) { + $no_error{"/$_"} = 1; + } + foreach (@branch_dirs) { + $no_error{"/$_"} = 1; + } + print STDERR "$rev: Could not determine tag or branch ", + "directory for path '$path'\n", + unless (defined $no_error{$path}); } if ($path eq "") { $path = "/"; } elsif ($project_name) { $path = project_path($path, $project_name); } - return ($branch,$path); + return ($dir,$path); } sub branch_rev($$) { @@ -874,9 +889,32 @@ sub commit { $dest =~ tr/_/\./ if $opt_u; - system('git-tag', $dest, $cid) == 0 - or die "Cannot create tag $dest: $!\n"; - + # Since we support multiple directories that host tags we + # must support repositories that contain the same tag name + # in different tag directories for whatever reason, + # e.g. tags/jim/1.0-rc3 and tags/huck/1.0-rc3 + # + # Also, because in Subversion a given tag directory could + # exist in revision A, be deleted in revision B and later + # recreated under the same name in revision C, we + # cannot guarantee that a tag is unique simply by + # looking at the tag's path. + # + # So if we fail to create the tag the first time, we try + # to create the tag with the same name except with the + # revision number of the current commit appended. + # Users can rename tags again later after the repository + # has been converted if they don't like this. + # It's still much better than failing to convert the + # repository alltogether. + if (system('git-tag', $dest, $cid) != 0) { + print STDERR "Could not create tag $dest, ", + "trying to create tag $dest-r$revision ", + "instead\n"; + $dest = "$dest-r$revision"; + system('git-tag', $dest, $cid) == 0 + or die "Cannot create tag $dest: $? $!\n"; + } print "Created tag '$dest' on '$branch'\n" if $opt_v; } $branches{$branch}{"LAST"} = $cid; -- Stefan Sperling Software Developer elego Software Solutions GmbH HRB 77719 Gustav-Meyer-Allee 25, Gebaeude 12 Tel: +49 30 23 45 86 96 13355 Berlin Fax: +49 30 23 45 86 95 http://www.elego.de Geschaeftsfuehrer: Olaf Wagner