tangent icon

label-forks script for Fossil

tangent | PRO | 07/11/19 11:07:15 AM UTC | 0 ⭐ | 7743 👁️ | Never ⏰ | []
Perl |

1.5 KB

|

None

|

0 👍

/

0 👎

#!/usr/bin/env perl
use strict;
use warnings;
 
use Carp;
 
my $lfi = 'label-forks-index.txt';
my $repo = glob('~/museum/repo.fossil')[0];
chdir glob('~/src/repo')[0];    # working tree
 
my $index = 1;
if (open my $i, '<', $lfi) {
    $index = <$i>;
    chomp $index;
    close $i;
}
 
open my $fbr, '-|', 'fossil branch' 
        or die "Branch listing failed: $!\n";
my @branches = <$fbr>;
close $fbr;
for my $branch (@branches) {
    chomp $branch;
    $branch = substr($branch, 3);  # strip leading spaces & *
 
    unless (-d $branch) {
        mkdir $branch;
        system("cd $branch ; fossil open $repo $branch");
    }
 
    chdir $branch;
 
    open my $up, '-|', 'fossil update'
            or croak "Failed to run fossil update: $!";
    my @upout = <$up>;
    close $up;
 
    my $forked = 0;
    while (@upout) {
        if (index($_, 'multiple open leaf check-ins') >= 0) {
            $forked = 1;
        }
        elsif ($forked) {
            my ($ckid) = m{
                \s                  # leading space
                ([0-9a-f]{40,64})   # SHA-1 or SHA3-256 hash
                \s                  # trailing space
            }x;
            if (defined $ckid and (++$forked > 2)) {
                system("fossil amend $ckid --branch 'FORK#$index'");
                ++$index;
            }
        }
    }
 
    chdir('..');
}
 
if (open my $i, '>', $lfi) {
    print $i $index, "\n";
    close $i;
}
else {
    die "Couldn't save index: $!\n";
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎