This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a --checkout / -c flag to git-find-p4-change
[perl5.git] / Porting / git-find-p4-change
... / ...
CommitLineData
1#!/usr/bin/perl
2
3# given a perforce change number, output the equivalent git commit id
4# with -c, checks out the specified commit
5
6die "usage: $0 [-c|--checkout] [git-log-options] changenum" unless @ARGV;
7
8my $num = 1;
9my $checkout = 0;
10
11for (@ARGV) {
12 m{^\d+$} && (($change,$_) = ($_,undef));
13 m{^-\d+$} && (($num,$_) = (-$_,undef));
14 $_ eq '-c' || $_ eq '--checkout'
15 and $checkout = 1;
16}
17
18my $grep = "--grep=^p4raw-id:.*\@$change\$";
19@ARGV = grep { defined } @ARGV;
20
21if ($checkout) {
22 my $commit = qx(git rev-list -1 --all '$grep');
23 chomp $commit;
24 die "no commit found" unless $commit;
25 system(git => checkout => $commit);
26}
27else {
28 if ( -t STDOUT or @ARGV ) {
29 system(qw(git log), $grep, "-$num", "--all", @ARGV);
30 }
31 else {
32 system(qw(git rev-list -1 --all), $grep);
33 }
34}