1#!/usr/bin/perl -w 2my $file = pop(@ARGV); 3my %meta; 4$ENV{'P4PORT'} ||= 'bactrian:1667'; 5$ENV{'P4CLIENT'} ||= 'ni-s'; 6open(FILE,$file) || die "Cannot open $file:$!"; 7while (<FILE>) 8 { 9 if (/^(From|Subject|Date|Message-ID):(.*)$/i) 10 { 11 $meta{lc($1)} = $2; 12 } 13 } 14my @results = `patch @ARGV <$file 2>&1`; 15warn @results; 16my $code = $?; 17warn "$code from patch\n"; 18foreach (@results) 19 { 20 if (/[Pp]atching\s+file\s*(\S+)/) 21 { 22 push(@edit,$1); 23 } 24 } 25my @have = `p4 have @edit`; 26 27if ($code == 0) 28 { 29 System("p4 edit @edit"); 30 open(PIPE,"|p4 change -i") || die "Cannot open pipe to p4:$!"; 31 print PIPE "Change: new\n"; 32 print PIPE "Description:\n"; 33 foreach my $key (qw(Subject From Date Message-Id)) 34 { 35 if (exists $meta{lc($key)}) 36 { 37 print PIPE "\t$key: ",$meta{lc($key)},"\n"; 38 print "$key: ",$meta{lc($key)},"\n"; 39 } 40 } 41 print PIPE "Files:\n"; 42 foreach (@have) 43 { 44 if (m,^(.*)#,) 45 { 46 print PIPE "\t$1\n" 47 } 48 } 49 close(PIPE); 50 } 51else 52 { 53 if (@edit) 54 { 55 System("p4 refresh @edit"); 56 } 57 } 58 59sub System 60{ 61 my $cmd = join(' ',@_); 62 warn "$cmd\n"; 63 if (fork) 64 { 65 wait; 66 } 67 else 68 { 69 _exit(exec $cmd); 70 } 71} 72 73