home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / contrib / log.pl < prev    next >
Perl Script  |  1996-09-28  |  4KB  |  170 lines

  1. #! xPERL_PATHx
  2. # -*-Perl-*-
  3. #
  4. #ident    "$CVSid$"
  5. #
  6. # XXX: FIXME: handle multiple '-f logfile' arguments
  7. #
  8. # XXX -- I HATE Perl!  This *will* be re-written in shell/awk/sed soon!
  9. #
  10.  
  11. # Usage:  log.pl [[-m user] ...] [-s] -f logfile 'dirname file ...'
  12. #
  13. #    -m user        - for each user to receive cvs log reports
  14. #            (multiple -m's permitted)
  15. #    -s        - to prevent "cvs status -v" messages
  16. #    -f logfile    - for the logfile to append to (mandatory,
  17. #            but only one logfile can be specified).
  18.  
  19. # here is what the output looks like:
  20. #
  21. #    From: woods@kuma.domain.top
  22. #    Subject: CVS update: testmodule
  23. #
  24. #    Date: Wednesday November 23, 1994 @ 14:15
  25. #    Author: woods
  26. #
  27. #    Update of /local/src-CVS/testmodule
  28. #    In directory kuma:/home/kuma/woods/work.d/testmodule
  29. #    
  30. #    Modified Files:
  31. #        test3 
  32. #    Added Files:
  33. #        test6 
  34. #    Removed Files:
  35. #        test4 
  36. #    Log Message:
  37. #    - wow, what a test
  38. #
  39. # (and for each file the "cvs status -v" output is appended unless -s is used)
  40. #
  41. #    ==================================================================
  42. #    File: test3               Status: Up-to-date
  43. #    
  44. #       Working revision:    1.41    Wed Nov 23 14:15:59 1994
  45. #       Repository revision:    1.41    /local/src-CVS/cvs/testmodule/test3,v
  46. #       Sticky Options:    -ko
  47. #    
  48. #       Existing Tags:
  49. #        local-v2                     (revision: 1.7)
  50. #        local-v1                     (revision: 1.1.1.2)
  51. #        CVS-1_4A2                    (revision: 1.1.1.2)
  52. #        local-v0                     (revision: 1.2)
  53. #        CVS-1_4A1                    (revision: 1.1.1.1)
  54. #        CVS                          (branch: 1.1.1)
  55.  
  56. $cvsroot = $ENV{'CVSROOT'};
  57.  
  58. # turn off setgid
  59. #
  60. $) = $(;
  61.  
  62. $dostatus = 1;
  63.  
  64. # parse command line arguments
  65. #
  66. while (@ARGV) {
  67.         $arg = shift @ARGV;
  68.  
  69.     if ($arg eq '-m') {
  70.                 $users = "$users " . shift @ARGV;
  71.     } elsif ($arg eq '-f') {
  72.         ($logfile) && die "Too many '-f' args";
  73.         $logfile = shift @ARGV;
  74.     } elsif ($arg eq '-s') {
  75.         $dostatus = 0;
  76.     } else {
  77.         ($donefiles) && die "Too many arguments!\n";
  78.         $donefiles = 1;
  79.         @files = split(/ /, $arg);
  80.     }
  81. }
  82.  
  83. # the first argument is the module location relative to $CVSROOT
  84. #
  85. $modulepath = shift @files;
  86.  
  87. $mailcmd = "| Mail -s 'CVS update: $modulepath'";
  88.  
  89. # Initialise some date and time arrays
  90. #
  91. @mos = (January,February,March,April,May,June,July,August,September,
  92.         October,November,December);
  93. @days = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
  94.  
  95. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  96.  
  97. # get a login name for the guy doing the commit....
  98. #
  99. $login = getlogin || (getpwuid($<))[0] || "nobody";
  100.  
  101. # open log file for appending
  102. #
  103. open(OUT, ">>" . $logfile) || die "Could not open(" . $logfile . "): $!\n";
  104.  
  105. # send mail, if there's anyone to send to!
  106. #
  107. if ($users) {
  108.     $mailcmd = "$mailcmd $users";
  109.     open(MAIL, $mailcmd) || die "Could not Exec($mailcmd): $!\n";
  110. }
  111.  
  112. # print out the log Header
  113. print OUT "\n";
  114. print OUT "****************************************\n";
  115. print OUT "Date:\t$days[$wday] $mos[$mon] $mday, 19$year @ $hour:" . sprintf("%02d", $min) . "\n";
  116. print OUT "Author:\t$login\n\n";
  117.  
  118. if (MAIL) {
  119.     print MAIL "\n";
  120.     print MAIL "Date:\t$days[$wday] $mos[$mon] $mday, 19$year @ $hour:" . sprintf("%02d", $min) . "\n";
  121.     print MAIL "Author:\t$login\n\n";
  122. }
  123.  
  124. # print the stuff from logmsg that comes in on stdin to the logfile
  125. #
  126. open(IN, "-");
  127. while (<IN>) {
  128.     print OUT $_;
  129.     if (MAIL) {
  130.         print MAIL $_;
  131.     }
  132. }
  133. close(IN);
  134.  
  135. print OUT "\n";
  136.  
  137. # after log information, do an 'cvs -Qq status -v' on each file in the arguments.
  138. #
  139. if ($dostatus != 0) {
  140.     while (@files) {
  141.         $file = shift @files;
  142.         if ($file eq "-") {
  143.             print OUT "[input file was '-']\n";
  144.             if (MAIL) {
  145.                 print MAIL "[input file was '-']\n";
  146.             }
  147.             last;
  148.         }
  149.         open(RCS, "-|") || exec 'cvs', '-nQq', 'status', '-v', $file;
  150.         while (<RCS>) {
  151.             print OUT;
  152.             if (MAIL) {
  153.                 print MAIL;
  154.             }
  155.         }
  156.         close(RCS);
  157.     }
  158. }
  159.  
  160. close(OUT);
  161. die "Write to $logfile failed" if $?;
  162.  
  163. close(MAIL);
  164. die "Pipe to $mailcmd failed" if $?;
  165.  
  166. ## must exit cleanly
  167. ##
  168. exit 0;
  169.