Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement