{"thread":{"id":"7134","subject":"[PATCH] git-archimport: allow remapping branch names","startedAt":"2007-03-07T07:59:22Z","lastAt":"2007-03-07T09:48:52Z","messageCount":9,"participants":["Paolo Bonzini","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"36533","messageId":"eslrcr$9rc$1@sea.gmane.org","threadId":"7134","inReplyTo":null,"subject":"[PATCH] git-archimport: allow remapping branch names","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2007-03-07T07:59:22Z","receivedAt":"2007-03-07T07:59:22Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"This patch add support to archimport for remapping the branch names\nto match those used in git more closely.  This is useful for\nprojects that *migrate* to git (as opposed to users that want\nto use clone into git from Arch-based projects).  For example, one\ncan choose the name \"master\" for the development branch.\n\nThe new command-line syntax should not be a problem, since a colon\nin a branch name would be a pretty weird choice even for\nArch standards.\n\nThe new feature is implemented so that archives rotated every\nyear can be remapped into a single git archive.\n---\n Documentation/git-archimport.txt |   19 +++++++-\n git-archimport.perl              |   86 ++++++++++++++++++++++++++++----------\n 2 files changed, 81 insertions(+), 24 deletions(-)\n\ndiff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt\nindex 5a13187..5794928 100644\n--- a/Documentation/git-archimport.txt\n+++ b/Documentation/git-archimport.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]\n-               <archive/branch> [ <archive/branch> ]\n+               <archive/branch>[:<git-branch>] ...\n \n DESCRIPTION\n -----------\n@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun\n `git-archimport` with the same parameters as the initial import to perform \n incremental imports.\n \n+While git-archimport will try to create sensible branch names for the\n+archives that it imports, it is also possible to specify git branch names\n+manually.  To do so, write a git branch name after each <archive/branch>\n+parameter, separated by a colon.  This way, you can shorten the Arch\n+branch names and convert Arch jargon to git jargon, for example mapping a\n+\"PROJECT--devo--VERSION\" branch to \"master\".\n+\n+Associating multiple Arch branches to one git branch is possible; the\n+result will make the most sense only if no commits are made to the first\n+branch, after the second branch is created.  Still, this is useful to\n+convert Arch repositories that had been rotated periodically.\n+\n+\n MERGES\n ------\n Patch merge data from Arch is used to mark merges in git as well. git \n@@ -73,7 +86,9 @@ OPTIONS\n \tUse this for compatibility with old-style branch names used by\n \tearlier versions of git-archimport.  Old-style branch names\n \twere category--branch, whereas new-style branch names are\n-\tarchive,category--branch--version.\n+\tarchive,category--branch--version.  In both cases, names given\n+\ton the command-line will override the automatically-generated\n+\tones.\n \n -D <depth>::\n \tFollow merge ancestry and attempt to import trees that have been\ndiff --git a/git-archimport.perl b/git-archimport.perl\nindex 0fcb156..1044695 100755\n--- a/git-archimport.perl\n+++ b/git-archimport.perl\n@@ -89,7 +89,11 @@ usage if $opt_h;\n # values associated with keys:\n #   =1 - Arch version / git 'branch' detected via abrowse on a limit\n #   >1 - Arch version / git 'branch' of an auxiliary branch we've merged\n-my %arch_branches = map { $_ => 1 } @ARGV;\n+my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;\n+\n+# $branch_name_map:\n+# maps arch branches to git branch names\n+my %branch_name_map = map { m/^([^:]*):(.*)/; $1 => $2 } grep { m/:/ } @ARGV;\n \n $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:\n my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);\n@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory\n     closedir DIR\n }\n \n+my $default_archive;\t\t# default Arch archive\n my %reachable = ();             # Arch repositories we can access\n my %unreachable = ();           # Arch repositories we can't access :<\n my @psets  = ();                # the collection\n@@ -303,7 +308,34 @@ sub old_style_branchname {\n     return $ret;\n }\n \n-*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;\n+*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;\n+\n+# retrieve default archive, since $branch_name_map keys might not include it\n+sub get_default_archive {\n+    if (!defined $default_archive) {\n+        $default_archive = safe_pipe_capture($TLA,'my-default-archive');\n+        chomp $default_archive;\n+    }\n+    return $default_archive;\n+}\n+\n+sub git_branchname {\n+    my $revision = shift;\n+    my $name = extract_versionname($revision);\n+\n+    if (defined $branch_name_map{$name}) {\n+\treturn $branch_name_map{$name};\n+\n+    } elsif ($name =~ m#^([^/]*)/(.*)$#\n+\t     && $1 eq get_default_archive()\n+\t     && defined $branch_name_map{$2}) {\n+\t# the names given in the command-line lacked the archive.\n+\treturn $branch_name_map{$2};\n+\n+    } else {\n+\treturn git_default_branchname($revision);\n+    }\n+}\n \n sub process_patchset_accurate {\n     my $ps = shift;\n@@ -333,19 +365,23 @@ sub process_patchset_accurate {\n         if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {\n             \n             # find where we are supposed to branch from\n-            system('git-checkout','-f','-b',$ps->{branch},\n-                            $branchpoint) == 0 or die \"$! $?\\n\";\n-            \n+\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n+\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n+\n+\t\t# We trust Arch with the fact that this is just a tag,\n+\t\t# and it does not affect the state of the tree, so\n+\t\t# we just tag and move on.  If the user really wants us\n+\t\t# to consolidate more branches into one, don't tag because\n+\t\t# the tag name would be already taken.\n+\t\ttag($ps->{id}, $branchpoint);\n+\t\tptag($ps->{id}, $branchpoint);\n+\t\tprint \" * Tagged $ps->{id} at $branchpoint\\n\";\n+\t    }\n+\t    system('git-checkout','-f',$ps->{branch}) == 0 or die \"$! $?\\n\";\n+\n             # remove any old stuff that got leftover:\n             my $rm = safe_pipe_capture('git-ls-files','--others','-z');\n             rmtree(split(/\\0/,$rm)) if $rm;\n-\n-            # If we trust Arch with the fact that this is just \n-            # a tag, and it does not affect the state of the tree\n-            # then we just tag and move on\n-            tag($ps->{id}, $branchpoint);\n-            ptag($ps->{id}, $branchpoint);\n-            print \" * Tagged $ps->{id} at $branchpoint\\n\";\n             return 0;\n         } else {\n             warn \"Tagging from unknown id unsupported\\n\" if $ps->{tag};\n@@ -385,14 +421,19 @@ sub process_patchset_fast {\n                 unless $branchpoint;\n             \n             # find where we are supposed to branch from\n-            system('git-checkout','-b',$ps->{branch},$branchpoint);\n-\n-            # If we trust Arch with the fact that this is just \n-            # a tag, and it does not affect the state of the tree\n-            # then we just tag and move on\n-            tag($ps->{id}, $branchpoint);\n-            ptag($ps->{id}, $branchpoint);\n-            print \" * Tagged $ps->{id} at $branchpoint\\n\";\n+\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n+\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n+\n+\t\t# We trust Arch with the fact that this is just a tag,\n+\t\t# and it does not affect the state of the tree, so\n+\t\t# we just tag and move on.  If the user really wants us\n+\t\t# to consolidate more branches into one, don't tag because\n+\t\t# the tag name would be already taken.\n+\t\ttag($ps->{id}, $branchpoint);\n+\t\tptag($ps->{id}, $branchpoint);\n+\t\tprint \" * Tagged $ps->{id} at $branchpoint\\n\";\n+            }\n+            system('git-checkout',$ps->{branch}) == 0 or die \"$! $?\\n\";\n             return 0;\n         } \n         die $! if $?;\n@@ -830,8 +871,9 @@ sub tag {\n     if ($opt_o) {\n         $tag =~ s|/|--|g;\n     } else {\n-        # don't use subdirs for tags yet, it could screw up other porcelains\n-        $tag =~ s|/|,|g;\n+\tmy $patchname = $tag;\n+\t$patchname =~ s/.*--//;\n+\t$tag = git_branchname ($tag) . '--' . $patchname;\n     }\n     \n     if ($commit) {\n"},{"id":"36534","messageId":"7vodn5iiew.fsf@assigned-by-dhcp.cox.net","threadId":"7134","inReplyTo":"eslrcr$9rc$1@sea.gmane.org","subject":"Re: [PATCH] git-archimport: allow remapping branch names","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-07T08:09:43Z","receivedAt":"2007-03-07T08:09:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paolo Bonzini <bonzini@gnu.org> writes:\n\n> The new command-line syntax should not be a problem, since a colon\n> in a branch name would be a pretty weird choice even for\n> Arch standards.\n>\n> The new feature is implemented so that archives rotated every\n> year can be remapped into a single git archive.\n\n>  'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]\n> -               <archive/branch> [ <archive/branch> ]\n> +               <archive/branch>[:<git-branch>] ...\n> ...\n> -my %arch_branches = map { $_ => 1 } @ARGV;\n> +my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;\n> +\n> +# $branch_name_map:\n> +# maps arch branches to git branch names\n> +my %branch_name_map = map { m/^([^:]*):(.*)/; $1 => $2 } grep { m/:/ } @ARGV;\n\nI am no arch/tla expert, but at least git does not allow colon\nin branch names at all, so if you make your command line parser\nto match left-greedy-anything, colon and then right-non-colon\n(i.e. m/^(.*):([^:]*)$/), you should be able to handle colons in\narch archive names.\n"},{"id":"36535","messageId":"45EE7442.6030308@lu.unisi.ch","threadId":"7134","inReplyTo":"7vodn5iiew.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH, 2nd version] git-archimport: allow remapping branch names","fromName":"Paolo Bonzini","fromEmail":"paolo.bonzini@lu.unisi.ch","sentAt":"2007-03-07T08:13:54Z","receivedAt":"2007-03-07T08:13:54Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"This patch add support to archimport for remapping the branch names\nto match those used in git more closely.  This is useful for\nprojects that *migrate* to git (as opposed to users that want\nto use git on Arch-based projects).  For example, one can\nchoose a branch name and call it \"master\".\n\nThe new command-line syntax works even if there is a colon in\na branch name, since only the part after the last colon is taken\nto be the git name (git does not allow colons in branch names).\n\nThe new feature is implemented so that archives rotated every\nyear can also be remapped into a single git archive.\n---\n Documentation/git-archimport.txt |   19 +++++++-\n git-archimport.perl              |   86 ++++++++++++++++++++++++++++----------\n 2 files changed, 81 insertions(+), 24 deletions(-)\n\n\t> I am no arch/tla expert, but at least git does not allow colon\n\t> in branch names at all, so if you make your command line parser\n\t> to match left-greedy-anything, colon and then right-non-colon\n\t> (i.e. m/^(.*):([^:]*)$/), you should be able to handle colons in\n\t> arch archive names.\n\t\n\tGreat idea.  Thanks.  By the way, this patch was tested on\n\tmy Arch repositories.\n\n\ndiff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt\nindex 5a13187..5794928 100644\n--- a/Documentation/git-archimport.txt\n+++ b/Documentation/git-archimport.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]\n-               <archive/branch> [ <archive/branch> ]\n+               <archive/branch>[:<git-branch>] ...\n \n DESCRIPTION\n -----------\n@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun\n `git-archimport` with the same parameters as the initial import to perform \n incremental imports.\n \n+While git-archimport will try to create sensible branch names for the\n+archives that it imports, it is also possible to specify git branch names\n+manually.  To do so, write a git branch name after each <archive/branch>\n+parameter, separated by a colon.  This way, you can shorten the Arch\n+branch names and convert Arch jargon to git jargon, for example mapping a\n+\"PROJECT--devo--VERSION\" branch to \"master\".\n+\n+Associating multiple Arch branches to one git branch is possible; the\n+result will make the most sense only if no commits are made to the first\n+branch, after the second branch is created.  Still, this is useful to\n+convert Arch repositories that had been rotated periodically.\n+\n+\n MERGES\n ------\n Patch merge data from Arch is used to mark merges in git as well. git \n@@ -73,7 +86,9 @@ OPTIONS\n \tUse this for compatibility with old-style branch names used by\n \tearlier versions of git-archimport.  Old-style branch names\n \twere category--branch, whereas new-style branch names are\n-\tarchive,category--branch--version.\n+\tarchive,category--branch--version.  In both cases, names given\n+\ton the command-line will override the automatically-generated\n+        ones.\n \n -D <depth>::\n \tFollow merge ancestry and attempt to import trees that have been\ndiff --git a/git-archimport.perl b/git-archimport.perl\nindex 0fcb156..1044695 100755\n--- a/git-archimport.perl\n+++ b/git-archimport.perl\n@@ -89,7 +89,11 @@ usage if $opt_h;\n # values associated with keys:\n #   =1 - Arch version / git 'branch' detected via abrowse on a limit\n #   >1 - Arch version / git 'branch' of an auxiliary branch we've merged\n-my %arch_branches = map { $_ => 1 } @ARGV;\n+my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;\n+\n+# $branch_name_map:\n+# maps arch branches to git branch names\n+my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;\n \n $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:\n my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);\n@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory\n     closedir DIR\n }\n \n+my $default_archive;\t\t# default Arch archive\n my %reachable = ();             # Arch repositories we can access\n my %unreachable = ();           # Arch repositories we can't access :<\n my @psets  = ();                # the collection\n@@ -303,7 +308,34 @@ sub old_style_branchname {\n     return $ret;\n }\n \n-*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;\n+*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;\n+\n+# retrieve default archive, since $branch_name_map keys might not include it\n+sub get_default_archive {\n+    if (!defined $default_archive) {\n+        $default_archive = safe_pipe_capture($TLA,'my-default-archive');\n+        chomp $default_archive;\n+    }\n+    return $default_archive;\n+}\n+\n+sub git_branchname {\n+    my $revision = shift;\n+    my $name = extract_versionname($revision);\n+\n+    if (defined $branch_name_map{$name}) {\n+\treturn $branch_name_map{$name};\n+\n+    } elsif ($name =~ m#^([^/]*)/(.*)$#\n+\t     && $1 eq get_default_archive()\n+\t     && defined $branch_name_map{$2}) {\n+\t# the names given in the command-line lacked the archive.\n+\treturn $branch_name_map{$2};\n+\n+    } else {\n+\treturn git_default_branchname($revision);\n+    }\n+}\n \n sub process_patchset_accurate {\n     my $ps = shift;\n@@ -333,19 +365,23 @@ sub process_patchset_accurate {\n         if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {\n             \n             # find where we are supposed to branch from\n-            system('git-checkout','-f','-b',$ps->{branch},\n-                            $branchpoint) == 0 or die \"$! $?\\n\";\n-            \n+\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n+\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n+\n+\t\t# We trust Arch with the fact that this is just a tag,\n+\t\t# and it does not affect the state of the tree, so\n+\t\t# we just tag and move on.  If the user really wants us\n+\t\t# to consolidate more branches into one, don't tag because\n+\t\t# the tag name would be already taken.\n+\t\ttag($ps->{id}, $branchpoint);\n+\t\tptag($ps->{id}, $branchpoint);\n+\t\tprint \" * Tagged $ps->{id} at $branchpoint\\n\";\n+\t    }\n+\t    system('git-checkout','-f',$ps->{branch}) == 0 or die \"$! $?\\n\";\n+\n             # remove any old stuff that got leftover:\n             my $rm = safe_pipe_capture('git-ls-files','--others','-z');\n             rmtree(split(/\\0/,$rm)) if $rm;\n-\n-            # If we trust Arch with the fact that this is just \n-            # a tag, and it does not affect the state of the tree\n-            # then we just tag and move on\n-            tag($ps->{id}, $branchpoint);\n-            ptag($ps->{id}, $branchpoint);\n-            print \" * Tagged $ps->{id} at $branchpoint\\n\";\n             return 0;\n         } else {\n             warn \"Tagging from unknown id unsupported\\n\" if $ps->{tag};\n@@ -385,14 +421,19 @@ sub process_patchset_fast {\n                 unless $branchpoint;\n             \n             # find where we are supposed to branch from\n-            system('git-checkout','-b',$ps->{branch},$branchpoint);\n-\n-            # If we trust Arch with the fact that this is just \n-            # a tag, and it does not affect the state of the tree\n-            # then we just tag and move on\n-            tag($ps->{id}, $branchpoint);\n-            ptag($ps->{id}, $branchpoint);\n-            print \" * Tagged $ps->{id} at $branchpoint\\n\";\n+\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n+\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n+\n+\t\t# We trust Arch with the fact that this is just a tag,\n+\t\t# and it does not affect the state of the tree, so\n+\t\t# we just tag and move on.  If the user really wants us\n+\t\t# to consolidate more branches into one, don't tag because\n+\t\t# the tag name would be already taken.\n+\t\ttag($ps->{id}, $branchpoint);\n+\t\tptag($ps->{id}, $branchpoint);\n+\t\tprint \" * Tagged $ps->{id} at $branchpoint\\n\";\n+            }\n+            system('git-checkout',$ps->{branch}) == 0 or die \"$! $?\\n\";\n             return 0;\n         } \n         die $! if $?;\n@@ -830,8 +871,9 @@ sub tag {\n     if ($opt_o) {\n         $tag =~ s|/|--|g;\n     } else {\n-        # don't use subdirs for tags yet, it could screw up other porcelains\n-        $tag =~ s|/|,|g;\n+\tmy $patchname = $tag;\n+\t$patchname =~ s/.*--//;\n+        $tag = git_branchname ($tag) . '--' . $patchname;\n     }\n     \n     if ($commit) {\n-- \n1.4.4.2\n"},{"id":"36536","messageId":"45EE76E7.3020906@lu.unisi.ch","threadId":"7134","inReplyTo":"7vfy8hihwp.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH, 2nd version] git-archimport: allow remapping branch names","fromName":"Paolo Bonzini","fromEmail":"paolo.bonzini@lu.unisi.ch","sentAt":"2007-03-07T08:25:11Z","receivedAt":"2007-03-07T08:25:11Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> Thanks.  [Signed-Off-By?]\n\nSorry, I keep forgetting it.  I'll add an alias to pass -s always. :-)\n\nSigned-Off-By: Paolo Bonzini  <bonzini@gnu.org>\n\nPaolo\n"},{"id":"36537","messageId":"7vlki9h1mg.fsf@assigned-by-dhcp.cox.net","threadId":"7134","inReplyTo":"45EE7442.6030308@lu.unisi.ch","subject":"Re: [PATCH, 2nd version] git-archimport: allow remapping branch names","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-07T08:57:43Z","receivedAt":"2007-03-07T08:57:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:\n\n> \tGreat idea.  Thanks.  By the way, this patch was tested on\n> \tmy Arch repositories.\n\nJust to make sure.  Was it tested with AND WITHOUT the new colon\nfeature?  I am asking how likely is there a regression.\n\n> diff --git a/git-archimport.perl b/git-archimport.perl\n> index 0fcb156..1044695 100755\n> --- a/git-archimport.perl\n> +++ b/git-archimport.perl\n> @@ -89,7 +89,11 @@ usage if $opt_h;\n>  # values associated with keys:\n>  #   =1 - Arch version / git 'branch' detected via abrowse on a limit\n>  #   >1 - Arch version / git 'branch' of an auxiliary branch we've merged\n> -my %arch_branches = map { $_ => 1 } @ARGV;\n> +my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;\n\nI am a bit puzzled here.  Let's consider four cases.\n\n (0) No colon in arch archive, no mapping\n (1) No colon in arch archive, mapped to 'master'\n (2) A colon in arch archive, no mapping specified\n (3) A colon in arch archive, mapped to 'master'\n\nThe above s/:.*// would do:\n\n (0) bonzini-2005/devo ==> bonzini-2005/devo\n (1) bonzini-2005/devo:master ==> bonzini-2005/devo\n (2) bonzini:gnu-2005/devo ==> bonzini\n (3) bonzini:gnu-2005/devo:master ==> bonzini\n\nand then later branch_name_map splits them to:\n\n (0) bonzini-2005/devo ==> no entry in %branch_name_map\n (1) bonzini-2005/devo ==> no entry in %branch_name_map\n (2) bonzini:gnu-2005/devo ==> (bonzini => gnu-2005/devo)\n (3) bonzini:gnu-2005/devo:master ==> (bonzini:gnu-2005/devo => master)\n\nIn effect, (2) is an error, which is fine, because if the arch\narchive had colon in its name then the user can ask explicitly\nto map it by having an extra ':<branchname>'.  However, I think\nyour s/:.*// above breaks case (3).\n\n> +\n> +# $branch_name_map:\n> +# maps arch branches to git branch names\n> +my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;\n> ...\n> @@ -104,6 +108,7 @@ ...\n> +sub git_branchname {\n> +    my $revision = shift;\n> +    my $name = extract_versionname($revision);\n> +\n> +    if (defined $branch_name_map{$name}) {\n> +\treturn $branch_name_map{$name};\n\nThis is purely a style issue, but I tend to prefer 'exists' over\n'defined' when checking if a name is something that was placed\nin a hash we set up earlier by reading configuration or command,\neven if we _know_ that the hash was created with 'defined' values\nin them.\n\n>  sub process_patchset_accurate {\n>      my $ps = shift;\n> @@ -333,19 +365,23 @@ sub process_patchset_accurate {\n>          if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {\n>              \n>              # find where we are supposed to branch from\n> -            system('git-checkout','-f','-b',$ps->{branch},\n> -                            $branchpoint) == 0 or die \"$! $?\\n\";\n> -            \n> +\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n> +\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n\nStrictly speaking (-e \"$git_dir/refs/heads/$branch\") test would\nnot work if the repository was pack-ref'ed with --all option.\nRun \"git show-ref -q --verify refs/heads/$branch\" and check its\nexit status, or run it without -q and read its output.\n\n> @@ -830,8 +871,9 @@ sub tag {\n>      if ($opt_o) {\n>          $tag =~ s|/|--|g;\n>      } else {\n> -        # don't use subdirs for tags yet, it could screw up other porcelains\n> -        $tag =~ s|/|,|g;\n> +\tmy $patchname = $tag;\n> +\t$patchname =~ s/.*--//;\n> +        $tag = git_branchname ($tag) . '--' . $patchname;\n>      }\n>      \n>      if ($commit) {\n\nThe call to git_branchname() is essential for mapping the name\nwe get from arch using the command line mapping, but if the user\nis not using this remapping feature, does this keep the original\nbehaviour?\n\nWith the original code, a tag \"t--a/g\" was mapped to \"t--a,g\" in\nthe else clause, but the new code yields git_branchname(\"t--a/g\")\nfollowed by '--' followed by \"g\", which would evaluate to I do\nnot know what exactly, but I am sure it would not evaluate to\n\"t--a,g\".  Would it be a non-issue?  As archimport seems to support\nincremental import, I suspect it might upset existing users.\n"},{"id":"36538","messageId":"45EE80B0.8010403@lu.unisi.ch","threadId":"7134","inReplyTo":"7vlki9h1mg.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH, 2nd version] git-archimport: allow remapping branch names","fromName":"Paolo Bonzini","fromEmail":"paolo.bonzini@lu.unisi.ch","sentAt":"2007-03-07T09:06:56Z","receivedAt":"2007-03-07T09:06:56Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> Just to make sure.  Was it tested with AND WITHOUT the new colon\n> feature?  I am asking how likely is there a regression.\n\nYes.  But my Arch repositories do not have colons in the name (I mean I tested on real-world repositories and not weird ones created exactly to make the patch fail).\n\n>> -my %arch_branches = map { $_ => 1 } @ARGV;\n>> +my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;\n\nIn fact, I was too headlong on your suggestion.  I should have noticed that this substitution must be changed to\n\n$branch =~ s/:[^:]*$//\n\nI just realized, however, that branches with colons in the names would have failed before my patch too, because git would have failed creating a branch with a colon in it.  So this is not a regression, strictly speaking.\n\n> Strictly speaking (-e \"$git_dir/refs/heads/$branch\") test would\n> not work if the repository was pack-ref'ed with --all option.\n> Run \"git show-ref -q --verify refs/heads/$branch\" and check its\n> exit status, or run it without -q and read its output.\n\nUnfortunately this is pervasive in git-archimport.  I can fix it, but I think it belongs in a separate patch.\n\n> With the original code, a tag \"t--a/g\" was mapped to \"t--a,g\" in\n> the else clause, but the new code yields git_branchname(\"t--a/g\")\n> followed by '--' followed by \"g\", which would evaluate to I do\n> not know what exactly, but I am sure it would not evaluate to\n> \"t--a,g\".  Would it be a non-issue?  As archimport seems to support\n> incremental import, I suspect it might upset existing users.\n\nIn this case, this input will always be of the form t--a/g--REVISION.\n\nSo the old one would change to t--a,g--REVISION; the new one would\nstrip to t--a/g and convert it to t--a,g (using git_default_branchname)\nand file tack --REVISION at the end again.\n\nI will shortly send an updated patch\n\nPaolo\n"},{"id":"36540","messageId":"7vwt1tfle8.fsf@assigned-by-dhcp.cox.net","threadId":"7134","inReplyTo":"45EE80B0.8010403@lu.unisi.ch","subject":"Re: [PATCH, 2nd version] git-archimport: allow remapping branch names","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-07T09:33:35Z","receivedAt":"2007-03-07T09:33:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:\n\n>> Just to make sure.  Was it tested with AND WITHOUT the new colon\n>> feature?  I am asking how likely is there a regression.\n>\n> Yes.  But my Arch repositories do not have colons in the name (I mean I tested on real-world repositories and not weird ones created exactly to make the patch fail).\n\nThat's fine.\n\n> In this case, this input will always be of the form t--a/g--REVISION.\n>\n> So the old one would change to t--a,g--REVISION; the new one would\n> strip to t--a/g and convert it to t--a,g (using git_default_branchname)\n> and file tack --REVISION at the end again.\n\nAh, thanks.\n"},{"id":"36541","messageId":"45EE894D.4000206@lu.unisi.ch","threadId":"7134","inReplyTo":"7vwt1tfle8.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH, final version] git-archimport: allow remapping branch names","fromName":"Paolo Bonzini","fromEmail":"paolo.bonzini@lu.unisi.ch","sentAt":"2007-03-07T09:43:41Z","receivedAt":"2007-03-07T09:43:41Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"This patch add support to archimport for remapping the branch names\nto match those used in git more closely.  This is useful for\nprojects that *migrate* to git (as opposed to users that want\nto use git on Arch-based projects).  For example, one can\nchoose a branch name and call it \"master\".\n\nThe new command-line syntax works even if there is a colon in\na branch name, since only the part after the last colon is taken\nto be the git name (git does not allow colons in branch names).\n\nThe new feature is implemented so that archives rotated every\nyear can also be remapped into a single git archive.\n---\n Documentation/git-archimport.txt |   19 +++++++-\n git-archimport.perl              |   86 ++++++++++++++++++++++++++++----------\n 2 files changed, 81 insertions(+), 24 deletions(-)\n\n\t>> In this case, this input will always be of the form t--a/g--REVISION.\n\t>>\n\t>> So the old one would change to t--a,g--REVISION; the new one would\n\t>> strip to t--a/g and convert it to t--a,g (using git_default_branchname)\n\t>> and file tack --REVISION at the end again.\n\t> \n\t> Ah, thanks.\n\n\tGood, here's the final version then.  Thanks for putting up with me.\n\ndiff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt\nindex 5a13187..5794928 100644\n--- a/Documentation/git-archimport.txt\n+++ b/Documentation/git-archimport.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]\n-               <archive/branch> [ <archive/branch> ]\n+               <archive/branch>[:<git-branch>] ...\n \n DESCRIPTION\n -----------\n@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun\n `git-archimport` with the same parameters as the initial import to perform \n incremental imports.\n \n+While git-archimport will try to create sensible branch names for the\n+archives that it imports, it is also possible to specify git branch names\n+manually.  To do so, write a git branch name after each <archive/branch>\n+parameter, separated by a colon.  This way, you can shorten the Arch\n+branch names and convert Arch jargon to git jargon, for example mapping a\n+\"PROJECT--devo--VERSION\" branch to \"master\".\n+\n+Associating multiple Arch branches to one git branch is possible; the\n+result will make the most sense only if no commits are made to the first\n+branch, after the second branch is created.  Still, this is useful to\n+convert Arch repositories that had been rotated periodically.\n+\n+\n MERGES\n ------\n Patch merge data from Arch is used to mark merges in git as well. git \n@@ -73,7 +86,9 @@ OPTIONS\n \tUse this for compatibility with old-style branch names used by\n \tearlier versions of git-archimport.  Old-style branch names\n \twere category--branch, whereas new-style branch names are\n-\tarchive,category--branch--version.\n+\tarchive,category--branch--version.  In both cases, names given\n+\ton the command-line will override the automatically-generated\n+\tones.\n \n -D <depth>::\n \tFollow merge ancestry and attempt to import trees that have been\ndiff --git a/git-archimport.perl b/git-archimport.perl\nindex 0fcb156..1044695 100755\n--- a/git-archimport.perl\n+++ b/git-archimport.perl\n@@ -89,7 +89,11 @@ usage if $opt_h;\n # values associated with keys:\n #   =1 - Arch version / git 'branch' detected via abrowse on a limit\n #   >1 - Arch version / git 'branch' of an auxiliary branch we've merged\n-my %arch_branches = map { $_ => 1 } @ARGV;\n+my %arch_branches = map { my $branch = $_; $branch =~ s/:[^:]*$//; $branch => 1 } @ARGV;\n+\n+# $branch_name_map:\n+# maps arch branches to git branch names\n+my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;\n \n $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:\n my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);\n@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory\n     closedir DIR\n }\n \n+my $default_archive;\t\t# default Arch archive\n my %reachable = ();             # Arch repositories we can access\n my %unreachable = ();           # Arch repositories we can't access :<\n my @psets  = ();                # the collection\n@@ -303,7 +308,34 @@ sub old_style_branchname {\n     return $ret;\n }\n \n-*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;\n+*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;\n+\n+# retrieve default archive, since $branch_name_map keys might not include it\n+sub get_default_archive {\n+    if (!defined $default_archive) {\n+        $default_archive = safe_pipe_capture($TLA,'my-default-archive');\n+        chomp $default_archive;\n+    }\n+    return $default_archive;\n+}\n+\n+sub git_branchname {\n+    my $revision = shift;\n+    my $name = extract_versionname($revision);\n+\n+    if (exists $branch_name_map{$name}) {\n+\treturn $branch_name_map{$name};\n+\n+    } elsif ($name =~ m#^([^/]*)/(.*)$#\n+\t     && $1 eq get_default_archive()\n+\t     && exists $branch_name_map{$2}) {\n+\t# the names given in the command-line lacked the archive.\n+\treturn $branch_name_map{$2};\n+\n+    } else {\n+\treturn git_default_branchname($revision);\n+    }\n+}\n \n sub process_patchset_accurate {\n     my $ps = shift;\n@@ -333,19 +365,23 @@ sub process_patchset_accurate {\n         if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {\n             \n             # find where we are supposed to branch from\n-            system('git-checkout','-f','-b',$ps->{branch},\n-                            $branchpoint) == 0 or die \"$! $?\\n\";\n-            \n+\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n+\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n+\n+\t\t# We trust Arch with the fact that this is just a tag,\n+\t\t# and it does not affect the state of the tree, so\n+\t\t# we just tag and move on.  If the user really wants us\n+\t\t# to consolidate more branches into one, don't tag because\n+\t\t# the tag name would be already taken.\n+\t\ttag($ps->{id}, $branchpoint);\n+\t\tptag($ps->{id}, $branchpoint);\n+\t\tprint \" * Tagged $ps->{id} at $branchpoint\\n\";\n+\t    }\n+\t    system('git-checkout','-f',$ps->{branch}) == 0 or die \"$! $?\\n\";\n+\n             # remove any old stuff that got leftover:\n             my $rm = safe_pipe_capture('git-ls-files','--others','-z');\n             rmtree(split(/\\0/,$rm)) if $rm;\n-\n-            # If we trust Arch with the fact that this is just \n-            # a tag, and it does not affect the state of the tree\n-            # then we just tag and move on\n-            tag($ps->{id}, $branchpoint);\n-            ptag($ps->{id}, $branchpoint);\n-            print \" * Tagged $ps->{id} at $branchpoint\\n\";\n             return 0;\n         } else {\n             warn \"Tagging from unknown id unsupported\\n\" if $ps->{tag};\n@@ -385,14 +421,19 @@ sub process_patchset_fast {\n                 unless $branchpoint;\n             \n             # find where we are supposed to branch from\n-            system('git-checkout','-b',$ps->{branch},$branchpoint);\n-\n-            # If we trust Arch with the fact that this is just \n-            # a tag, and it does not affect the state of the tree\n-            # then we just tag and move on\n-            tag($ps->{id}, $branchpoint);\n-            ptag($ps->{id}, $branchpoint);\n-            print \" * Tagged $ps->{id} at $branchpoint\\n\";\n+\t    if (! -e \"$git_dir/refs/heads/$ps->{branch}\") {\n+\t\tsystem('git-branch',$ps->{branch},$branchpoint) == 0 or die \"$! $?\\n\";\n+\n+\t\t# We trust Arch with the fact that this is just a tag,\n+\t\t# and it does not affect the state of the tree, so\n+\t\t# we just tag and move on.  If the user really wants us\n+\t\t# to consolidate more branches into one, don't tag because\n+\t\t# the tag name would be already taken.\n+\t\ttag($ps->{id}, $branchpoint);\n+\t\tptag($ps->{id}, $branchpoint);\n+\t\tprint \" * Tagged $ps->{id} at $branchpoint\\n\";\n+            }\n+            system('git-checkout',$ps->{branch}) == 0 or die \"$! $?\\n\";\n             return 0;\n         } \n         die $! if $?;\n@@ -830,8 +871,9 @@ sub tag {\n     if ($opt_o) {\n         $tag =~ s|/|--|g;\n     } else {\n-        # don't use subdirs for tags yet, it could screw up other porcelains\n-        $tag =~ s|/|,|g;\n+\tmy $patchname = $tag;\n+\t$patchname =~ s/.*--//;\n+        $tag = git_branchname ($tag) . '--' . $patchname;\n     }\n     \n     if ($commit) {\n-- 1.4.4.2 \n"},{"id":"36542","messageId":"45EE8A84.8070908@lu.unisi.ch","threadId":"7134","inReplyTo":"45EE894D.4000206@lu.unisi.ch","subject":"Re: [PATCH, final version] git-archimport: allow remapping branch names","fromName":"Paolo Bonzini","fromEmail":"paolo.bonzini@lu.unisi.ch","sentAt":"2007-03-07T09:48:52Z","receivedAt":"2007-03-07T09:48:52Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> This patch add support to archimport for remapping the branch names\n> to match those used in git more closely.  This is useful for\n> projects that *migrate* to git (as opposed to users that want\n> to use git on Arch-based projects).  For example, one can\n> choose a branch name and call it \"master\".\n> \n> The new command-line syntax works even if there is a colon in\n> a branch name, since only the part after the last colon is taken\n> to be the git name (git does not allow colons in branch names).\n> \n> The new feature is implemented so that archives rotated every\n> year can also be remapped into a single git archive.\n\nARGH!\n\nSigned-Off-By: Paolo Bonzini  <bonzini@gnu.org>\n\npaolo\n"}]}