blob: d3bdb0bd70de67b416ccce011fbc7097f6ec64af (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/perl -w
my $file = pop(@ARGV);
my %meta;
$ENV{'P4PORT'} = 'bactrian:1667';
$ENV{'P4CLIENT'} = 'ni-s';
open(FILE,$file) || die "Cannot open $file:$!";
while (<FILE>)
{
if (/^(From|Subject|Date|Message-ID):(.*)$/i)
{
$meta{lc($1)} = $2;
}
}
my @results = `patch @ARGV <$file 2>&1`;
warn @results;
my $code = $?;
warn "$code from patch\n";
foreach (@results)
{
if (/patching\s+file\s*(.*?)\s*$/)
{
push(@edit,$1);
}
}
my @have = `p4 have @edit`;
if ($code == 0)
{
System("p4 edit @edit");
open(PIPE,"|p4 change -i") || die "Cannot open pipe to p4:$!";
print PIPE "Change: new\n";
print PIPE "Description:\n";
foreach my $key (qw(Subject From Date Message-Id))
{
if (exists $meta{lc($key)})
{
print PIPE "\t$key: ",$meta{lc($key)},"\n";
print "$key: ",$meta{lc($key)},"\n";
}
}
print PIPE "Files:\n";
foreach (@have)
{
if (m,^(.*)#,)
{
print PIPE "\t$1\n"
}
}
close(PIPE);
}
else
{
if (@edit)
{
System("p4 refresh @edit");
}
}
sub System
{
my $cmd = join(' ',@_);
warn "$cmd\n";
if (fork)
{
wait;
}
else
{
_exit(exec $cmd);
}
}
|