Commit | Line | Data |
---|---|---|
1a95a0fc SV |
1 | #!/usr/bin/perl |
2 | ||
a7d002a1 | 3 | # given a perforce change number, output the equivalent git commit id |
8ff80fc4 | 4 | # with -c, checks out the specified commit |
a7d002a1 | 5 | |
8ff80fc4 | 6 | die "usage: $0 [-c|--checkout] [git-log-options] changenum" unless @ARGV; |
1a95a0fc SV |
7 | |
8 | my $num = 1; | |
8ff80fc4 | 9 | my $checkout = 0; |
1a95a0fc SV |
10 | |
11 | for (@ARGV) { | |
12 | m{^\d+$} && (($change,$_) = ($_,undef)); | |
13 | m{^-\d+$} && (($num,$_) = (-$_,undef)); | |
8ff80fc4 RGS |
14 | $_ eq '-c' || $_ eq '--checkout' |
15 | and $checkout = 1; | |
1a95a0fc SV |
16 | } |
17 | ||
18 | my $grep = "--grep=^p4raw-id:.*\@$change\$"; | |
19 | @ARGV = grep { defined } @ARGV; | |
20 | ||
8ff80fc4 RGS |
21 | if ($checkout) { |
22 | my $commit = qx(git rev-list -1 --all '$grep'); | |
23 | chomp $commit; | |
24 | die "no commit found" unless $commit; | |
25 | system(git => checkout => $commit); | |
1a95a0fc SV |
26 | } |
27 | else { | |
8ff80fc4 RGS |
28 | if ( -t STDOUT or @ARGV ) { |
29 | system(qw(git log), $grep, "-$num", "--all", @ARGV); | |
30 | } | |
31 | else { | |
1a95a0fc | 32 | system(qw(git rev-list -1 --all), $grep); |
8ff80fc4 | 33 | } |
1a95a0fc | 34 | } |