On Tue, Apr 08, 2008 at 01:45:30PM +1000, Anthony Towns wrote:
> FWIW, attached is something that'll take a directory of changesets
> (".") and either die with an error if there's a problem, or print out
> the order they should be applied in.

*sigh*

Cheers,
aj


#!/usr/bin/perl -w

use strict;

my $dir = ".";

my $head = undef;
my %next = ();
my %prev = ();

opendir DIR, "$dir" or die "can't opendir $dir";
while (my $chset = readdir DIR) {
        next if ($chset eq "." || $chset eq "..");

        my $path = "$dir/$chset";
        next if (! -r $path);

        open CHSET, "< $path" or die "can't open $path";
        while(<CHSET>) {
                chomp;
                next unless /^Prev-Changeset:\s*(\S.*)$/;

                my $p = $1;
                $prev{$chset} = $p;
                if (defined $next{$p}) {
                        die "branch: $p -> $chset and $next{$p}";
                }
                $next{$p} = $chset;
                last;
        }
        if (not defined $prev{$chset}) {
                if (defined $head) {
                        die "multipled heads: $chset, $head\n";
                }
                $head = $chset;
        }
        close CHSET;
}

my @res = ($head);
for (my $c = $head; defined $next{$c}; $c = $next{$c}) {
        push @res, $next{$c};
}
if (scalar(@res) lt scalar(keys %prev)) {
        die "some changesets in a loop";
}
print join(",", @res)."\n";

Attachment: signature.asc
Description: Digital signature

Reply via email to