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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/usr/bin/perl -w
#
# $FreeBSD$
use strict;
use lib $ENV{CVSROOT};
use CVSROOT::cfg;
my $CVSROOT = $ENV{'CVSROOT'} || die "Can't determine \$CVSROOT!";
my $debug = $cfg::DEBUG;
my $BASE_FN = "$cfg::TMPDIR/$cfg::FILE_PREFIX";
my $FILES_FILE = "$BASE_FN.files";
print "$$: pgrp: ", getpgrp(), "\n" if ($debug);
print "$$: committer: ", $cfg::COMMITTER, "\n" if ($debug);
foreach (@ARGV) {
print "$$: args: $_\n" if ($debug);
}
my $logfile = $ARGV[0];
my $log = "";
if (-r $logfile) {
open(H, "<$logfile") or die;
foreach (<H>) {
print "$$: log: $_" if ($debug);
$log .= $_;
}
close(H);
}
if (-r $FILES_FILE and open(FILES, $FILES_FILE)) {
my %tag;
while (<FILES>) {
chomp;
my ($tag, $file) = split(/\t/, $_, 2);
print "$$: files_file: tag=$tag, file=$file\n" if ($debug);
push @{$tag{$tag}}, $file;
}
close(FILES);
if (check_approvers($log, %tag)) {
unlink $FILES_FILE;
exit 1;
}
}
exit 0;
# ============================================================
sub read_approvers {
my @Approvers;
my $approvers = "$CVSROOT/CVSROOT/approvers";
if (-r $approvers) {
print "$$: Read $approvers\n" if ($debug);
open(APP, "<$approvers") or return;
while (<APP>) {
chomp;
next if (/^#/);
my ($mod, $tag, $rev) = split(/\t+/, $_, 3);
if ($rev) {
push @Approvers, { mod => $mod,
tag => $tag,
app => $rev };
}
}
close(APP);
}
@Approvers;
}
sub check_approvers {
my ($log, %files) = @_;
my %tag;
my @Approvers = &read_approvers();
foreach my $t (keys %files) {
foreach (@{$files{$t}}) {
$tag{$t}->{$_}++;
}
}
foreach my $r (@Approvers) {
printf "$$: checking: %s, %s, %s\n",
$r->{mod}, $r->{tag}, $r->{app} if ($debug);
foreach my $tag (sort keys %tag) {
foreach my $file (sort keys %{$tag{$tag}}) {
return 1 if (check_one($log, $r, $tag, $file));
}
}
}
0;
}
sub check_one {
my ($log, $r, $tag, $file) = @_;
if ($file !~ m|$r->{mod}|) {
printf "$$: file not matched (%s, %s)\n", $file, $r->{mod}
if ($debug);
return 0;
}
printf "$$: file matched (%s, %s)\n", $file, $r->{mod} if ($debug);
if ($tag !~ m|$r->{tag}|) {
printf "$$: tag not matched (%s, %s)\n",
$tag, $r->{tag} if ($debug);
return 0;
}
printf "$$: tag matched (%s, %s)\n", $tag, $r->{tag} if ($debug);
if ($log =~ m|Approved by:[\t ]*$r->{app}|s) {
printf "$$: log matched (%s, %s)\n", $log, $r->{app}
if ($debug);
return 0;
}
printf "$$: log not matched (%s, %s)\n", $log, $r->{app} if ($debug);
printf "**** You need \"Approved by: %s\" line in your log entry.\n",
$r->{app};
return 1;
}
|