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