Skip to content

Commit d9cb539

Browse files
Paolo BonziniJunio C Hamano
authored andcommitted
git-archimport: allow remapping branch names
This patch adds 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 an Arch 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. Signed-off-by: Paolo Bonzini <bonzini@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent e3d842c commit d9cb539

File tree

2 files changed

+81
-24
lines changed

2 files changed

+81
-24
lines changed

Documentation/git-archimport.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
13-
<archive/branch> [ <archive/branch> ]
13+
<archive/branch>[:<git-branch>] ...
1414

1515
DESCRIPTION
1616
-----------
@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun
3939
`git-archimport` with the same parameters as the initial import to perform
4040
incremental imports.
4141

42+
While git-archimport will try to create sensible branch names for the
43+
archives that it imports, it is also possible to specify git branch names
44+
manually. To do so, write a git branch name after each <archive/branch>
45+
parameter, separated by a colon. This way, you can shorten the Arch
46+
branch names and convert Arch jargon to git jargon, for example mapping a
47+
"PROJECT--devo--VERSION" branch to "master".
48+
49+
Associating multiple Arch branches to one git branch is possible; the
50+
result will make the most sense only if no commits are made to the first
51+
branch, after the second branch is created. Still, this is useful to
52+
convert Arch repositories that had been rotated periodically.
53+
54+
4255
MERGES
4356
------
4457
Patch merge data from Arch is used to mark merges in git as well. git
@@ -73,7 +86,9 @@ OPTIONS
7386
Use this for compatibility with old-style branch names used by
7487
earlier versions of git-archimport. Old-style branch names
7588
were category--branch, whereas new-style branch names are
76-
archive,category--branch--version.
89+
archive,category--branch--version. In both cases, names given
90+
on the command-line will override the automatically-generated
91+
ones.
7792

7893
-D <depth>::
7994
Follow merge ancestry and attempt to import trees that have been

git-archimport.perl

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ END
8989
# values associated with keys:
9090
# =1 - Arch version / git 'branch' detected via abrowse on a limit
9191
# >1 - Arch version / git 'branch' of an auxiliary branch we've merged
92-
my %arch_branches = map { $_ => 1 } @ARGV;
92+
my %arch_branches = map { my $branch = $_; $branch =~ s/:[^:]*$//; $branch => 1 } @ARGV;
93+
94+
# $branch_name_map:
95+
# maps arch branches to git branch names
96+
my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;
9397

9498
$ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
9599
my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -104,6 +108,7 @@ END
104108
closedir DIR
105109
}
106110

111+
my $default_archive; # default Arch archive
107112
my %reachable = (); # Arch repositories we can access
108113
my %unreachable = (); # Arch repositories we can't access :<
109114
my @psets = (); # the collection
@@ -303,7 +308,34 @@ sub old_style_branchname {
303308
return $ret;
304309
}
305310

306-
*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
311+
*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
312+
313+
# retrieve default archive, since $branch_name_map keys might not include it
314+
sub get_default_archive {
315+
if (!defined $default_archive) {
316+
$default_archive = safe_pipe_capture($TLA,'my-default-archive');
317+
chomp $default_archive;
318+
}
319+
return $default_archive;
320+
}
321+
322+
sub git_branchname {
323+
my $revision = shift;
324+
my $name = extract_versionname($revision);
325+
326+
if (exists $branch_name_map{$name}) {
327+
return $branch_name_map{$name};
328+
329+
} elsif ($name =~ m#^([^/]*)/(.*)$#
330+
&& $1 eq get_default_archive()
331+
&& exists $branch_name_map{$2}) {
332+
# the names given in the command-line lacked the archive.
333+
return $branch_name_map{$2};
334+
335+
} else {
336+
return git_default_branchname($revision);
337+
}
338+
}
307339

308340
sub process_patchset_accurate {
309341
my $ps = shift;
@@ -333,19 +365,23 @@ sub process_patchset_accurate {
333365
if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
334366

335367
# find where we are supposed to branch from
336-
system('git-checkout','-f','-b',$ps->{branch},
337-
$branchpoint) == 0 or die "$! $?\n";
338-
368+
if (! -e "$git_dir/refs/heads/$ps->{branch}") {
369+
system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
370+
371+
# We trust Arch with the fact that this is just a tag,
372+
# and it does not affect the state of the tree, so
373+
# we just tag and move on. If the user really wants us
374+
# to consolidate more branches into one, don't tag because
375+
# the tag name would be already taken.
376+
tag($ps->{id}, $branchpoint);
377+
ptag($ps->{id}, $branchpoint);
378+
print " * Tagged $ps->{id} at $branchpoint\n";
379+
}
380+
system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n";
381+
339382
# remove any old stuff that got leftover:
340383
my $rm = safe_pipe_capture('git-ls-files','--others','-z');
341384
rmtree(split(/\0/,$rm)) if $rm;
342-
343-
# If we trust Arch with the fact that this is just
344-
# a tag, and it does not affect the state of the tree
345-
# then we just tag and move on
346-
tag($ps->{id}, $branchpoint);
347-
ptag($ps->{id}, $branchpoint);
348-
print " * Tagged $ps->{id} at $branchpoint\n";
349385
return 0;
350386
} else {
351387
warn "Tagging from unknown id unsupported\n" if $ps->{tag};
@@ -385,14 +421,19 @@ sub process_patchset_fast {
385421
unless $branchpoint;
386422

387423
# find where we are supposed to branch from
388-
system('git-checkout','-b',$ps->{branch},$branchpoint);
389-
390-
# If we trust Arch with the fact that this is just
391-
# a tag, and it does not affect the state of the tree
392-
# then we just tag and move on
393-
tag($ps->{id}, $branchpoint);
394-
ptag($ps->{id}, $branchpoint);
395-
print " * Tagged $ps->{id} at $branchpoint\n";
424+
if (! -e "$git_dir/refs/heads/$ps->{branch}") {
425+
system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
426+
427+
# We trust Arch with the fact that this is just a tag,
428+
# and it does not affect the state of the tree, so
429+
# we just tag and move on. If the user really wants us
430+
# to consolidate more branches into one, don't tag because
431+
# the tag name would be already taken.
432+
tag($ps->{id}, $branchpoint);
433+
ptag($ps->{id}, $branchpoint);
434+
print " * Tagged $ps->{id} at $branchpoint\n";
435+
}
436+
system('git-checkout',$ps->{branch}) == 0 or die "$! $?\n";
396437
return 0;
397438
}
398439
die $! if $?;
@@ -830,8 +871,9 @@ sub tag {
830871
if ($opt_o) {
831872
$tag =~ s|/|--|g;
832873
} else {
833-
# don't use subdirs for tags yet, it could screw up other porcelains
834-
$tag =~ s|/|,|g;
874+
my $patchname = $tag;
875+
$patchname =~ s/.*--//;
876+
$tag = git_branchname ($tag) . '--' . $patchname;
835877
}
836878

837879
if ($commit) {

0 commit comments

Comments
 (0)