File: git-find-p4-change

package info (click to toggle)
perl 5.24.1-3+deb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,716 kB
  • sloc: perl: 559,611; ansic: 293,886; sh: 67,316; pascal: 7,632; cpp: 3,895; makefile: 2,436; xml: 2,410; yacc: 989; sed: 6; lisp: 1
file content (36 lines) | stat: -rw-r--r-- 905 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 [-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 ($checkout) {
    my $commit = qx(git rev-list -1 --all $before '$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", $before, @ARGV);
    }
    else {
	system(qw(git rev-list -1 --all), $before, $grep);
    }
}