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