@matheusbsbs / matheus-bagliano / commits / d9cb5399ee
Fork 0

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>

Paolo Bonzini committed Mar 7, 2007 at 10:43 UTC d9cb5399ee6e3ca4b3190f158ada7bd3802b3c70
2 files changed +81 -24
Documentation/git-archimport.txt
+17 -2
@@ -10,7 +10,7 @@ SYNOPSIS
10 --------
11 [verse]
12 'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir]
13 - <archive/branch> [ <archive/branch> ]
13 + <archive/branch>[:<git-branch>] ...
14
15 DESCRIPTION
16 -----------
@@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun
39 `git-archimport` with the same parameters as the initial import to perform
40 incremental imports.
41
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 +
55 MERGES
56 ------
57 Patch merge data from Arch is used to mark merges in git as well. git
@@ -73,7 +86,9 @@ OPTIONS
86 Use this for compatibility with old-style branch names used by
87 earlier versions of git-archimport. Old-style branch names
88 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.
92
93 -D <depth>::
94 Follow merge ancestry and attempt to import trees that have been
git-archimport.perl
+64 -22
@@ -89,7 +89,11 @@ usage if $opt_h;
89 # values associated with keys:
90 # =1 - Arch version / git 'branch' detected via abrowse on a limit
91 # >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;
97
98 $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
99 my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory
108 closedir DIR
109 }
110
111 +my $default_archive; # default Arch archive
112 my %reachable = (); # Arch repositories we can access
113 my %unreachable = (); # Arch repositories we can't access :<
114 my @psets = (); # the collection
@@ -303,7 +308,34 @@ sub old_style_branchname {
308 return $ret;
309 }
310
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 +}
339
340 sub process_patchset_accurate {
341 my $ps = shift;
@@ -333,19 +365,23 @@ sub process_patchset_accurate {
365 if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
366
367 # 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 +
382 # remove any old stuff that got leftover:
383 my $rm = safe_pipe_capture('git-ls-files','--others','-z');
384 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";
385 return 0;
386 } else {
387 warn "Tagging from unknown id unsupported\n" if $ps->{tag};
@@ -385,14 +421,19 @@ sub process_patchset_fast {
421 unless $branchpoint;
422
423 # 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";
437 return 0;
438 }
439 die $! if $?;
@@ -830,8 +871,9 @@ sub tag {
871 if ($opt_o) {
872 $tag =~ s|/|--|g;
873 } 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;
877 }
878
879 if ($commit) {