summaryrefslogtreecommitdiffstats
path: root/bin/git/git-treehash
blob: 8b2d1a4d1944e32f7fd37e4620d75508a615f0ac (plain) (blame)
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
#!/usr/bin/perl

my %opt;
use Getopt::Std;
getopts("q", \%opt);

@ARGV = qw(HEAD ORIG_HEAD) unless @ARGV;

for my $rev (@ARGV) {
  chomp(my $res = qx{git rev-parse $rev^{tree}});
  if ($?) { $BAD++ }
  else { push @{$hash{$res}}, $rev }
}

exit 2 if $BAD;
if (keys(%hash) == 1) {
  my ($res) = keys %hash;
  print "$res\n" unless $opt{"q"};
  exit 0;
} else {
  unless ($opt{"q"}) {
    for my $res (keys %hash) {
      print $res, " ", join(" ", @{$hash{$res}}), "\n";
    }
  }
  exit 1;
}