This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
clarify the process for dist/ (blead-first) distributions
[perl5.git] / Porting / git-find-p4-change
old mode 100755 (executable)
new mode 100644 (file)
index ba1a0b7..6363ae2
@@ -1,22 +1,36 @@
 #!/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;
+
+my $before = '--before=2008-12-18'; # only changes made under perforce
 
 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 $before '$grep');
+    chomp $commit;
+    die "no commit found" unless $commit;
+    system(git => checkout => $commit);
 }
 else {
-       system(qw(git rev-list -1 --all), $grep);
+    if ( -t STDOUT or @ARGV ) {
+       system(qw(git log), $grep, "-$num", "--all", $before, @ARGV);
+    }
+    else {
+       system(qw(git rev-list -1 --all), $before, $grep);
+    }
 }