* [PATCH] git-archimport: allow remapping branch names
@ 2007-03-07 7:59 Paolo Bonzini
2007-03-07 8:09 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2007-03-07 7:59 UTC (permalink / raw)
To: git
This patch add support to archimport for remapping the branch names
to match those used in git more closely. This is useful for
projects that *migrate* to git (as opposed to users that want
to use clone into git from Arch-based projects). For example, one
can choose the name "master" for the development branch.
The new command-line syntax should not be a problem, since a colon
in a branch name would be a pretty weird choice even for
Arch standards.
The new feature is implemented so that archives rotated every
year can be remapped into a single git archive.
---
Documentation/git-archimport.txt | 19 +++++++-
git-archimport.perl | 86 ++++++++++++++++++++++++++++----------
2 files changed, 81 insertions(+), 24 deletions(-)
diff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt
index 5a13187..5794928 100644
--- a/Documentation/git-archimport.txt
+++ b/Documentation/git-archimport.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
- <archive/branch> [ <archive/branch> ]
+ <archive/branch>[:<git-branch>] ...
DESCRIPTION
-----------
@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun
`git-archimport` with the same parameters as the initial import to perform
incremental imports.
+While git-archimport will try to create sensible branch names for the
+archives that it imports, it is also possible to specify git branch names
+manually. To do so, write a git branch name after each <archive/branch>
+parameter, separated by a colon. This way, you can shorten the Arch
+branch names and convert Arch jargon to git jargon, for example mapping a
+"PROJECT--devo--VERSION" branch to "master".
+
+Associating multiple Arch branches to one git branch is possible; the
+result will make the most sense only if no commits are made to the first
+branch, after the second branch is created. Still, this is useful to
+convert Arch repositories that had been rotated periodically.
+
+
MERGES
------
Patch merge data from Arch is used to mark merges in git as well. git
@@ -73,7 +86,9 @@ OPTIONS
Use this for compatibility with old-style branch names used by
earlier versions of git-archimport. Old-style branch names
were category--branch, whereas new-style branch names are
- archive,category--branch--version.
+ archive,category--branch--version. In both cases, names given
+ on the command-line will override the automatically-generated
+ ones.
-D <depth>::
Follow merge ancestry and attempt to import trees that have been
diff --git a/git-archimport.perl b/git-archimport.perl
index 0fcb156..1044695 100755
--- a/git-archimport.perl
+++ b/git-archimport.perl
@@ -89,7 +89,11 @@ usage if $opt_h;
# values associated with keys:
# =1 - Arch version / git 'branch' detected via abrowse on a limit
# >1 - Arch version / git 'branch' of an auxiliary branch we've merged
-my %arch_branches = map { $_ => 1 } @ARGV;
+my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;
+
+# $branch_name_map:
+# maps arch branches to git branch names
+my %branch_name_map = map { m/^([^:]*):(.*)/; $1 => $2 } grep { m/:/ } @ARGV;
$ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory
closedir DIR
}
+my $default_archive; # default Arch archive
my %reachable = (); # Arch repositories we can access
my %unreachable = (); # Arch repositories we can't access :<
my @psets = (); # the collection
@@ -303,7 +308,34 @@ sub old_style_branchname {
return $ret;
}
-*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
+*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
+
+# retrieve default archive, since $branch_name_map keys might not include it
+sub get_default_archive {
+ if (!defined $default_archive) {
+ $default_archive = safe_pipe_capture($TLA,'my-default-archive');
+ chomp $default_archive;
+ }
+ return $default_archive;
+}
+
+sub git_branchname {
+ my $revision = shift;
+ my $name = extract_versionname($revision);
+
+ if (defined $branch_name_map{$name}) {
+ return $branch_name_map{$name};
+
+ } elsif ($name =~ m#^([^/]*)/(.*)$#
+ && $1 eq get_default_archive()
+ && defined $branch_name_map{$2}) {
+ # the names given in the command-line lacked the archive.
+ return $branch_name_map{$2};
+
+ } else {
+ return git_default_branchname($revision);
+ }
+}
sub process_patchset_accurate {
my $ps = shift;
@@ -333,19 +365,23 @@ sub process_patchset_accurate {
if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
# find where we are supposed to branch from
- system('git-checkout','-f','-b',$ps->{branch},
- $branchpoint) == 0 or die "$! $?\n";
-
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
+
+ # We trust Arch with the fact that this is just a tag,
+ # and it does not affect the state of the tree, so
+ # we just tag and move on. If the user really wants us
+ # to consolidate more branches into one, don't tag because
+ # the tag name would be already taken.
+ tag($ps->{id}, $branchpoint);
+ ptag($ps->{id}, $branchpoint);
+ print " * Tagged $ps->{id} at $branchpoint\n";
+ }
+ system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n";
+
# remove any old stuff that got leftover:
my $rm = safe_pipe_capture('git-ls-files','--others','-z');
rmtree(split(/\0/,$rm)) if $rm;
-
- # If we trust Arch with the fact that this is just
- # a tag, and it does not affect the state of the tree
- # then we just tag and move on
- tag($ps->{id}, $branchpoint);
- ptag($ps->{id}, $branchpoint);
- print " * Tagged $ps->{id} at $branchpoint\n";
return 0;
} else {
warn "Tagging from unknown id unsupported\n" if $ps->{tag};
@@ -385,14 +421,19 @@ sub process_patchset_fast {
unless $branchpoint;
# find where we are supposed to branch from
- system('git-checkout','-b',$ps->{branch},$branchpoint);
-
- # If we trust Arch with the fact that this is just
- # a tag, and it does not affect the state of the tree
- # then we just tag and move on
- tag($ps->{id}, $branchpoint);
- ptag($ps->{id}, $branchpoint);
- print " * Tagged $ps->{id} at $branchpoint\n";
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
+
+ # We trust Arch with the fact that this is just a tag,
+ # and it does not affect the state of the tree, so
+ # we just tag and move on. If the user really wants us
+ # to consolidate more branches into one, don't tag because
+ # the tag name would be already taken.
+ tag($ps->{id}, $branchpoint);
+ ptag($ps->{id}, $branchpoint);
+ print " * Tagged $ps->{id} at $branchpoint\n";
+ }
+ system('git-checkout',$ps->{branch}) == 0 or die "$! $?\n";
return 0;
}
die $! if $?;
@@ -830,8 +871,9 @@ sub tag {
if ($opt_o) {
$tag =~ s|/|--|g;
} else {
- # don't use subdirs for tags yet, it could screw up other porcelains
- $tag =~ s|/|,|g;
+ my $patchname = $tag;
+ $patchname =~ s/.*--//;
+ $tag = git_branchname ($tag) . '--' . $patchname;
}
if ($commit) {
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] git-archimport: allow remapping branch names
2007-03-07 7:59 [PATCH] git-archimport: allow remapping branch names Paolo Bonzini
@ 2007-03-07 8:09 ` Junio C Hamano
2007-03-07 8:13 ` [PATCH, 2nd version] " Paolo Bonzini
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-03-07 8:09 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: git
Paolo Bonzini <bonzini@gnu.org> writes:
> The new command-line syntax should not be a problem, since a colon
> in a branch name would be a pretty weird choice even for
> Arch standards.
>
> The new feature is implemented so that archives rotated every
> year can be remapped into a single git archive.
> 'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
> - <archive/branch> [ <archive/branch> ]
> + <archive/branch>[:<git-branch>] ...
> ...
> -my %arch_branches = map { $_ => 1 } @ARGV;
> +my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;
> +
> +# $branch_name_map:
> +# maps arch branches to git branch names
> +my %branch_name_map = map { m/^([^:]*):(.*)/; $1 => $2 } grep { m/:/ } @ARGV;
I am no arch/tla expert, but at least git does not allow colon
in branch names at all, so if you make your command line parser
to match left-greedy-anything, colon and then right-non-colon
(i.e. m/^(.*):([^:]*)$/), you should be able to handle colons in
arch archive names.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH, 2nd version] git-archimport: allow remapping branch names
2007-03-07 8:09 ` Junio C Hamano
@ 2007-03-07 8:13 ` Paolo Bonzini
[not found] ` <7vfy8hihwp.fsf@assigned-by-dhcp.cox.net>
2007-03-07 8:57 ` Junio C Hamano
0 siblings, 2 replies; 9+ messages in thread
From: Paolo Bonzini @ 2007-03-07 8:13 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This patch add support to archimport for remapping the branch names
to match those used in git more closely. This is useful for
projects that *migrate* to git (as opposed to users that want
to use git on Arch-based projects). For example, one can
choose a branch name and call it "master".
The new command-line syntax works even if there is a colon in
a branch name, since only the part after the last colon is taken
to be the git name (git does not allow colons in branch names).
The new feature is implemented so that archives rotated every
year can also be remapped into a single git archive.
---
Documentation/git-archimport.txt | 19 +++++++-
git-archimport.perl | 86 ++++++++++++++++++++++++++++----------
2 files changed, 81 insertions(+), 24 deletions(-)
> I am no arch/tla expert, but at least git does not allow colon
> in branch names at all, so if you make your command line parser
> to match left-greedy-anything, colon and then right-non-colon
> (i.e. m/^(.*):([^:]*)$/), you should be able to handle colons in
> arch archive names.
Great idea. Thanks. By the way, this patch was tested on
my Arch repositories.
diff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt
index 5a13187..5794928 100644
--- a/Documentation/git-archimport.txt
+++ b/Documentation/git-archimport.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
- <archive/branch> [ <archive/branch> ]
+ <archive/branch>[:<git-branch>] ...
DESCRIPTION
-----------
@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun
`git-archimport` with the same parameters as the initial import to perform
incremental imports.
+While git-archimport will try to create sensible branch names for the
+archives that it imports, it is also possible to specify git branch names
+manually. To do so, write a git branch name after each <archive/branch>
+parameter, separated by a colon. This way, you can shorten the Arch
+branch names and convert Arch jargon to git jargon, for example mapping a
+"PROJECT--devo--VERSION" branch to "master".
+
+Associating multiple Arch branches to one git branch is possible; the
+result will make the most sense only if no commits are made to the first
+branch, after the second branch is created. Still, this is useful to
+convert Arch repositories that had been rotated periodically.
+
+
MERGES
------
Patch merge data from Arch is used to mark merges in git as well. git
@@ -73,7 +86,9 @@ OPTIONS
Use this for compatibility with old-style branch names used by
earlier versions of git-archimport. Old-style branch names
were category--branch, whereas new-style branch names are
- archive,category--branch--version.
+ archive,category--branch--version. In both cases, names given
+ on the command-line will override the automatically-generated
+ ones.
-D <depth>::
Follow merge ancestry and attempt to import trees that have been
diff --git a/git-archimport.perl b/git-archimport.perl
index 0fcb156..1044695 100755
--- a/git-archimport.perl
+++ b/git-archimport.perl
@@ -89,7 +89,11 @@ usage if $opt_h;
# values associated with keys:
# =1 - Arch version / git 'branch' detected via abrowse on a limit
# >1 - Arch version / git 'branch' of an auxiliary branch we've merged
-my %arch_branches = map { $_ => 1 } @ARGV;
+my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;
+
+# $branch_name_map:
+# maps arch branches to git branch names
+my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;
$ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory
closedir DIR
}
+my $default_archive; # default Arch archive
my %reachable = (); # Arch repositories we can access
my %unreachable = (); # Arch repositories we can't access :<
my @psets = (); # the collection
@@ -303,7 +308,34 @@ sub old_style_branchname {
return $ret;
}
-*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
+*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
+
+# retrieve default archive, since $branch_name_map keys might not include it
+sub get_default_archive {
+ if (!defined $default_archive) {
+ $default_archive = safe_pipe_capture($TLA,'my-default-archive');
+ chomp $default_archive;
+ }
+ return $default_archive;
+}
+
+sub git_branchname {
+ my $revision = shift;
+ my $name = extract_versionname($revision);
+
+ if (defined $branch_name_map{$name}) {
+ return $branch_name_map{$name};
+
+ } elsif ($name =~ m#^([^/]*)/(.*)$#
+ && $1 eq get_default_archive()
+ && defined $branch_name_map{$2}) {
+ # the names given in the command-line lacked the archive.
+ return $branch_name_map{$2};
+
+ } else {
+ return git_default_branchname($revision);
+ }
+}
sub process_patchset_accurate {
my $ps = shift;
@@ -333,19 +365,23 @@ sub process_patchset_accurate {
if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
# find where we are supposed to branch from
- system('git-checkout','-f','-b',$ps->{branch},
- $branchpoint) == 0 or die "$! $?\n";
-
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
+
+ # We trust Arch with the fact that this is just a tag,
+ # and it does not affect the state of the tree, so
+ # we just tag and move on. If the user really wants us
+ # to consolidate more branches into one, don't tag because
+ # the tag name would be already taken.
+ tag($ps->{id}, $branchpoint);
+ ptag($ps->{id}, $branchpoint);
+ print " * Tagged $ps->{id} at $branchpoint\n";
+ }
+ system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n";
+
# remove any old stuff that got leftover:
my $rm = safe_pipe_capture('git-ls-files','--others','-z');
rmtree(split(/\0/,$rm)) if $rm;
-
- # If we trust Arch with the fact that this is just
- # a tag, and it does not affect the state of the tree
- # then we just tag and move on
- tag($ps->{id}, $branchpoint);
- ptag($ps->{id}, $branchpoint);
- print " * Tagged $ps->{id} at $branchpoint\n";
return 0;
} else {
warn "Tagging from unknown id unsupported\n" if $ps->{tag};
@@ -385,14 +421,19 @@ sub process_patchset_fast {
unless $branchpoint;
# find where we are supposed to branch from
- system('git-checkout','-b',$ps->{branch},$branchpoint);
-
- # If we trust Arch with the fact that this is just
- # a tag, and it does not affect the state of the tree
- # then we just tag and move on
- tag($ps->{id}, $branchpoint);
- ptag($ps->{id}, $branchpoint);
- print " * Tagged $ps->{id} at $branchpoint\n";
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
+
+ # We trust Arch with the fact that this is just a tag,
+ # and it does not affect the state of the tree, so
+ # we just tag and move on. If the user really wants us
+ # to consolidate more branches into one, don't tag because
+ # the tag name would be already taken.
+ tag($ps->{id}, $branchpoint);
+ ptag($ps->{id}, $branchpoint);
+ print " * Tagged $ps->{id} at $branchpoint\n";
+ }
+ system('git-checkout',$ps->{branch}) == 0 or die "$! $?\n";
return 0;
}
die $! if $?;
@@ -830,8 +871,9 @@ sub tag {
if ($opt_o) {
$tag =~ s|/|--|g;
} else {
- # don't use subdirs for tags yet, it could screw up other porcelains
- $tag =~ s|/|,|g;
+ my $patchname = $tag;
+ $patchname =~ s/.*--//;
+ $tag = git_branchname ($tag) . '--' . $patchname;
}
if ($commit) {
--
1.4.4.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH, 2nd version] git-archimport: allow remapping branch names
[not found] ` <7vfy8hihwp.fsf@assigned-by-dhcp.cox.net>
@ 2007-03-07 8:25 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2007-03-07 8:25 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
> Thanks. [Signed-Off-By?]
Sorry, I keep forgetting it. I'll add an alias to pass -s always. :-)
Signed-Off-By: Paolo Bonzini <bonzini@gnu.org>
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH, 2nd version] git-archimport: allow remapping branch names
2007-03-07 8:13 ` [PATCH, 2nd version] " Paolo Bonzini
[not found] ` <7vfy8hihwp.fsf@assigned-by-dhcp.cox.net>
@ 2007-03-07 8:57 ` Junio C Hamano
2007-03-07 9:06 ` Paolo Bonzini
1 sibling, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-03-07 8:57 UTC (permalink / raw)
To: bonzini; +Cc: git
Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:
> Great idea. Thanks. By the way, this patch was tested on
> my Arch repositories.
Just to make sure. Was it tested with AND WITHOUT the new colon
feature? I am asking how likely is there a regression.
> diff --git a/git-archimport.perl b/git-archimport.perl
> index 0fcb156..1044695 100755
> --- a/git-archimport.perl
> +++ b/git-archimport.perl
> @@ -89,7 +89,11 @@ usage if $opt_h;
> # values associated with keys:
> # =1 - Arch version / git 'branch' detected via abrowse on a limit
> # >1 - Arch version / git 'branch' of an auxiliary branch we've merged
> -my %arch_branches = map { $_ => 1 } @ARGV;
> +my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;
I am a bit puzzled here. Let's consider four cases.
(0) No colon in arch archive, no mapping
(1) No colon in arch archive, mapped to 'master'
(2) A colon in arch archive, no mapping specified
(3) A colon in arch archive, mapped to 'master'
The above s/:.*// would do:
(0) bonzini-2005/devo ==> bonzini-2005/devo
(1) bonzini-2005/devo:master ==> bonzini-2005/devo
(2) bonzini:gnu-2005/devo ==> bonzini
(3) bonzini:gnu-2005/devo:master ==> bonzini
and then later branch_name_map splits them to:
(0) bonzini-2005/devo ==> no entry in %branch_name_map
(1) bonzini-2005/devo ==> no entry in %branch_name_map
(2) bonzini:gnu-2005/devo ==> (bonzini => gnu-2005/devo)
(3) bonzini:gnu-2005/devo:master ==> (bonzini:gnu-2005/devo => master)
In effect, (2) is an error, which is fine, because if the arch
archive had colon in its name then the user can ask explicitly
to map it by having an extra ':<branchname>'. However, I think
your s/:.*// above breaks case (3).
> +
> +# $branch_name_map:
> +# maps arch branches to git branch names
> +my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;
> ...
> @@ -104,6 +108,7 @@ ...
> +sub git_branchname {
> + my $revision = shift;
> + my $name = extract_versionname($revision);
> +
> + if (defined $branch_name_map{$name}) {
> + return $branch_name_map{$name};
This is purely a style issue, but I tend to prefer 'exists' over
'defined' when checking if a name is something that was placed
in a hash we set up earlier by reading configuration or command,
even if we _know_ that the hash was created with 'defined' values
in them.
> sub process_patchset_accurate {
> my $ps = shift;
> @@ -333,19 +365,23 @@ sub process_patchset_accurate {
> if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
>
> # find where we are supposed to branch from
> - system('git-checkout','-f','-b',$ps->{branch},
> - $branchpoint) == 0 or die "$! $?\n";
> -
> + if (! -e "$git_dir/refs/heads/$ps->{branch}") {
> + system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
Strictly speaking (-e "$git_dir/refs/heads/$branch") test would
not work if the repository was pack-ref'ed with --all option.
Run "git show-ref -q --verify refs/heads/$branch" and check its
exit status, or run it without -q and read its output.
> @@ -830,8 +871,9 @@ sub tag {
> if ($opt_o) {
> $tag =~ s|/|--|g;
> } else {
> - # don't use subdirs for tags yet, it could screw up other porcelains
> - $tag =~ s|/|,|g;
> + my $patchname = $tag;
> + $patchname =~ s/.*--//;
> + $tag = git_branchname ($tag) . '--' . $patchname;
> }
>
> if ($commit) {
The call to git_branchname() is essential for mapping the name
we get from arch using the command line mapping, but if the user
is not using this remapping feature, does this keep the original
behaviour?
With the original code, a tag "t--a/g" was mapped to "t--a,g" in
the else clause, but the new code yields git_branchname("t--a/g")
followed by '--' followed by "g", which would evaluate to I do
not know what exactly, but I am sure it would not evaluate to
"t--a,g". Would it be a non-issue? As archimport seems to support
incremental import, I suspect it might upset existing users.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH, 2nd version] git-archimport: allow remapping branch names
2007-03-07 8:57 ` Junio C Hamano
@ 2007-03-07 9:06 ` Paolo Bonzini
2007-03-07 9:33 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2007-03-07 9:06 UTC (permalink / raw)
To: Junio C Hamano; +Cc: bonzini, git
> Just to make sure. Was it tested with AND WITHOUT the new colon
> feature? I am asking how likely is there a regression.
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).
>> -my %arch_branches = map { $_ => 1 } @ARGV;
>> +my %arch_branches = map { my $branch = $_; $branch =~ s/:.*//; $branch => 1 } @ARGV;
In fact, I was too headlong on your suggestion. I should have noticed that this substitution must be changed to
$branch =~ s/:[^:]*$//
I 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.
> Strictly speaking (-e "$git_dir/refs/heads/$branch") test would
> not work if the repository was pack-ref'ed with --all option.
> Run "git show-ref -q --verify refs/heads/$branch" and check its
> exit status, or run it without -q and read its output.
Unfortunately this is pervasive in git-archimport. I can fix it, but I think it belongs in a separate patch.
> With the original code, a tag "t--a/g" was mapped to "t--a,g" in
> the else clause, but the new code yields git_branchname("t--a/g")
> followed by '--' followed by "g", which would evaluate to I do
> not know what exactly, but I am sure it would not evaluate to
> "t--a,g". Would it be a non-issue? As archimport seems to support
> incremental import, I suspect it might upset existing users.
In this case, this input will always be of the form t--a/g--REVISION.
So the old one would change to t--a,g--REVISION; the new one would
strip to t--a/g and convert it to t--a,g (using git_default_branchname)
and file tack --REVISION at the end again.
I will shortly send an updated patch
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH, 2nd version] git-archimport: allow remapping branch names
2007-03-07 9:06 ` Paolo Bonzini
@ 2007-03-07 9:33 ` Junio C Hamano
2007-03-07 9:43 ` [PATCH, final " Paolo Bonzini
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-03-07 9:33 UTC (permalink / raw)
To: bonzini; +Cc: git
Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:
>> Just to make sure. Was it tested with AND WITHOUT the new colon
>> feature? I am asking how likely is there a regression.
>
> 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).
That's fine.
> In this case, this input will always be of the form t--a/g--REVISION.
>
> So the old one would change to t--a,g--REVISION; the new one would
> strip to t--a/g and convert it to t--a,g (using git_default_branchname)
> and file tack --REVISION at the end again.
Ah, thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH, final version] git-archimport: allow remapping branch names
2007-03-07 9:33 ` Junio C Hamano
@ 2007-03-07 9:43 ` Paolo Bonzini
2007-03-07 9:48 ` Paolo Bonzini
0 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2007-03-07 9:43 UTC (permalink / raw)
To: Junio C Hamano; +Cc: bonzini, git
This patch add support to archimport for remapping the branch names
to match those used in git more closely. This is useful for
projects that *migrate* to git (as opposed to users that want
to use git on Arch-based projects). For example, one can
choose a branch name and call it "master".
The new command-line syntax works even if there is a colon in
a branch name, since only the part after the last colon is taken
to be the git name (git does not allow colons in branch names).
The new feature is implemented so that archives rotated every
year can also be remapped into a single git archive.
---
Documentation/git-archimport.txt | 19 +++++++-
git-archimport.perl | 86 ++++++++++++++++++++++++++++----------
2 files changed, 81 insertions(+), 24 deletions(-)
>> In this case, this input will always be of the form t--a/g--REVISION.
>>
>> So the old one would change to t--a,g--REVISION; the new one would
>> strip to t--a/g and convert it to t--a,g (using git_default_branchname)
>> and file tack --REVISION at the end again.
>
> Ah, thanks.
Good, here's the final version then. Thanks for putting up with me.
diff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt
index 5a13187..5794928 100644
--- a/Documentation/git-archimport.txt
+++ b/Documentation/git-archimport.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
- <archive/branch> [ <archive/branch> ]
+ <archive/branch>[:<git-branch>] ...
DESCRIPTION
-----------
@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun
`git-archimport` with the same parameters as the initial import to perform
incremental imports.
+While git-archimport will try to create sensible branch names for the
+archives that it imports, it is also possible to specify git branch names
+manually. To do so, write a git branch name after each <archive/branch>
+parameter, separated by a colon. This way, you can shorten the Arch
+branch names and convert Arch jargon to git jargon, for example mapping a
+"PROJECT--devo--VERSION" branch to "master".
+
+Associating multiple Arch branches to one git branch is possible; the
+result will make the most sense only if no commits are made to the first
+branch, after the second branch is created. Still, this is useful to
+convert Arch repositories that had been rotated periodically.
+
+
MERGES
------
Patch merge data from Arch is used to mark merges in git as well. git
@@ -73,7 +86,9 @@ OPTIONS
Use this for compatibility with old-style branch names used by
earlier versions of git-archimport. Old-style branch names
were category--branch, whereas new-style branch names are
- archive,category--branch--version.
+ archive,category--branch--version. In both cases, names given
+ on the command-line will override the automatically-generated
+ ones.
-D <depth>::
Follow merge ancestry and attempt to import trees that have been
diff --git a/git-archimport.perl b/git-archimport.perl
index 0fcb156..1044695 100755
--- a/git-archimport.perl
+++ b/git-archimport.perl
@@ -89,7 +89,11 @@ usage if $opt_h;
# values associated with keys:
# =1 - Arch version / git 'branch' detected via abrowse on a limit
# >1 - Arch version / git 'branch' of an auxiliary branch we've merged
-my %arch_branches = map { $_ => 1 } @ARGV;
+my %arch_branches = map { my $branch = $_; $branch =~ s/:[^:]*$//; $branch => 1 } @ARGV;
+
+# $branch_name_map:
+# maps arch branches to git branch names
+my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;
$ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory
closedir DIR
}
+my $default_archive; # default Arch archive
my %reachable = (); # Arch repositories we can access
my %unreachable = (); # Arch repositories we can't access :<
my @psets = (); # the collection
@@ -303,7 +308,34 @@ sub old_style_branchname {
return $ret;
}
-*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
+*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
+
+# retrieve default archive, since $branch_name_map keys might not include it
+sub get_default_archive {
+ if (!defined $default_archive) {
+ $default_archive = safe_pipe_capture($TLA,'my-default-archive');
+ chomp $default_archive;
+ }
+ return $default_archive;
+}
+
+sub git_branchname {
+ my $revision = shift;
+ my $name = extract_versionname($revision);
+
+ if (exists $branch_name_map{$name}) {
+ return $branch_name_map{$name};
+
+ } elsif ($name =~ m#^([^/]*)/(.*)$#
+ && $1 eq get_default_archive()
+ && exists $branch_name_map{$2}) {
+ # the names given in the command-line lacked the archive.
+ return $branch_name_map{$2};
+
+ } else {
+ return git_default_branchname($revision);
+ }
+}
sub process_patchset_accurate {
my $ps = shift;
@@ -333,19 +365,23 @@ sub process_patchset_accurate {
if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
# find where we are supposed to branch from
- system('git-checkout','-f','-b',$ps->{branch},
- $branchpoint) == 0 or die "$! $?\n";
-
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
+
+ # We trust Arch with the fact that this is just a tag,
+ # and it does not affect the state of the tree, so
+ # we just tag and move on. If the user really wants us
+ # to consolidate more branches into one, don't tag because
+ # the tag name would be already taken.
+ tag($ps->{id}, $branchpoint);
+ ptag($ps->{id}, $branchpoint);
+ print " * Tagged $ps->{id} at $branchpoint\n";
+ }
+ system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n";
+
# remove any old stuff that got leftover:
my $rm = safe_pipe_capture('git-ls-files','--others','-z');
rmtree(split(/\0/,$rm)) if $rm;
-
- # If we trust Arch with the fact that this is just
- # a tag, and it does not affect the state of the tree
- # then we just tag and move on
- tag($ps->{id}, $branchpoint);
- ptag($ps->{id}, $branchpoint);
- print " * Tagged $ps->{id} at $branchpoint\n";
return 0;
} else {
warn "Tagging from unknown id unsupported\n" if $ps->{tag};
@@ -385,14 +421,19 @@ sub process_patchset_fast {
unless $branchpoint;
# find where we are supposed to branch from
- system('git-checkout','-b',$ps->{branch},$branchpoint);
-
- # If we trust Arch with the fact that this is just
- # a tag, and it does not affect the state of the tree
- # then we just tag and move on
- tag($ps->{id}, $branchpoint);
- ptag($ps->{id}, $branchpoint);
- print " * Tagged $ps->{id} at $branchpoint\n";
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
+
+ # We trust Arch with the fact that this is just a tag,
+ # and it does not affect the state of the tree, so
+ # we just tag and move on. If the user really wants us
+ # to consolidate more branches into one, don't tag because
+ # the tag name would be already taken.
+ tag($ps->{id}, $branchpoint);
+ ptag($ps->{id}, $branchpoint);
+ print " * Tagged $ps->{id} at $branchpoint\n";
+ }
+ system('git-checkout',$ps->{branch}) == 0 or die "$! $?\n";
return 0;
}
die $! if $?;
@@ -830,8 +871,9 @@ sub tag {
if ($opt_o) {
$tag =~ s|/|--|g;
} else {
- # don't use subdirs for tags yet, it could screw up other porcelains
- $tag =~ s|/|,|g;
+ my $patchname = $tag;
+ $patchname =~ s/.*--//;
+ $tag = git_branchname ($tag) . '--' . $patchname;
}
if ($commit) {
-- 1.4.4.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH, final version] git-archimport: allow remapping branch names
2007-03-07 9:43 ` [PATCH, final " Paolo Bonzini
@ 2007-03-07 9:48 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2007-03-07 9:48 UTC (permalink / raw)
To: bonzini; +Cc: Junio C Hamano, git
> This patch add support to archimport for remapping the branch names
> to match those used in git more closely. This is useful for
> projects that *migrate* to git (as opposed to users that want
> to use git on Arch-based projects). For example, one can
> choose a branch name and call it "master".
>
> The new command-line syntax works even if there is a colon in
> a branch name, since only the part after the last colon is taken
> to be the git name (git does not allow colons in branch names).
>
> The new feature is implemented so that archives rotated every
> year can also be remapped into a single git archive.
ARGH!
Signed-Off-By: Paolo Bonzini <bonzini@gnu.org>
paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-03-07 9:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-07 7:59 [PATCH] git-archimport: allow remapping branch names Paolo Bonzini
2007-03-07 8:09 ` Junio C Hamano
2007-03-07 8:13 ` [PATCH, 2nd version] " Paolo Bonzini
[not found] ` <7vfy8hihwp.fsf@assigned-by-dhcp.cox.net>
2007-03-07 8:25 ` Paolo Bonzini
2007-03-07 8:57 ` Junio C Hamano
2007-03-07 9:06 ` Paolo Bonzini
2007-03-07 9:33 ` Junio C Hamano
2007-03-07 9:43 ` [PATCH, final " Paolo Bonzini
2007-03-07 9:48 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).