Porting: add a little script to find a perforce change
Sam Vilain [Mon, 16 Jun 2008 11:02:43 +0000 (23:02 +1200)]
Requested by Nicholas Clark

Porting/git-find-p4-change [new file with mode: 0755]

diff --git a/Porting/git-find-p4-change b/Porting/git-find-p4-change
new file mode 100755 (executable)
index 0000000..b777953
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+die "usage: $0 [git-log-options] num" unless @ARGV;
+
+my $num = 1;
+
+for (@ARGV) {
+       m{^\d+$} && (($change,$_) = ($_,undef));
+       m{^-\d+$} && (($num,$_) = (-$_,undef));
+}
+
+my $grep = "--grep=^p4raw-id:.*\@$change\$";
+@ARGV = grep { defined } @ARGV;
+
+if ( -t STDOUT or @ARGV ) {
+       system(qw(git log), $grep, "-$num", "--all", @ARGV);
+}
+else {
+       system(qw(git rev-list -1 --all), $grep);
+}