Advertisement
tangent

label-forks script for Fossil

Jul 11th, 2019
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.50 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4.  
  5. use Carp;
  6.  
  7. my $lfi = 'label-forks-index.txt';
  8. my $repo = glob('~/museum/repo.fossil')[0];
  9. chdir glob('~/src/repo')[0];    # working tree
  10.  
  11. my $index = 1;
  12. if (open my $i, '<', $lfi) {
  13.     $index = <$i>;
  14.     chomp $index;
  15.     close $i;
  16. }
  17.  
  18. open my $fbr, '-|', 'fossil branch'
  19.         or die "Branch listing failed: $!\n";
  20. my @branches = <$fbr>;
  21. close $fbr;
  22. for my $branch (@branches) {
  23.     chomp $branch;
  24.     $branch = substr($branch, 3);  # strip leading spaces & *
  25.  
  26.     unless (-d $branch) {
  27.         mkdir $branch;
  28.         system("cd $branch ; fossil open $repo $branch");
  29.     }
  30.  
  31.     chdir $branch;
  32.  
  33.     open my $up, '-|', 'fossil update'
  34.             or croak "Failed to run fossil update: $!";
  35.     my @upout = <$up>;
  36.     close $up;
  37.  
  38.     my $forked = 0;
  39.     while (@upout) {
  40.         if (index($_, 'multiple open leaf check-ins') >= 0) {
  41.             $forked = 1;
  42.         }
  43.         elsif ($forked) {
  44.             my ($ckid) = m{
  45.                 \s                  # leading space
  46.                 ([0-9a-f]{40,64})   # SHA-1 or SHA3-256 hash
  47.                 \s                  # trailing space
  48.             }x;
  49.             if (defined $ckid and (++$forked > 2)) {
  50.                 system("fossil amend $ckid --branch 'FORK#$index'");
  51.                 ++$index;
  52.             }
  53.         }
  54.     }
  55.  
  56.     chdir('..');
  57. }
  58.  
  59. if (open my $i, '>', $lfi) {
  60.     print $i $index, "\n";
  61.     close $i;
  62. }
  63. else {
  64.     die "Couldn't save index: $!\n";
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement