Porting/README.y2038 Perl notes for the 2038 fix
Porting/regcharclass.pl Generate regcharclass.h from inline data
Porting/sort_perldiag.pl Keep our diagnostics orderly
-Porting/switch_to_perforce_id.pl Checkout a given p4 change number
Porting/testall.atom Cumulative profile with Third Degree
Porting/thirdclean Cleanup Third Degree reports
Porting/timecheck2.c Test program for the 2038 fix
#!/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);
+ }
}
+++ /dev/null
-#!perl
-#
-# given a perforce change number, checkout the equivalent git commit
-# into the git working directory
-#
-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|' or 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";