1 #!/usr/bin/perl -wpi.bak
4 # Munge "p4 describe ..." output to include new files.
6 # Gurusamy Sarathy <gsar@activestate.com>
9 use vars qw($thisfile $change $file $fnum $h $v $p4port @addfiles
14 $p4port = $ENV{P4PORT} || 'localhost:1666';
16 if ($p4port =~ /^\s+$/) {
35 unless (@files) { @files = '-'; undef $^I; }
37 $branches = '//depot/perl/' unless defined $branches;
40 Usage: $0 [-p \$P4PORT] [-v] [-h] [files]
42 -phost:port p4 port (e.g. myhost:1666)
44 -v output progress messages
45 -bbranch(es) which branches to include (regex)
46 (default: //depot/perl/)
49 A smart 'cat'. When fed the spew from "p4 describe ..." on STDIN,
50 spits it right out on STDOUT, followed by patches for any new files
51 detected in the spew. Can also be used to edit insitu a bunch of
52 files containing said spew.
54 WARNING 1: Currently only emits unified diffs (diff -u).
56 WARNING 2: By default only the changes in the //depot/perl branch
57 are shown. To include all the branches, supply "-b." arguments
61 p4 describe -du 123 | $0 > change-123.desc
62 p4 describe -du 123 | $0 | p4d2p > change-123.patch
71 if ($ARGV ne $thisfile) {
72 warn "processing patchfile [$ARGV]\n" unless $ARGV eq '-';
76 my $cur = m|^Affected files| ... m|^Differences|;
78 # while we are within range
82 if (m{^\.\.\. (//depot/.+?\#\d+) (add|branch)$}) {
84 push @addfiles, $newfile;
85 warn "$newfile add, revision != 1!\n" unless $newfile =~ /#1$/;
91 warn "file [$file] line [$cur] file# [$fnum]\n" if $v;
94 if (m|^==== //depot/|) {
95 $skip = !m|$branches|;
100 if (/^Change (\d+) by/) {
101 $_ = "\n\n" . $_ if $change; # start of a new change list
103 my $new = newfiles();
116 for $addfile (@addfiles) {
117 my $type = `p4 -p $p4port files '$addfile'`;
119 warn "$0: `p4 -p $p4port print '$addfile'` failed, status[$?]\n";
122 $type =~ m|^//.*\((.+)\)$| or next;
124 unless ($type =~ /text/) {
125 $ret .= "\n==== $addfile ($type) ====\n\n";
128 my @new = `p4 -p $p4port print '$addfile'`;
130 die "$0: `p4 -p $p4port print '$addfile'` failed, status[$?]\n";
132 my $desc = shift @new; # discard initial description
133 $ret .= "\n==== $addfile ($type) ====\n\n";
134 my $lines = "," . @new;
135 $lines = "" if @new < 2;
136 $ret .= "\@\@ -0,0 +1$lines \@\@\n";
137 $ret .= join("+","",@new);
138 $ret .= "\n\\ No newline at end of file\n" if $ret !~ /\n$/;