home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Programy / Programowanie / cvs-1.11.lha / cvs-1.11 / contrib / log.pl < prev    next >
Encoding:
Perl Script  |  2000-02-25  |  4.2 KB  |  183 lines

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