|
89 | 89 | # values associated with keys: |
90 | 90 | # =1 - Arch version / git 'branch' detected via abrowse on a limit |
91 | 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; |
93 | 97 |
|
94 | 98 | $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls: |
95 | 99 | my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1); |
|
104 | 108 | closedir DIR |
105 | 109 | } |
106 | 110 |
|
| 111 | +my $default_archive; # default Arch archive |
107 | 112 | my %reachable = (); # Arch repositories we can access |
108 | 113 | my %unreachable = (); # Arch repositories we can't access :< |
109 | 114 | my @psets = (); # the collection |
@@ -303,7 +308,34 @@ sub old_style_branchname { |
303 | 308 | return $ret; |
304 | 309 | } |
305 | 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 | +} |
307 | 339 |
|
308 | 340 | sub process_patchset_accurate { |
309 | 341 | my $ps = shift; |
@@ -333,19 +365,23 @@ sub process_patchset_accurate { |
333 | 365 | if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) { |
334 | 366 |
|
335 | 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 | + |
339 | 382 | # remove any old stuff that got leftover: |
340 | 383 | my $rm = safe_pipe_capture('git-ls-files','--others','-z'); |
341 | 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"; |
349 | 385 | return 0; |
350 | 386 | } else { |
351 | 387 | warn "Tagging from unknown id unsupported\n" if $ps->{tag}; |
@@ -385,14 +421,19 @@ sub process_patchset_fast { |
385 | 421 | unless $branchpoint; |
386 | 422 |
|
387 | 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"; |
396 | 437 | return 0; |
397 | 438 | } |
398 | 439 | die $! if $?; |
@@ -830,8 +871,9 @@ sub tag { |
830 | 871 | if ($opt_o) { |
831 | 872 | $tag =~ s|/|--|g; |
832 | 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; |
835 | 877 | } |
836 | 878 |
|
837 | 879 | if ($commit) { |
|
0 commit comments