Commit | Line | Data |
1a95a0fc |
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 |
7 | |
8 | my $num = 1; |
8ff80fc4 |
9 | my $checkout = 0; |
1a95a0fc |
10 | |
f3b6b452 |
11 | my $before = '--before=2008-12-18'; # only changes made under perforce |
12 | |
1a95a0fc |
13 | for (@ARGV) { |
14 | m{^\d+$} && (($change,$_) = ($_,undef)); |
15 | m{^-\d+$} && (($num,$_) = (-$_,undef)); |
8ff80fc4 |
16 | $_ eq '-c' || $_ eq '--checkout' |
17 | and $checkout = 1; |
1a95a0fc |
18 | } |
19 | |
20 | my $grep = "--grep=^p4raw-id:.*\@$change\$"; |
21 | @ARGV = grep { defined } @ARGV; |
22 | |
8ff80fc4 |
23 | if ($checkout) { |
f3b6b452 |
24 | my $commit = qx(git rev-list -1 --all $before '$grep'); |
8ff80fc4 |
25 | chomp $commit; |
26 | die "no commit found" unless $commit; |
27 | system(git => checkout => $commit); |
1a95a0fc |
28 | } |
29 | else { |
8ff80fc4 |
30 | if ( -t STDOUT or @ARGV ) { |
f3b6b452 |
31 | system(qw(git log), $grep, "-$num", "--all", $before, @ARGV); |
8ff80fc4 |
32 | } |
33 | else { |
f3b6b452 |
34 | system(qw(git rev-list -1 --all), $before, $grep); |
8ff80fc4 |
35 | } |
1a95a0fc |
36 | } |