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