X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Porting%2Fgit-find-p4-change;h=55bcbb8b99752fd08498bf1792008d9e6812b938;hb=e7deb4af6a1bddab29db10b779d229aec81737e3;hp=ba1a0b76cf30ef61c89ca926843e15001e6dc2cb;hpb=a7d002a11216fa10d2d93aff87fec9eea46a32ff;p=p5sagit%2Fp5-mst-13.2.git diff --git a/Porting/git-find-p4-change b/Porting/git-find-p4-change index ba1a0b7..55bcbb8 100755 --- a/Porting/git-find-p4-change +++ b/Porting/git-find-p4-change @@ -1,22 +1,34 @@ #!/usr/bin/perl # given a perforce change number, output the equivalent git commit id +# with -c, checks out the specified commit -die "usage: $0 [git-log-options] num" unless @ARGV; +die "usage: $0 [-c|--checkout] [git-log-options] changenum" unless @ARGV; my $num = 1; +my $checkout = 0; for (@ARGV) { m{^\d+$} && (($change,$_) = ($_,undef)); m{^-\d+$} && (($num,$_) = (-$_,undef)); + $_ eq '-c' || $_ eq '--checkout' + and $checkout = 1; } my $grep = "--grep=^p4raw-id:.*\@$change\$"; @ARGV = grep { defined } @ARGV; -if ( -t STDOUT or @ARGV ) { - system(qw(git log), $grep, "-$num", "--all", @ARGV); +if ($checkout) { + my $commit = qx(git rev-list -1 --all '$grep'); + chomp $commit; + die "no commit found" unless $commit; + system(git => checkout => $commit); } else { + if ( -t STDOUT or @ARGV ) { + system(qw(git log), $grep, "-$num", "--all", @ARGV); + } + else { system(qw(git rev-list -1 --all), $grep); + } }