From: Rafael Garcia-Suarez Date: Tue, 6 Jan 2009 08:59:35 +0000 (+0100) Subject: Add a --checkout / -c flag to git-find-p4-change X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8ff80fc4c8e0f0cb22397f72417eafe1cf3e2c64;p=p5sagit%2Fp5-mst-13.2.git Add a --checkout / -c flag to git-find-p4-change Remove the now obsolete switch_to_perforce_id.pl --- diff --git a/MANIFEST b/MANIFEST index fe68438..075532c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3532,7 +3532,6 @@ Porting/pumpkin.pod Guidelines and hints for Perl maintainers 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 diff --git a/Porting/git-find-p4-change b/Porting/git-find-p4-change index ba1a0b7..55bcbb8 100755 --- a/Porting/git-find-p4-change +++ b/Porting/git-find-p4-change @@ -1,22 +1,34 @@ #!/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); + } } diff --git a/Porting/switch_to_perforce_id.pl b/Porting/switch_to_perforce_id.pl deleted file mode 100755 index fb3611d..0000000 --- a/Porting/switch_to_perforce_id.pl +++ /dev/null @@ -1,26 +0,0 @@ -#!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";