Add a program to switch to a Perforce id
Leon Brocard [Sat, 20 Dec 2008 08:42:06 +0000 (08:42 +0000)]
Porting/switch_to_perforce_id.pl [new file with mode: 0755]

diff --git a/Porting/switch_to_perforce_id.pl b/Porting/switch_to_perforce_id.pl
new file mode 100755 (executable)
index 0000000..cf21a13
--- /dev/null
@@ -0,0 +1,22 @@
+#!perl
+use strict;
+use warnings;
+use English;
+
+my $perforce_id = shift;
+die "Usage: switch_to_perforce_id.pl 34440" unless $perforce_id;
+
+open my $fh, 'git log -z --pretty=raw|' || die $!;
+local $INPUT_RECORD_SEPARATOR = "\0";
+
+my $re = qr/p4raw-id:.+\@$perforce_id/;
+
+while ( my $log = <$fh> ) {
+    next unless $log =~ /$re/;
+    my ($commit) = $log =~ /commit ([a-z0-9]+)/;
+    system "git checkout $commit";
+    print "(use git checkout blead to go back)\n";
+    exit;
+}
+
+die "No log found for $perforce_id";