forked from pflanze/chj-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcj-git-ancestor-sort
executable file
·56 lines (43 loc) · 1.05 KB
/
cj-git-ancestor-sort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl -w
# Mon Jul 22 21:20:05 BST 2013
(my $email='XXX%YYY,ch')=~ tr/%,/@./;
use strict;
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname
Sorts the commits given on stdin according to their ancestor
history: oldest are sorted to the bottom, newest to the top.
(Christian Jaeger <$email>)
";
exit (@_ ? 1 : 0);
}
use Getopt::Long;
our $verbose=0;
#our $opt_dry;
GetOptions("verbose"=> \$verbose,
"help"=> sub{usage},
#"dry-run"=> \$opt_dry,
) or exit 1;
use Memoize;
use Chj::Git::Functions 'is_ancestor_of';
memoize('is_ancestor_of');
our @ids;
while (<STDIN>) {
chomp $_;
push @ids, $_
}
close STDIN or die $!;
our @s= sort {
my $f = is_ancestor_of($a,$b);
my $r = is_ancestor_of($b,$a);
($f and $r) ? 0 : $f ? 1 : $r ? -1 : die "no ancestorship between '$a' and '$b'";
} @ids;
# XX 'ancestorship'?
for (@s) {
print $_,"\n" or die $!;
}
close STDOUT or die $!;
#use Chj::ruse;
#use Chj::Backtrace; use Chj::repl; repl;