Gentoo Archives: gentoo-commits

From: "Robin H. Johnson (robbat2)" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] CVSROOT commit in /: commitlog-infra.pl loginfo
Date: Fri, 21 Sep 2007 03:52:40
Message-Id: E1IYZRS-000894-5w@stork.gentoo.org
1 robbat2 07/09/21 03:44:34
2
3 Modified: loginfo
4 Added: commitlog-infra.pl
5 Log:
6 Special commit mail for gentoo-infra repository.
7
8 Revision Changes Path
9 1.98 loginfo
10
11 file : http://sources.gentoo.org/viewcvs.py/CVSROOT/loginfo?rev=1.98&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/CVSROOT/loginfo?rev=1.98&content-type=text/plain
13 diff : http://sources.gentoo.org/viewcvs.py/CVSROOT/loginfo?r1=1.97&r2=1.98
14
15 Index: loginfo
16 ===================================================================
17 RCS file: /var/cvsroot/CVSROOT/loginfo,v
18 retrieving revision 1.97
19 retrieving revision 1.98
20 diff -u -r1.97 -r1.98
21 --- loginfo 7 Sep 2007 06:48:49 -0000 1.97
22 +++ loginfo 21 Sep 2007 03:44:33 -0000 1.98
23 @@ -53,6 +53,7 @@
24 ^gentoo\/ ( $CVSROOT/CVSROOT/commitlog-portage.pl %p %{s} )
25 ^gentoo$ ( $CVSROOT/CVSROOT/commitlog-portage.pl %p %{s} )
26 ^gentoo-doc ( $CVSROOT/CVSROOT/commitlog-portage.pl %p %{s} )
27 +^gentoo-infra ( $CVSROOT/CVSROOT/commitlog-infra.pl %p %{s} )
28 ^gentoo-gfx ( $CVSROOT/CVSROOT/commitlog-portage.pl %p %{s} )
29 ^gentoo-projects ( $CVSROOT/CVSROOT/commitlog-portage.pl %p %{s} )
30 ^gentoo-src ( $CVSROOT/CVSROOT/commitlog-portage.pl %p %{s} )
31
32
33
34 1.1 commitlog-infra.pl
35
36 file : http://sources.gentoo.org/viewcvs.py/CVSROOT/commitlog-infra.pl?rev=1.1&view=markup
37 plain: http://sources.gentoo.org/viewcvs.py/CVSROOT/commitlog-infra.pl?rev=1.1&content-type=text/plain
38
39 Index: commitlog-infra.pl
40 ===================================================================
41 #!/usr/bin/perl
42 #
43 # Perl filter to handle the log messages from the checkin of files in
44 # a directory. This script will group the lists of files by log
45 # message, and mail a single consolidated log message at the end of
46 # the commit.
47 #
48 # This file assumes a pre-commit checking program that leaves the
49 # names of the first and last commit directories in a temporary file.
50 #
51 # Contributed by David Hampton <hampton@×××××.com>
52 # Roy Fielding removed useless code and added log/mail of new files
53 # Ken Coar added special processing (i.e., no diffs) for binary files
54 #
55
56 ############################################################
57 #
58 # Configurable options
59 #
60 ############################################################
61 #
62 # Where do you want the RCS ID and delta info?
63 # 0 = none,
64 # 1 = in mail only,
65 # 2 = rcsids in both mail and logs.
66 #
67 $rcsidinfo = 1;
68
69 ############################################################
70 #
71 # Constants
72 #
73 ############################################################
74 $STATE_NONE = 0;
75 $STATE_CHANGED = 1;
76 $STATE_ADDED = 2;
77 $STATE_REMOVED = 3;
78 $STATE_LOG = 4;
79
80 $TMPDIR = $ENV{'TMPDIR'} || '/tmp';
81 $FILE_PREFIX = '#cvs.';
82
83 $LAST_FILE = "$TMPDIR/${FILE_PREFIX}lastdir";
84 $CHANGED_FILE = "$TMPDIR/${FILE_PREFIX}files.changed";
85 $ADDED_FILE = "$TMPDIR/${FILE_PREFIX}files.added";
86 $REMOVED_FILE = "$TMPDIR/${FILE_PREFIX}files.removed";
87 $LOG_FILE = "$TMPDIR/${FILE_PREFIX}files.log";
88 $BRANCH_FILE = "$TMPDIR/${FILE_PREFIX}files.branch";
89 $SUMMARY_FILE = "$TMPDIR/${FILE_PREFIX}files.summary";
90
91 $CVSROOT = $ENV{'CVSROOT'};
92
93 $MAIL_TO = 'cfengine@g.o';
94 $CVSWEB = 'http://sources.gentoo.org/viewcvs.py';
95 #$CVSWEBROOT = $1 if $CVSROOT =~ m#/cvsroot/(\S+)#;
96 #$CVSWEBROOT = 'gentoo-x86';
97
98 # Path to your USCD sendmail compatible binary (your mailer daemon created this
99 # program somewhere).
100 $sendmail = '/usr/sbin/sendmail';
101
102 ############################################################
103 #
104 # Subroutines
105 #
106 ############################################################
107
108 sub format_names {
109 local($dir, @files) = @_;
110 local(@lines);
111
112 $lines[0] = sprintf(" %-08s", $dir);
113 foreach $file (@files) {
114 if (length($lines[$#lines]) + length($file) > 60) {
115 $lines[++$#lines] = sprintf(" %8s", " ");
116 }
117 $lines[$#lines] .= " ".$file;
118 }
119 @lines;
120 }
121
122 sub cleanup_tmpfiles {
123 local(@files);
124
125 opendir(DIR, $TMPDIR);
126 push(@files, grep(/^${FILE_PREFIX}.*\.${id}$/, readdir(DIR)));
127 closedir(DIR);
128 foreach (@files) {
129 unlink "$TMPDIR/$_";
130 }
131 }
132
133 sub write_logfile {
134 local($filename, @lines) = @_;
135
136 open(FILE, ">$filename") || die ("Cannot open log file $filename: $!\n");
137 print(FILE join("\n", @lines), "\n");
138 close(FILE);
139 }
140
141 sub append_to_file {
142 local($filename, $dir, @files) = @_;
143
144 if (@files) {
145 local(@lines) = &format_names($dir, @files);
146 open(FILE, ">>$filename") || die ("Cannot open file $filename: $!\n");
147 print(FILE join("\n", @lines), "\n");
148 close(FILE);
149 }
150 }
151
152 sub write_line {
153 local($filename, $line) = @_;
154
155 open(FILE, ">$filename") || die("Cannot open file $filename: $!\n");
156 print(FILE $line, "\n");
157 close(FILE);
158 }
159
160 sub append_line {
161 local($filename, $line) = @_;
162
163 open(FILE, ">>$filename") || die("Cannot open file $filename: $!\n");
164 print(FILE $line, "\n");
165 close(FILE);
166 }
167
168 sub read_line {
169 local($filename) = @_;
170 local($line);
171
172 open(FILE, "<$filename") || die("Cannot open file $filename: $!\n");
173 $line = <FILE>;
174 close(FILE);
175 chomp($line);
176 $line;
177 }
178
179 sub read_file {
180 local($filename, $leader) = @_;
181 local(@text) = ();
182
183 open(FILE, "<$filename") || return ();
184 while (<FILE>) {
185 chomp;
186 push(@text, sprintf(" %-10s %s", $leader, $_));
187 $leader = "";
188 }
189 close(FILE);
190 @text;
191 }
192
193 sub read_logfile {
194 local($filename, $leader) = @_;
195 local(@text) = ();
196
197 open(FILE, "<$filename") || die ("Cannot open log file $filename: $!\n");
198 while (<FILE>) {
199 chomp;
200 push(@text, $leader.$_);
201 }
202 close(FILE);
203 @text;
204 }
205
206 #
207 # do an 'cvs -Qn status' on each file in the arguments, and extract info.
208 #
209 sub change_summary {
210 local($out, @filenames) = @_;
211 local(@revline);
212 local($file, $rev, $rcsfile, $line);
213
214 while (@filenames) {
215 $file = shift @filenames;
216
217 if ("$file" eq "") {
218 next;
219 }
220
221 open(RCS, "-|") || exec 'cvs', '-Qn', 'status', $file;
222
223 $rev = "";
224 $delta = "";
225 $rcsfile = "";
226 $module = "";
227
228 while (<RCS>) {
229 if (/^[ \t]*Repository revision/) {
230 chomp;
231 @revline = split(' ', $_);
232 $rev = $revline[2];
233 $rcsfile = $revline[3];
234 #print "DEBUG: rcsfile1 ='$rcsfile'\n";
235 $rcsfile =~ s,^$CVSROOT/,,;
236 #print "DEBUG: rcsfile2 ='$rcsfile'\n";
237 #$rcsfile =~ s,^$CVSWEBROOT/,,;
238 #print "DEBUG: rcsfile3 ='$rcsfile'\n";
239 $rcsfile =~ s/,v$//;
240 #print "DEBUG: rcsfile4 ='$rcsfile'\n";
241 ($module,$rcsfile) = split /\//,$rcsfile,2;
242 }
243 }
244 close(RCS);
245
246
247 if ($rev ne '' && $rcsfile ne '') {
248 open(RCS, "-|") || exec 'cvs', '-Qn', 'log', "-r$rev", $file;
249 while (<RCS>) {
250 if (/^date:/) {
251 chomp;
252 $delta = $_;
253 $delta =~ s/^.*;//;
254 $delta =~ s/^[\s]+lines://;
255 }
256 }
257 close(RCS);
258 }
259
260 $diff = "\n\n";
261
262 #
263 # If this is a binary file, don't try to report a diff; not only is
264 # it meaningless, but it also screws up some mailers. We rely on
265 # Perl's 'is this binary' algorithm; it's pretty good. But not
266 # perfect.
267 #
268 if (($file =~ /\.(?:pdf|gif|jpg|mpg)$/i) || (-B $file)) {
269 $diff .= "\t<<Binary file>>\n\n";
270 }
271 else {
272 #
273 # Get the differences between this and the previous revision,
274 # being aware that new files always have revision '1.1' and
275 # new branches always end in '.n.1'.
276 #
277 if ($rev =~ /^(.*)\.([0-9]+)$/) {
278 $prev = $2 - 1;
279 $prev_rev = $1 . '.' . $prev;
280
281 $prev_rev =~ s/\.[0-9]+\.0$//;# Truncate if first rev on branch
282
283 if ($rev eq '1.1') {
284 $diff .= "file : $CVSWEB/$module/$rcsfile?rev=$rev&view=markup\n";
285 $diff .= "plain: $CVSWEB/$module/$rcsfile?rev=$rev&content-type=text/plain\n\n";
286 open(DIFF, "-|")
287 || exec 'cvs', '-Qn', 'update', '-p', '-r1.1', $file;
288 $diff .= "Index: $file\n=================================="
289 . "=================================\n";
290 }
291 else {
292 $diff .= "file : $CVSWEB/$module/$rcsfile?rev=$rev&view=markup\n";
293 $diff .= "plain: $CVSWEB/$module/$rcsfile?rev=$rev&content-type=text/plain\n";
294 $diff .= "diff : $CVSWEB/$module/$rcsfile?r1=$prev_rev&r2=$rev\n\n";
295
296 open(DIFF, "-|")
297 || exec 'cvs', '-Qn', 'diff', '-u',
298 "-r$prev_rev", "-r$rev", $file;
299 }
300
301 while ($_ = <DIFF>) {
302 $diff .= $_;
303 }
304
305 close(DIFF);
306 $diff .= "\n\n";
307 }
308 }
309
310 &append_line($out, sprintf("%-9s%-12s%s%s", $rev, $delta,
311 $rcsfile, $diff));
312 }
313 }
314
315
316 sub build_header {
317 local($header);
318 delete $ENV{'TZ'};
319 local($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
320
321 $header = sprintf("%-8s %02d/%02d/%02d %02d:%02d:%02d",
322 $login, $year%100, $mon+1, $mday,
323 $hour, $min, $sec);
324 }
325
326 sub do_changes_file
327 {
328 local($category, @text) = @_;
329 local($changes);
330
331 $changes = "$CVSROOT/CVSROOT/commitlogs/$category";
332
333 if (open(CHANGES, ">>$changes")) {
334 print(CHANGES join("\n", @text), "\n\n");
335 close(CHANGES);
336 }
337 else {
338 warn "Cannot open $changes: $!\n";
339 }
340 }
341
342 sub mail_notification
343 {
344 local(@text) = @_;
345
346 @files = @ARGV;
347 $path = shift @files;
348
349 unless ( $files[0] =~ /(Manifest|digest-|userinfo.xml)/i ) {
350 print "Mailing the commit message...\n";
351
352 @repository_path = split /\//, $path, 2;
353 $repository = $repository_path[0];
354 $path = $repository_path[1] || '/';
355
356
357 # Build an exact array of headers we are adding to the email
358 my @headers = (
359 "From: \"$gecos ($login)\" <$login\@gentoo.org>",
360 "To: $MAIL_TO",
361 "Subject: $repository commit in $path: @files",
362 "X-VCS-Repository: $repository",
363 "X-VCS-Files: @files",
364 "X-VCS-Directories: $path",
365 "X-VCS-Committer: $login",
366 "X-VCS-Committer-Name: $gecos",
367 #"X-VCS-MagicString: DopefviWelcagheavOakwobyichWudrupGocMujDajlujGhad9",
368 "Content-Type: text/plain; charset=utf8",
369 "Content-Transfer-Encoding: 8bit",
370 );
371 my $cmd = "$sendmail -t -oi -oem -f$login\@gentoo.org";
372
373 #print "DEBUG: before mailing...\n";
374 #use Data::Dumper;
375 #print "DEBUG: environment:\n".Dumper(%ENV);
376 #print "DEBUG: $cmd\n";
377
378 open(MAIL, "| $cmd") or die "Failed to open mail pipe: $!";
379 #print "DEBUG: open...\n";
380 print(MAIL join("\n", @headers)) or die "Failed to write header to mail pipe: $!";
381 # seperates the headers from the body
382 print(MAIL "\n\n");
383 print(MAIL join("\n", @text)) or die "Failed to write body to mail pipe: $!";
384 #print "DEBUG: pipe...\n";
385 close(MAIL) or die "Failed to close mail pipe: $? - $!";
386 #print "DEBUG: close...\n";
387 }
388
389 }
390
391 #############################################################
392 #
393 # Main Body
394 #
395 ############################################################
396 #
397 # Setup environment
398 #
399 umask (002);
400 $SIG{PIPE} = 'IGNORE';
401
402 #
403 # Initialize basic variables
404 #
405 $id = getpgrp();
406 $state = $STATE_NONE;
407 $login = $ENV{'USER'} || getlogin || (getpwuid($<))[0] || sprintf("uid#%d",$<);
408 $gecos = (getpwuid($<))[6] || "gecos missing";
409 @files = @ARGV;
410 @path = shift @files;
411 $repository = $ARGV[0];
412 #if ($#path == 0) {
413 # $dir = ".";
414 #} else {
415 # $dir = join('/', @path[1..$#path]);
416 #}
417 #print("ARGV - ", join(":", @ARGV), "\n");
418 #print("files - ", join(":", @files), "\n");
419 #print("path - ", join(":", @path), "\n");
420 #print("dir - ", $dir, "\n");
421 #print("id - ", $id, "\n");
422
423 ##########################
424 # Uncomment the following if we ever have per-repository cvs mail
425
426 ##########################
427 #
428 # Check for a new directory first. This will always appear as a
429 # single item in the argument list, and an empty log message.
430 #
431 #if ($ARGV[0] =~ /New directory/) {
432 # $header = &build_header;
433 # @text = ();
434 # push(@text, $header);
435 # push(@text, "");
436 # push(@text, " ".$ARGV[0]);
437 # &do_changes_file($mlist, @text);
438 # &mail_notification(@text) if defined($MAIL_TO);
439 # exit 0;
440 #}
441
442 #
443 # Iterate over the body of the message collecting information.
444 #
445 while (<STDIN>) {
446 chomp; # Drop the newline
447 if (/^Revision\/Branch:/) {
448 s,^Revision/Branch:,,;
449 push (@branch_lines, split);
450 next;
451 }
452 # next if (/^[ \t]+Tag:/ && $state != $STATE_LOG);
453 if (/^Modified Files/) { $state = $STATE_CHANGED; next; }
454 if (/^Added Files/) { $state = $STATE_ADDED; next; }
455 if (/^Removed Files/) { $state = $STATE_REMOVED; next; }
456 if (/^Log Message/) { $state = $STATE_LOG; next; }
457 s/[ \t\n]+$//; # delete trailing space
458
459 push (@changed_files, split) if ($state == $STATE_CHANGED);
460 push (@added_files, split) if ($state == $STATE_ADDED);
461 push (@removed_files, split) if ($state == $STATE_REMOVED);
462 if ($state == $STATE_LOG) {
463 if (/^PR:$/i ||
464 /^Reviewed by:$/i ||
465 /^Submitted by:$/i ||
466 /^Obtained from:$/i) {
467 next;
468 }
469 push (@log_lines, $_);
470 }
471 }
472
473 #
474 # Strip leading and trailing blank lines from the log message. Also
475 # compress multiple blank lines in the body of the message down to a
476 # single blank line.
477 # (Note, this only does the mail and changes log, not the rcs log).
478 #
479 while ($#log_lines > -1) {
480 last if ($log_lines[0] ne "");
481 shift(@log_lines);
482 }
483 while ($#log_lines > -1) {
484 last if ($log_lines[$#log_lines] ne "");
485 pop(@log_lines);
486 }
487 for ($i = $#log_lines; $i > 0; $i--) {
488 if (($log_lines[$i - 1] eq "") && ($log_lines[$i] eq "")) {
489 splice(@log_lines, $i, 1);
490 }
491 }
492
493 #
494 # Find the log file that matches this log message
495 #
496 for ($i = 0; ; $i++) {
497 last if (! -e "$LOG_FILE.$i.$id");
498 @text = &read_logfile("$LOG_FILE.$i.$id", "");
499 last if ($#text == -1);
500 last if (join(" ", @log_lines) eq join(" ", @text));
501 }
502
503 #
504 # Spit out the information gathered in this pass.
505 #
506 &write_logfile("$LOG_FILE.$i.$id", @log_lines);
507 &append_to_file("$BRANCH_FILE.$i.$id", $dir, @branch_lines);
508 &append_to_file("$ADDED_FILE.$i.$id", $dir, @added_files);
509 &append_to_file("$CHANGED_FILE.$i.$id", $dir, @changed_files);
510 &append_to_file("$REMOVED_FILE.$i.$id", $dir, @removed_files);
511 if ($rcsidinfo) {
512 &change_summary("$SUMMARY_FILE.$i.$id", (@changed_files, @added_files));
513 }
514
515 #
516 # Check whether this is the last directory. If not, quit.
517 #
518 if (-e "$LAST_FILE.$id") {
519 $_ = &read_line("$LAST_FILE.$id");
520 $tmpfiles = $files[0];
521 $tmpfiles =~ s,([^a-zA-Z0-9_/]),\\$1,g;
522 if (! grep(/$tmpfiles$/, $_)) {
523 print "More commits to come...\n";
524 exit 0
525 }
526 }
527
528 #
529 # This is it. The commits are all finished. Lump everything together
530 # into a single message, fire a copy off to the mailing list, and drop
531 # it on the end of the Changes file.
532 #
533 $header = &build_header;
534
535 #
536 # Produce the final compilation of the log messages
537 #
538 @text = ();
539 push(@text, $header);
540 push(@text, "");
541 for ($i = 0; ; $i++) {
542 last if (! -e "$LOG_FILE.$i.$id");
543 push(@text, &read_file("$BRANCH_FILE.$i.$id", "Branch:"));
544 push(@text, &read_file("$CHANGED_FILE.$i.$id", "Modified:"));
545 push(@text, &read_file("$ADDED_FILE.$i.$id", "Added:"));
546 push(@text, &read_file("$REMOVED_FILE.$i.$id", "Removed:"));
547 push(@text, " Log:");
548 push(@text, &read_logfile("$LOG_FILE.$i.$id", " "));
549 if ($rcsidinfo == 2) {
550 if (-e "$SUMMARY_FILE.$i.$id") {
551 push(@text, " ");
552 push(@text, " Revision Changes Path");
553 push(@text, &read_logfile("$SUMMARY_FILE.$i.$id", " "));
554 }
555 }
556 push(@text, "");
557 }
558 #
559 # Append the log message to the commitlogs/<module> file
560 #
561 #&do_changes_file($mlist, @text);
562 #
563 # Now generate the extra info for the mail message..
564 #
565 if ($rcsidinfo == 1) {
566 $revhdr = 0;
567 for ($i = 0; ; $i++) {
568 last if (! -e "$LOG_FILE.$i.$id");
569 if (-e "$SUMMARY_FILE.$i.$id") {
570 if (!$revhdr++) {
571 push(@text, "Revision Changes Path");
572 }
573 push(@text, &read_logfile("$SUMMARY_FILE.$i.$id", ""));
574 }
575 }
576 if ($revhdr) {
577 push(@text, ""); # consistancy...
578 }
579 }
580 #
581 # Mail out the notification.
582 #
583 &mail_notification(@text) if defined($MAIL_TO);
584 &cleanup_tmpfiles;
585 exit 0;
586
587
588
589 --
590 gentoo-commits@g.o mailing list