1 #!/l/local/bin/perl -wpi.bak
4 # Munge "p4 describe ..." output to include new files.
6 # Gurusamy Sarathy <gsar@umich.edu>
9 use vars qw($thisfile $change $file $fnum $h $v $p4port @addfiles);
13 $p4port = $ENV{P4PORT} || 'localhost:1666';
15 if ($p4port =~ /^\s+$/) {
31 unless (@files) { @files = '-'; undef $^I; }
35 Usage: $0 [-p \$P4PORT] [-v] [-h] [files]
37 -p host:port p4 port (e.g. myhost:1666)
39 -v output progress messages
41 A smart 'cat'. When fed the spew from "p4 describe ..." on STDIN,
42 spits it right out on STDOUT, followed by patches for any new files
43 detected in the spew. Can also be used to edit insitu a bunch of
44 files containing said spew.
46 WARNING: Currently only emits unified diffs.
49 p4 describe -du 123 | $0 > change-123.desc
50 p4 describe -du 123 | $0 | p4d2p > change-123.patch
59 if ($ARGV ne $thisfile) {
60 warn "processing patchfile [$ARGV]\n" unless $ARGV eq '-';
64 my $cur = m|^Affected files| ... m|^Differences|;
66 # while we are within range
68 if (m|^\.\.\. (//depot/.+?#\d+) add$|) {
70 push @addfiles, $newfile;
71 warn "$newfile add, revision != 1!\n" unless $newfile =~ /#1$/;
73 warn "file [$file] line [$cur] file# [$fnum]\n" if $v;
76 if (/^Change (\d+) by/) {
77 $_ = "\n\n" . $_ if $change; # start of a new change list
92 for $addfile (@addfiles) {
93 my @new = `p4 -p $p4port print $addfile`;
95 die "$0: `p4 -p $p4port print $addfile` failed, status[$?]\n";
97 my $desc = shift @new; # discard initial description
98 $ret .= "\n==== $addfile (text) ====\n\n";
99 my $lines = "," . @new;
100 $lines = "" if @new < 2;
101 $ret .= "\@\@ -0,0 +1$lines \@\@\n";
102 $ret .= join("+","",@new);