head	1.21;
access;
symbols
	TIGRIS_1_1_0RC2:1.20
	TIGRIS_1_1_0RC1:1.20
	TIGRIS_1_1:1.20.0.4
	TIGRIS_1_0_8:1.20
	TIGRIS_1_0_8RC3:1.20
	TIGRIS_1_0_8RC2:1.20
	TIGRIS_1_0_8RC1:1.20
	TIGRIS_1_0_7:1.20
	TIGRIS_1_0_7RC3:1.20
	TIGRIS_1_0_7RC2:1.20
	TIGRIS_1_0_7RC1:1.20
	TIGRIS_1_0_6:1.20
	TIGRIS_1_0_6RC5:1.20
	TIGRIS_1_0_6RC4:1.20
	TIGRIS_1_0_6RC3:1.20
	TIGRIS_1_0_6RC2:1.20
	TIGRIS_1_0_6RC1:1.20
	TIGRIS_1_0_5:1.20
	TIGRIS_1_0_5RC6:1.20
	TIGRIS_1_0_5RC5:1.20
	TIGRIS_1_0_5RC4:1.20
	TIGRIS_1_0_5RC3:1.20
	TIGRIS_1_0_5RC2:1.20
	TIGRIS_1_0_5RC1:1.20
	TIGRIS_1_0_4:1.20
	TIGRIS_1_0_3:1.20
	TIGRIS_1_0_2:1.20
	TIGRIS_1_0_1:1.20
	TIGRIS_1_0:1.20.0.6
	TIGRIS_1_0_0:1.20
	TIGRIS_1_0_0_RC1:1.20.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.18
	TIGRIS_0_9_2_3:1.18
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.18
	TIGRIS_0_9_2_1:1.18
	TIGRIS_0_9_2:1.18.0.6
	TIGRIS_0_9_0:1.18.0.4
	TIGRIS_0_8_4:1.18.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1
	OLDHELM:1.15.0.2
	TIGRIS_NOV_11_2000:1.15
	TIGRIS_SEP_13_2000:1.12.0.2
	TIGRIS_BASELINE:1.14;
locks; strict;
comment	@# @;


1.21
date	2001.05.22.17.57.42;	author thom;	state dead;
branches;
next	1.20;

1.20
date	2001.02.15.17.22.19;	author jrobbins;	state Exp;
branches;
next	1.19;

1.19
date	2001.02.15.16.27.41;	author jrobbins;	state Exp;
branches;
next	1.18;

1.18
date	2000.11.27.21.54.12;	author thom;	state Exp;
branches
	1.18.4.1
	1.18.8.1;
next	1.17;

1.17
date	2000.11.22.02.08.52;	author thom;	state Exp;
branches;
next	1.16;

1.16
date	2000.11.12.22.57.30;	author dlr;	state Exp;
branches;
next	1.15;

1.15
date	2000.10.23.16.26.49;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2000.09.22.18.39.16;	author thom;	state Exp;
branches;
next	1.13;

1.13
date	2000.09.22.18.16.44;	author jrobbins;	state Exp;
branches;
next	1.12;

1.12
date	2000.09.05.22.37.42;	author thom;	state Exp;
branches;
next	1.11;

1.11
date	2000.09.05.22.37.32;	author thom;	state Exp;
branches;
next	1.10;

1.10
date	2000.09.05.22.37.23;	author thom;	state Exp;
branches;
next	1.9;

1.9
date	2000.09.05.22.37.13;	author thom;	state Exp;
branches;
next	1.8;

1.8
date	2000.09.05.22.37.03;	author thom;	state Exp;
branches;
next	1.7;

1.7
date	2000.09.05.22.36.52;	author thom;	state Exp;
branches;
next	1.6;

1.6
date	2000.09.05.22.36.44;	author thom;	state Exp;
branches;
next	1.5;

1.5
date	2000.09.05.22.36.34;	author thom;	state Exp;
branches;
next	1.4;

1.4
date	2000.09.05.22.36.25;	author thom;	state Exp;
branches;
next	1.3;

1.3
date	2000.09.05.22.36.15;	author thom;	state Exp;
branches;
next	1.2;

1.2
date	2000.09.05.22.12.42;	author thom;	state Exp;
branches;
next	1.1;

1.1
date	2000.07.11.21.15.44;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.14.11;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.31.48;	author dlr;	state Exp;
branches;
next	;

1.18.4.1
date	2001.02.15.16.42.20;	author jrobbins;	state Exp;
branches;
next	1.18.4.2;

1.18.4.2
date	2001.02.15.17.23.11;	author jrobbins;	state Exp;
branches;
next	;

1.18.8.1
date	2001.02.17.18.56.38;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.21
log
@remove the use of log_accum and commit_prep. this is now replaced with
logchange.pl and logchange.config
Issue number:  2528, 2577, 3002
Obtained from:
Submitted by:
Reviewed by:
@
text
@#!/usr/bin/perl
#
# Perl filter to handle the log messages from the checkin of files in
# a directory.  This script will group the lists of files by log
# message, and mail a single consolidated log message at the end of
# the commit.
#
# This file assumes a pre-commit checking program that leaves the
# names of the first and last commit directories in a temporary file.
#
# IMPORTANT: what the above means is, this script interacts with
# commit_prep, in that they have to agree on the tmpfile name to use.
# See $LAST_FILE below. 
#
# How this works: CVS triggers this script once for each directory
# involved in the commit -- in other words, a single commit can invoke
# this script N times.  It knows when it's on the last invocation by
# examining the contents of $LAST_FILE.  Between invocations, it
# caches information for its future incarnations in various temporary
# files in /tmp, which are named according to the process group and
# the committer (by themselves, neither of these are unique, but
# together they almost always are, unless the same user is doing two
# commits simultaneously).  The final invocation is the one that
# actually sends the mail -- it gathers up the cached information,
# combines that with what it found out on this pass, and sends a
# commit message to the appropriate mailing list.
#
# (Ask Karl Fogel <kfogel@@collab.net> if questions.)
#
# Contributed by David Hampton <hampton@@cisco.com>
# Roy Fielding removed useless code and added log/mail of new files
# Ken Coar added special processing (i.e., no diffs) for binary files
#

# Tigris libraries
# CONFIG - set this to /path/to/tigris/perl
use lib "__SANDBOX__/helm/perl";

############################################################
#
# Configurable options
#
############################################################
#
# Where do you want the RCS ID and delta info?
# 0 = none,
# 1 = in mail only,
# 2 = in both mail and logs.
#
$rcsidinfo = 2;

#if you are using CVS web then set this to some value... if not set it to ""
$CVSWEB_SCHEME = "__HTTP_SCHEME__";
$CVSWEB_DOMAIN = "__DOMAIN__";
$CVSWEB_PORT = "__APACHE_PORT__";
$CVSWEB_URI = "source/browse/";
$SEND_URL = "__LOG_ACCUM_SEND_URL__";
$SEND_DIFF = "__LOG_ACCUM_SEND_DIFF__";


# Set this to a domain to have CVS pretend that all users who make
# commits have mail accounts within that domain.
$EMULATE_LOCAL_MAIL_USER="__DOMAIN__"; 

# Set this to '-c' for context diffs; defaults to '-u' for unidiff format.
$difftype = '-u';

############################################################
#
# Constants
#
############################################################
$STATE_NONE    = 0;
$STATE_CHANGED = 1;
$STATE_ADDED   = 2;
$STATE_REMOVED = 3;
$STATE_LOG     = 4;

$TMPDIR        = $ENV{'TMPDIR'} || '/tmp';
$FILE_PREFIX   = '#cvs.';

$LAST_FILE     = "$TMPDIR/${FILE_PREFIX}lastdir";  # Created by commit_prep!
### <npm:removed>
#$CHANGED_FILE  = "$TMPDIR/${FILE_PREFIX}files.changed";
### </npm>
$ADDED_FILE    = "$TMPDIR/${FILE_PREFIX}files.added";
$REMOVED_FILE  = "$TMPDIR/${FILE_PREFIX}files.removed";
$LOG_FILE      = "$TMPDIR/${FILE_PREFIX}files.log";
$BRANCH_FILE   = "$TMPDIR/${FILE_PREFIX}files.branch";
$MLIST_FILE    = "$TMPDIR/${FILE_PREFIX}files.mlist";
$SUMMARY_FILE  = "$TMPDIR/${FILE_PREFIX}files.summary";

$CVSROOT       = $ENV{'CVSROOT'};

$CVSBIN        = '/usr/bin';
$PATH          = "$PATH:/bin:/usr/bin";
#$MAIL_CMD      = "| /usr/lib/sendmail -i -t";
$MAIL_CMD      = "| /var/qmail/bin/qmail-inject";
$MAIL_FROM     = 'commitlogger';  #not needed if EMULATE_LOCAL_MAIL_USER
$SUBJECT_PRE   = 'CVS update:';


############################################################
#
# Subroutines
#
############################################################

sub format_names {
    local($dir, @@files) = @@_;
    local(@@lines);

    $lines[0] = sprintf(" %-08s", $dir);
    foreach $file (@@files) {
        if (length($lines[$#lines]) + length($file) > 60) {
            $lines[++$#lines] = sprintf(" %8s", " ");
        }
        $lines[$#lines] .= " ".$file;
    }
    @@lines;
}

sub cleanup_tmpfiles {
    local(@@files);

    opendir(DIR, $TMPDIR);
    push(@@files, grep(/^${FILE_PREFIX}.*\.${id}\.${cvs_user}$/, readdir(DIR)));
    closedir(DIR);
    foreach (@@files) {
        unlink "$TMPDIR/$_";
    }
}

sub write_logfile {
    local($filename, @@lines) = @@_;

    open(FILE, ">$filename") || die ("Cannot open log file $filename: $!\n");
    print(FILE join("\n", @@lines), "\n");
    close(FILE);
}

sub append_to_file {
    local($filename, $dir, @@files) = @@_;

    if (@@files) {
        local(@@lines) = &format_names($dir, @@files);
        open(FILE, ">>$filename") || die ("Cannot open file $filename: $!\n");
        print(FILE join("\n", @@lines), "\n");
        close(FILE);
    }
}

sub write_line {
    local($filename, $line) = @@_;

    open(FILE, ">$filename") || die("Cannot open file $filename: $!\n");
    print(FILE $line, "\n");
    close(FILE);
}

sub append_line {
    local($filename, $line) = @@_;

    open(FILE, ">>$filename") || die("Cannot open file $filename: $!\n");
    print(FILE $line, "\n");
    close(FILE);
}

sub read_line {
    local($filename) = @@_;
    local($line);

    open(FILE, "<$filename") || die("Cannot open file $filename: $!\n");
    $line = <FILE>;
    close(FILE);
    chomp($line);
    $line;
}

#<npm:added>
sub read_line_nodie {
    local($filename) = @@_;
    local($line);
    open(FILE, "<$filename") || return ("");

    $line = <FILE>;
    close(FILE);
    chomp($line);
    $line;
}
#</npm>

sub read_file_lines {
    local($filename) = @@_;
    local(@@text) = ();

    open(FILE, "<$filename") || return ();
    while (<FILE>) {
        chomp;
        push(@@text, $_);
    }
    close(FILE);
    @@text;
}

sub read_file {
    local($filename, $leader) = @@_;
    local(@@text) = ();

    open(FILE, "<$filename") || return ();
    while (<FILE>) {
        chomp;
        push(@@text, sprintf("  %-10s  %s", $leader, $_));
        $leader = "";
    }
    close(FILE);
    @@text;
}

sub read_logfile {
    local($filename, $leader) = @@_;
    local(@@text) = ();

    open(FILE, "<$filename") || die ("Cannot open log file $filename: $!\n");
    while (<FILE>) {
        chomp;
        push(@@text, $leader.$_);
    }
    close(FILE);
    @@text;
}

#
# do an 'cvs -Qn status' on each file in the arguments, and extract info.
#
sub change_summary {
    local($out, @@filenames) = @@_;
    local(@@revline);
    local($file, $rev, $rcsfile, $line, $vhost, $cvsweb_base);

    while (@@filenames) {
        $file = shift @@filenames;

        if ("$file" eq "") {
            next;
        }

        open(RCS, "-|") || exec "$cvsbin/cvs", '-Qn', 'status', $file;

        $rev = "";
        $delta = "";
        $rcsfile = "";


        while (<RCS>) {
            if (/^[ \t]*Repository revision/) {
                chomp;
                @@revline = split(' ', $_);
                $rev = $revline[2];
                $rcsfile = $revline[3];
                $rcsfile =~ s,^$CVSROOT/,,;
                $rcsfile =~ s/,v$//;
            }
        }
        close(RCS);


        if ($rev ne '' && $rcsfile ne '') {
            open(RCS, "-|") || exec "$cvsbin/cvs", '-Qn', 'log', "-r$rev", $file;
            while (<RCS>) {
                if (/^date:/) {
                    chomp;
                    $delta = $_;
                    $delta =~ s/^.*;//;
                    $delta =~ s/^[\s]+lines://;
                }
            }
            close(RCS);
        }

        $diff = "\n\n";
        $vhost = @@path[0];
        if ($CVSWEB_PORT eq "80") {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN/$CVSWEB_URI";
        }
        else {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN:$CVSWEB_PORT/$CVSWEB_URI";
        }
        if ($SEND_URL eq "true") {
          $diff .= $cvsweb_base . join("/", @@path) . "/$file";
        }

        #
        # If this is a binary file, don't try to report a diff; not only is
        # it meaningless, but it also screws up some mailers.  We rely on
        # Perl's 'is this binary' algorithm; it's pretty good.  But not
        # perfect.
        #
        if (($file =~ /\.(?:pdf|gif|jpg|mpg)$/i) || (-B $file)) {
          if ($SEND_URL eq "true") {
            $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
          }
          if ($SEND_DIFF eq "true") {
            $diff .= "\t<<Binary file>>\n\n";
          }
        }
        else {
            #
            # Get the differences between this and the previous revision,
            # being aware that new files always have revision '1.1' and
            # new branches always end in '.n.1'.
            #
            if ($rev =~ /^(.*)\.([0-9]+)$/) {
                $prev = $2 - 1;
                $prev_rev = $1 . '.' .  $prev;

                $prev_rev =~ s/\.[0-9]+\.0$//;# Truncate if first rev on branch

                if ($rev eq '1.1') {
                  if ($SEND_URL eq "true") {
                    $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
                    open(DIFF, "-|")
                      || exec "$cvsbin/cvs", '-Qn', 'update', '-p', '-r1.1', $file;
                    $diff .= "Index: $file\n=================================="
                      . "=================================\n";
                  }
                }
                else {
                  if ($SEND_URL eq "true") {
                    $diff .= ".diff?r1=$prev_rev&r2=$rev\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
                    $diff .= "(In the diff below, changes in quantity "
                      . "of whitespace are not shown.)\n\n";
                    open(DIFF, "-|")
                      || exec "$cvsbin/cvs", '-Qn', 'diff', "$difftype",
                      '-b', "-r$prev_rev", "-r$rev", $file;
                  }
                }

                if ($SEND_DIFF eq "true") {
                  while (<DIFF>) {
                    $diff .= $_;
                  }
                  close(DIFF);
                }
                $diff .= "\n\n";
            }
        }

        &append_line($out, sprintf("%-9s%-12s%s%s", $rev, $delta,
                                   $rcsfile, $diff));
    }
}


sub build_header {
    local($header);
    delete $ENV{'TZ'};
    local($sec,$min,$hour,$mday,$mon,$year) = localtime(time);

    $header = sprintf("  User: %-8s\n  Date: %02d/%02d/%02d %02d:%02d:%02d",
                       $cvs_user, $year%100, $mon+1, $mday,
                       $hour, $min, $sec);
#    $header = sprintf("%-8s    %02d/%02d/%02d %02d:%02d:%02d",
#                       $login, $year%100, $mon+1, $mday,
#                       $hour, $min, $sec);
}

# !!! Mailing-list and history file mappings here !!!
sub mlist_map
{
    local($path) = @@_;
    my $domain = "__DOMAIN__";
    
    if ($path =~ /^([^\/]+)/) {
        return "cvs\@@$1.$domain";
    } else {
        return "cvs\@@$domain";
    }
}    

### <npm:removed>
#sub do_changes_file
#{
#    local($category, @@text) = @@_;
#    local($changes);
#
#    $changes = "$CVSROOT/CVSROOT/commitlogs/$category";
#    if (open(CHANGES, ">>$changes")) {
#        print(CHANGES join("\n", @@text), "\n\n");
#        close(CHANGES);
#    }
#    else { 
#        warn "Cannot open $changes: $!\n";
#    }
#}
### </npm>

sub derive_subject_from_changes_file ()
{
  my $subj = "";

  for ($i = 0; ; $i++)
  {
    open (CH, "<$CHANGED_FILE.$i.$id.$cvs_user") or last;

    while (my $change = <CH>)
    {
      # A changes file looks like this:
      #
      #  src      foo.c newfile.html
      #  www      index.html project_nav.html
      #
      # Each line is " Dir File1 File2 ..."
      # We only care about Dir, since the subject line should
      # summarize. 
      
      $change =~ s/^[ \t]*//;
      $change =~ /^([^ \t]+)[ \t]*/;
      my $dir = $1;
      # Fold to rightmost directory component
      $dir =~ /([^\/]+)$/;
      $dir = $1;
      if ($subj eq "") {
        $subj = $dir;
      } else {
        $subj .= ", $dir"; 
      }
    }
    close (CH);
  }

###<npm:added>
  if ($subj ne "") {
      $subj = "MODIFIED: $subj ..."; 
  }
  else {
      # NPM: See if there's any file-addition notifications.
      my $added = &read_line_nodie("$ADDED_FILE.$i.$id.$cvs_user");
      if ($added ne "") {
          $subj .= "ADDED: $added "; 
      }
    
#    print "derive_subject_from_changes_file().. added== $added \n";
    
       ## NPM: See if there's any file-removal notications.
      my $removed = &read_line_nodie("$REMOVED_FILE.$i.$id.$cvs_user");
      if ($removed ne "") {
          $subj .= "REMOVED: $removed "; 
      }
    
#    print "derive_subject_from_changes_file().. removed== $removed \n";
    
      ## NPM: See if there's any branch notifications.
      my $branched = &read_line_nodie("$BRANCH_FILE.$i.$id.$cvs_user");
      if ($branched ne "") {
          $subj .= "BRANCHED: $branched"; 
      }
    
#    print "derive_subject_from_changes_file().. branched== $branched \n";
    
      ## NPM: DEFAULT: DIRECTORY CREATION (c.f. "Check for a new directory first" in main mody)
      if ($subj eq "") {
          my $subject = join("/", @@path);
          $subj = "NEW: $subject"; 
      }    
  }
###</npm>

  return $subj;
}

sub mail_notification
{
    local($addr_list, @@text) = @@_;
    local($mail_to);

    my $subj = &derive_subject_from_changes_file ();

    if ($EMULATE_LOCAL_MAIL_USER NE "") {
        $MAIL_FROM = "$cvs_user\@@$EMULATE_LOCAL_MAIL_USER";
    }

    $mail_to = join(", ", @@{$addr_list});

    print "Mailing the commit message to $mail_to (from $MAIL_FROM)\n";

    $ENV{'MAILUSER'} = $MAIL_FROM;
    # Commented out on hocus, so comment it out here.  -kff
    # $ENV{'QMAILINJECT'} = 'f';

    open(MAIL, "$MAIL_CMD -f$MAIL_FROM");
    print MAIL "From: $MAIL_FROM\n";
    print MAIL "To: $mail_to\n";
    print MAIL "Subject: $SUBJECT_PRE $subj\n\n";
    print(MAIL join("\n", @@text));
    close(MAIL);
#    print "Mailing the commit message to $MAIL_TO...\n";
#
#    #added by jrobbins@@collab.net 1999/12/15
#    # attempt to get rid of anonymous
#    $ENV{'MAILUSER'} = 'commitlogger';
#    $ENV{'QMAILINJECT'} = 'f';
#
#    open(MAIL, "| /var/qmail/bin/qmail-inject");
#    print(MAIL "To: $MAIL_TO\n"); 
#    print(MAIL "Subject: cvs commit: $ARGV[0]\n"); 
#    print(MAIL join("\n", @@text));
#    close(MAIL);
}

## process the command line arguments sent to this script
## it returns an array of files, %s, sent from the loginfo
## command
sub process_argv
{
    local(@@argv) = @@_;
    local(@@files);
    local($arg);
    print "Processing log script arguments...\n";

    while (@@argv) {
        $arg = shift @@argv;

        if ($arg eq '-u') {
                $cvs_user = shift @@argv;
        } else {
                ($donefiles) && die "Too many arguments!\n";
                $donefiles = 1;
                $ARGV[0] = $arg;
                @@files = split(' ', $arg);
        }
    }
    return @@files;
}


#############################################################
#
# Main Body
#
############################################################
#
# Setup environment
#
umask (002);

# Connect to the database
$cvsbin = "/usr/bin";

###<npm:add>
# NPM: derive host's domain name from DB, setup EMULATE_LOCAL_MAIL_USER so
# that commitlogger mail is sent as if from <cvsuser>@@<hostdomain>
$HOST_DOMAIN = "__DOMAIN__";
$EMULATE_LOCAL_MAIL_USER = "$HOST_DOMAIN";
###</npm>

#
# Initialize basic variables
#
$id = getpgrp();
$state = $STATE_NONE;
$cvs_user = $ENV{'USER'} || getlogin || (getpwuid($<))[0] || sprintf("uid#%d",$<);
@@files = process_argv(@@ARGV);
@@path = split('/', $files[0]);
$repository = $path[0];
if ($#path == 0) {
    $dir = ".";
} else {
    $dir = join('/', @@path[1..$#path]);
}
#print("ARGV  - ", join(":", @@ARGV), "\n");
#print("files - ", join(":", @@files), "\n");
#print("path  - ", join(":", @@path), "\n");
#print("dir   - ", $dir, "\n");
#print("id    - ", $id, "\n");

#
# Map the repository directory to a name for commitlogs.
#
$mlist = &mlist_map($files[0]);

##########################
# (dead code) Uncomment the following if we ever have per-repository cvs mail
#
# if (defined($mlist)) {
#     $MAIL_TO = $mlist
# }
# else { undef $MAIL_TO; }

##########################
#
# Check for a new directory first.  This will always appear as a
# single item in the argument list, and an empty log message.
#
if ($ARGV[0] =~ /New directory/) {
    $header = &build_header;
    @@text = ();
    push(@@text, $header);
    push(@@text, "");
    push(@@text, "  ".$ARGV[0]);
###<npm:remove>
##    &do_changes_file($mlist, @@text);
###</npm>
    &mail_notification([ $mlist ], @@text);
    exit 0;
}

#
# Iterate over the body of the message collecting information.
#
while (<STDIN>) {
    chomp;                      # Drop the newline
    if (/^Revision\/Branch:/) {
        s,^Revision/Branch:,,;
        push (@@branch_lines, split);
        next;
    }
#    next if (/^[ \t]+Tag:/ && $state != $STATE_LOG);
    if (/^Modified Files/) { $state = $STATE_CHANGED; next; }
    if (/^Added Files/)    { $state = $STATE_ADDED;   next; }
    if (/^Removed Files/)  { $state = $STATE_REMOVED; next; }
    if (/^Log Message/)    { $state = $STATE_LOG;     next; }
    s/[ \t\n]+$//;              # delete trailing space
    
    push (@@changed_files, split) if ($state == $STATE_CHANGED);
    push (@@added_files,   split) if ($state == $STATE_ADDED);
    push (@@removed_files, split) if ($state == $STATE_REMOVED);
    if ($state == $STATE_LOG) {
        if (/^PR:$/i ||
            /^Reviewed by:$/i ||
            /^Submitted by:$/i ||
            /^Obtained from:$/i) {
            next;
        }
        push (@@log_lines,     $_);
    }
}

#
# Strip leading and trailing blank lines from the log message.  Also
# compress multiple blank lines in the body of the message down to a
# single blank line.
# (Note, this only does the mail and changes log, not the rcs log).
#
while ($#log_lines > -1) {
    last if ($log_lines[0] ne "");
    shift(@@log_lines);
}
while ($#log_lines > -1) {
    last if ($log_lines[$#log_lines] ne "");
    pop(@@log_lines);
}
for ($i = $#log_lines; $i > 0; $i--) {
    if (($log_lines[$i - 1] eq "") && ($log_lines[$i] eq "")) {
        splice(@@log_lines, $i, 1);
    }
}

#
# Find the log file that matches this log message
#
for ($i = 0; ; $i++) {
    last if (! -e "$LOG_FILE.$i.$id.$cvs_user");
    @@text = &read_logfile("$LOG_FILE.$i.$id.$cvs_user", "");
    last if ($#text == -1);
    last if (join(" ", @@log_lines) eq join(" ", @@text));
}

#
# Spit out the information gathered in this pass.
#
&write_logfile("$LOG_FILE.$i.$id.$cvs_user", @@log_lines);
&append_to_file("$BRANCH_FILE.$i.$id.$cvs_user",  $dir, @@branch_lines);
&append_to_file("$ADDED_FILE.$i.$id.$cvs_user",   $dir, @@added_files);
&append_to_file("$CHANGED_FILE.$i.$id.$cvs_user", $dir, @@changed_files);
&append_to_file("$REMOVED_FILE.$i.$id.$cvs_user", $dir, @@removed_files);
&append_line("$MLIST_FILE.$i.$id.$cvs_user", $mlist);
if ($rcsidinfo) {
    &change_summary("$SUMMARY_FILE.$i.$id.$cvs_user", (@@changed_files, @@added_files));
}

#
# Check whether this is the last directory.  If not, quit.
#
if (-e "$LAST_FILE.$id.$cvs_user") {
   $_ = &read_line("$LAST_FILE.$id.$cvs_user");
   $tmpfiles = $files[0];
   $tmpfiles =~ s,([^a-zA-Z0-9_/]),\\$1,g;
   if (! grep(/$tmpfiles$/, $_)) {
        print "More commits to come...\n";
        exit 0
   }
}

#
# This is it.  The commits are all finished.  Lump everything together
# into a single message, fire a copy off to the mailing list, and drop
# it on the end of the Changes file.
#
$header = &build_header;

#
# Produce the final compilation of the log messages
#
@@text = ();
@@mlist_list = ();
push(@@text, $header);
push(@@text, "");
for ($i = 0; ; $i++) {
    last if (! -e "$LOG_FILE.$i.$id.$cvs_user");
    push(@@text, &read_file("$BRANCH_FILE.$i.$id.$cvs_user", "Branch:"));
    push(@@text, &read_file("$CHANGED_FILE.$i.$id.$cvs_user", "Modified:"));
    push(@@text, &read_file("$ADDED_FILE.$i.$id.$cvs_user", "Added:"));
    push(@@text, &read_file("$REMOVED_FILE.$i.$id.$cvs_user", "Removed:"));
    push(@@text, "  Log:");
    push(@@text, &read_logfile("$LOG_FILE.$i.$id.$cvs_user", "  "));
    push(@@mlist_list, &read_file_lines("$MLIST_FILE.$i.$id.$cvs_user"));
    if ($rcsidinfo == 2) {
        if (-e "$SUMMARY_FILE.$i.$id.$cvs_user") {
            push(@@text, "  ");
            push(@@text, "  Revision  Changes    Path");
            push(@@text, &read_logfile("$SUMMARY_FILE.$i.$id.$cvs_user", "  "));
        }
    }
    push(@@text, "");
}

###<npm:remove>
#
# Append the log message to the commitlogs/<module> file
#
#&do_changes_file($mlist, @@text);
###</npm>

#
# Now generate the extra info for the mail message..
#
if ($rcsidinfo == 1) {
    $revhdr = 0;
    for ($i = 0; ; $i++) {
        last if (! -e "$LOG_FILE.$i.$id.$cvs_user");
        if (-e "$SUMMARY_FILE.$i.$id.$cvs_user") {
            if (!$revhdr++) {
                push(@@text, "Revision  Changes    Path");
            }
            push(@@text, &read_logfile("$SUMMARY_FILE.$i.$id.$cvs_user", ""));
        }
    }
    if ($revhdr) {
        push(@@text, "");        # consistancy...
    }
}

%mlist_hash = ();

foreach (@@mlist_list) { $mlist_hash{ $_ } = 1; }

#
# Mail out the notification.
#
&mail_notification([ keys(%mlist_hash) ], @@text);
&cleanup_tmpfiles;
exit 0;
@


1.20
log
@corrected cut and paste error
@
text
@@


1.19
log
@added option to send webcvs URLs in commit messages
@
text
@d301 1
a301 1
            $diff .= ".diff?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
d321 1
a321 1
                    $diff .= ".diff?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
@


1.18
log
@added the read_line_nodie
@
text
@d53 7
a59 1
$CVSWEB = "http://__HOSTNAME__/source/browse/";
d239 1
a239 1
    local($file, $rev, $rcsfile, $line);
d282 10
d300 4
d305 1
d320 4
d325 1
a325 1
                        || exec "$cvsbin/cvs", '-Qn', 'update', '-p', '-r1.1', $file;
d327 2
a328 1
                        . "=================================\n";
d331 5
a335 1
                  $diff .= "(In the diff below, changes in quantity "
d338 3
a340 2
                        || exec "$cvsbin/cvs", '-Qn', 'diff', "$difftype",
                                '-b', "-r$prev_rev", "-r$rev", $file;
d343 2
a344 1
                while (<DIFF>) {
d346 2
a348 1
                close(DIFF);
@


1.18.8.1
log
@Merging from head.
@
text
@d53 1
a53 7
$CVSWEB_SCHEME = "__HTTP_SCHEME__";
$CVSWEB_DOMAIN = "__DOMAIN__";
$CVSWEB_PORT = "__APACHE_PORT__";
$CVSWEB_URI = "source/browse/";
$SEND_URL = "__LOG_ACCUM_SEND_URL__";
$SEND_DIFF = "__LOG_ACCUM_SEND_DIFF__";

d233 1
a233 1
    local($file, $rev, $rcsfile, $line, $vhost, $cvsweb_base);
a275 10
        $vhost = @@path[0];
        if ($CVSWEB_PORT eq "80") {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN/$CVSWEB_URI";
        }
        else {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN:$CVSWEB_PORT/$CVSWEB_URI";
        }
        if ($SEND_URL eq "true") {
          $diff .= $cvsweb_base . join("/", @@path) . "/$file";
        }
a283 4
          if ($SEND_URL eq "true") {
            $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
          }
          if ($SEND_DIFF eq "true") {
a284 1
          }
a298 4
                  if ($SEND_URL eq "true") {
                    $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
d300 1
a300 1
                      || exec "$cvsbin/cvs", '-Qn', 'update', '-p', '-r1.1', $file;
d302 1
a302 2
                      . "=================================\n";
                  }
d305 1
a305 5
                  if ($SEND_URL eq "true") {
                    $diff .= ".diff?r1=$prev_rev&r2=$rev\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
                    $diff .= "(In the diff below, changes in quantity "
d308 2
a309 3
                      || exec "$cvsbin/cvs", '-Qn', 'diff', "$difftype",
                      '-b', "-r$prev_rev", "-r$rev", $file;
                  }
d312 1
a312 2
                if ($SEND_DIFF eq "true") {
                  while (<DIFF>) {
a313 2
                  }
                  close(DIFF);
d315 1
@


1.18.4.1
log
@added option for log_accum to send URL into cvsweb
@
text
@d53 1
a53 7
$CVSWEB_SCHEME = "__HTTP_SCHEME__";
$CVSWEB_DOMAIN = "__DOMAIN__";
$CVSWEB_PORT = "__APACHE_PORT__";
$CVSWEB_URI = "source/browse/";
$SEND_URL = "__LOG_ACCUM_SEND_URL__";
$SEND_DIFF = "__LOG_ACCUM_SEND_DIFF__";

d233 1
a233 1
    local($file, $rev, $rcsfile, $line, $vhost, $cvsweb_base);
a275 10
        $vhost = @@path[0];
        if ($CVSWEB_PORT eq "80") {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN/$CVSWEB_URI";
        }
        else {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN:$CVSWEB_PORT/$CVSWEB_URI";
        }
        if ($SEND_URL eq "true") {
          $diff .= $cvsweb_base . join("/", @@path) . "/$file";
        }
a283 4
          if ($SEND_URL eq "true") {
            $diff .= ".diff?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
          }
          if ($SEND_DIFF eq "true") {
a284 1
          }
a298 4
                  if ($SEND_URL eq "true") {
                    $diff .= ".diff?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
d300 1
a300 1
                      || exec "$cvsbin/cvs", '-Qn', 'update', '-p', '-r1.1', $file;
d302 1
a302 2
                      . "=================================\n";
                  }
d305 1
a305 5
                  if ($SEND_URL eq "true") {
                    $diff .= ".diff?r1=$prev_rev&r2=$rev\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
                    $diff .= "(In the diff below, changes in quantity "
d308 2
a309 3
                      || exec "$cvsbin/cvs", '-Qn', 'diff', "$difftype",
                      '-b', "-r$prev_rev", "-r$rev", $file;
                  }
d312 1
a312 2
                if ($SEND_DIFF eq "true") {
                  while (<DIFF>) {
a313 2
                  }
                  close(DIFF);
d315 1
@


1.18.4.2
log
@corrected cut and paste error
@
text
@d301 1
a301 1
            $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
d321 1
a321 1
                    $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
@


1.17
log
@remove dependency on Helm::Database
@
text
@d174 13
@


1.16
log
@Resolved merge conflicts.
@
text
@a37 1
use Helm::Database;
d330 1
a330 1
    my $domain = $db->config('domain_dns');
d506 1
a506 2
$db = new Helm::Database;
$cvsbin = $db->config('cvs_cvsbin');
d511 1
a511 1
$HOST_DOMAIN = $db->config('domain_dns');
@


1.15
log
@Switched from context diffs to unidiffs.
@
text
@d78 3
a80 1
$CHANGED_FILE  = "$TMPDIR/${FILE_PREFIX}files.changed";
d340 16
a355 14
sub do_changes_file
{
    local($category, @@text) = @@_;
    local($changes);

    $changes = "$CVSROOT/CVSROOT/commitlogs/$category";
    if (open(CHANGES, ">>$changes")) {
        print(CHANGES join("\n", @@text), "\n\n");
        close(CHANGES);
    }
    else { 
        warn "Cannot open $changes: $!\n";
    }
}
d391 37
d510 7
d561 3
a563 1
    &do_changes_file($mlist, @@text);
d687 2
d692 3
a694 1
&do_changes_file($mlist, @@text);
@


1.14
log
@forget to check in -- FIX: for mail list problem
@
text
@d60 2
a61 2
# Set this to '-u' for unidiff format; defaults to '-c' for context diffs.
$difftype = '-c';
@


1.13
log
@Set EMULATE_LOCAL_USERS to be used by default.  Important people seem
to prefer this :).
@
text
@d83 1
d88 1
a88 1
$CVSBIN        = '/usr/local/bin';
a91 1
$MAIL_TO       = 'cvs';   # was user@@mycompany.com
d173 13
d392 2
a393 1
    local(@@text) = @@_;
d401 3
a403 1
    print "Mailing the commit message to $MAIL_TO (from $MAIL_FROM)\n";
d411 1
a411 1
    print MAIL "To: $MAIL_TO\n";
d495 5
a499 5
# Uncomment the following if we ever have per-repository cvs mail

 if (defined($mlist)) {
     $MAIL_TO = $mlist
 }
d514 1
a514 1
    &mail_notification(@@text) if defined($MAIL_TO);
d587 1
d616 1
d627 1
d659 5
d667 1
a667 1
&mail_notification(@@text) if defined($MAIL_TO);
@


1.12
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.11
date: 2000/08/30 01:29:38;  author: kfogel;  state: Exp;  lines: +8 -4
(derive_subject_from_changes_file): use \t to represent tab
characters, not the incorrect \i.
=============================================================================
@
text
@d58 1
a58 1
$EMULATE_LOCAL_MAIL_USER=""; 
@


1.11
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.10
date: 2000/07/29 01:44:06;  author: kfogel;  state: Exp;  lines: +3 -3
Change all "Tigris" ==> "Helm" and "tigris" ==> helm", as per Daniel
Rall's email about how the tigris path is probably obsolete.
=============================================================================
@
text
@d359 6
a364 2
      $change =~ s/^[ \i]*//;
      $change =~ /^([^ \i]+)[ \i]*/;
d366 1
a366 1
        $subj = $1;
d368 1
a368 1
        $subj .= ", $1"; 
@


1.10
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.9
date: 2000/07/29 01:12:26;  author: kfogel;  state: Exp;  lines: +22 -19
tweak derive_subject_from_changes_file()
=============================================================================
@
text
@d37 2
a38 2
use lib "__SANDBOX__/tigris/perl";
use Tigris::Database;
d446 1
a446 1
$db = new Tigris::Database;
@


1.9
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.8
date: 2000/07/29 00:53:50;  author: kfogel;  state: Exp;  lines: +33 -3
Make the email subject lines list all the directories in the commit,
and not talk about non-directories.

This is a roundabout fix for
http://www.netbeans.org/bugs-cgi/show_bug.cgi?id=7081.  If we actually
want the behavior described as "correct" by that bug report, we
perhaps shouldn't be using log_accum.pl.  However, that behavior --
sending a separate mail message for each directory involved in the
commit -- is counterintuitive, IMHO.  A single commit should produce a
single email, whose subject line summarizes the contents of the
commit.
=============================================================================
@
text
@d342 1
a342 2
  open (CH, "<$CHANGED_FILE.$i.$id.$cvs_user")
      or die ("trouble opening $CHANGED_FILE.$i.$id.$cvs_user ($!)");
d344 1
a344 2
  my $subj = "";
  while (my $change = <CH>)
d346 1
a346 8
    # A changes file looks like this:
    #
    #  src      foo.c newfile.html
    #  www      index.html project_nav.html
    #
    # Each line is " Dir File1 File2 ..."
    # We only care about Dir, since the subject line should
    # summarize. 
d348 18
a365 6
    $change =~ s/^[ \i]*//;
    $change =~ /^([^ \i]+)[ \i]*/;
    if ($subj eq "") {
      $subj = $1;
    } else {
      $subj .= " $1"; 
d367 1
a369 1
  close (CH);
@


1.8
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.7
date: 2000/07/29 00:31:42;  author: kfogel;  state: Exp;  lines: +2 -2
clarification
=============================================================================
@
text
@d340 30
d374 2
a376 1
        
a377 1
        
d389 1
a389 1
    print MAIL "Subject: $SUBJECT_PRE $ARGV[0]\n\n";
@


1.7
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.6
date: 2000/07/29 00:30:32;  author: kfogel;  state: Exp;  lines: +19 -0
Put in comments explaining how commit_prep and log_accum interact, and
how log_accum interacts with past and future invocations of itself.
=============================================================================
@
text
@d25 2
a26 2
# combines it with what it found out on this pass, and sends a commit
# message to the appropriate mailing list.
@


1.6
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.5
date: 2000/07/29 00:20:39;  author: kfogel;  state: Exp;  lines: +32 -99
Fixes for:
   http://www.netbeans.org/bugs-cgi/show_bug.cgi?id=7052
   http://www.netbeans.org/bugs-cgi/show_bug.cgi?id=6931

commitinfo now passes "-u $USER" to commit_prep.

commit_prep and log_accum now agree to append the committer's
cvs-username onto their tmp files, so overlapping commits by different
people don't get mixed up.
=============================================================================
@
text
@d11 19
@


1.5
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.4
date: 2000/07/28 23:54:28;  author: kfogel;  state: Exp;  lines: +9 -8
Incorporate tweaks found in the live `hocus:/cvs/CVSROOT/log_accum'.
Namely:

   + Look for Perl libs in __SANDBOX__/tigris/perl, not .../helm/perl.

   + Leave $ENV{'QMAILINJECT'} unset, instead of setting it to 'f'.

   + Pass -f (with sender arg) to the mail command.

   + Use Tigris::Database, not Helm::Database.

My intuition is that these changes needed incorporation in our dist,
but I'm not 100% sure.... Revert this change if it's not the case.
=============================================================================
@
text
@d30 1
a30 1
# 2 = rcsids in both mail and logs.
a35 1
#$CVSWEB = "";
d37 2
a38 2
# Set this to a domain to have CVS behave as though committer has a
# mail account in that domain.
d41 2
d58 1
a58 1
$LAST_FILE     = "$TMPDIR/${FILE_PREFIX}lastdir";
a82 70

# Get's the revision number of the given file or -1 if it doesn't have a 
# revision
sub getRevisionNumber {
 

    my($file) = @@_;
    
    if ($file EQ "") {
        print "Sorry.. you need to specify a file";
        return;
    }


        open(VERSION, "-|") || exec "$CVSBIN/cvs", '-Qqn', "-d$CVSROOT", 'status', "$file";
    

    while (<VERSION>) {

        local $tag = "Working revision:";
        
        if ( index( $_, $tag ) > -1 ) {
            $tmp = substr( $_, 21, length( $_ ) ); 

            $tmp = substr( $tmp, 0, index( $tmp, "\t") );

            if ( index( $tmp, "No entry for" ) > -1 ) {
                return -1;
            }
            
        }
    }

    
    close(VERSION);

    #make sure that this doesn't contain alpha chars... if it does... then 
    #return -1... this is a hack.

    if ( $tmp =~ /^[a-z]+$/ ) {
        return -1;
    }
    
    if ( $tmp =~ /^[A-Z]+$/ ) {
        return -1;
    }


    return $tmp;

    
}

sub getPrevRevisionNumber {
    
    my($number) = @@_;
    
    if ($number EQ "") {
        print "Sorry... you need to specify a rev number";
    }
    
    #this might not work on crazy version numbers.
    
    my($one, $two) = split( '\.', $number );
    
    $two = $two - 1;
    return "$one.$two";
    
}

d101 1
a101 1
    push(@@files, grep(/^${FILE_PREFIX}.*\.${id}$/, readdir(DIR)));
d259 2
d262 2
a263 2
                        || exec "$cvsbin/cvs", '-Qn', 'diff', '-u',
                              "-r$prev_rev", "-r$rev", $file;
d501 2
a502 2
    last if (! -e "$LOG_FILE.$i.$id");
    @@text = &read_logfile("$LOG_FILE.$i.$id", "");
d510 5
a514 5
&write_logfile("$LOG_FILE.$i.$id", @@log_lines);
&append_to_file("$BRANCH_FILE.$i.$id",  $dir, @@branch_lines);
&append_to_file("$ADDED_FILE.$i.$id",   $dir, @@added_files);
&append_to_file("$CHANGED_FILE.$i.$id", $dir, @@changed_files);
&append_to_file("$REMOVED_FILE.$i.$id", $dir, @@removed_files);
d516 1
a516 1
    &change_summary("$SUMMARY_FILE.$i.$id", (@@changed_files, @@added_files));
d522 2
a523 2
if (-e "$LAST_FILE.$id") {
   $_ = &read_line("$LAST_FILE.$id");
d546 5
a550 5
    last if (! -e "$LOG_FILE.$i.$id");
    push(@@text, &read_file("$BRANCH_FILE.$i.$id", "Branch:"));
    push(@@text, &read_file("$CHANGED_FILE.$i.$id", "Modified:"));
    push(@@text, &read_file("$ADDED_FILE.$i.$id", "Added:"));
    push(@@text, &read_file("$REMOVED_FILE.$i.$id", "Removed:"));
d552 1
a552 1
    push(@@text, &read_logfile("$LOG_FILE.$i.$id", "  "));
d554 1
a554 1
        if (-e "$SUMMARY_FILE.$i.$id") {
d557 1
a557 1
            push(@@text, &read_logfile("$SUMMARY_FILE.$i.$id", "  "));
d572 2
a573 2
        last if (! -e "$LOG_FILE.$i.$id");
        if (-e "$SUMMARY_FILE.$i.$id") {
d577 1
a577 1
            push(@@text, &read_logfile("$SUMMARY_FILE.$i.$id", ""));
@


1.4
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.3
date: 2000/07/12 05:41:04;  author: ryan;  state: Exp;  lines: +1 -1
replaced hardcoded host name with __HOSTNAME__
=============================================================================
@
text
@d18 2
a19 2
use lib "__SANDBOX__/helm/perl";
use Helm::Database;
d38 3
a40 3
$EMULATE_LOCAL_MAIL_USER="";            #set this to have CVS pretend that all
                                        #users that make commits have mail 
                                        #accounts within a specified domain.
d401 2
a402 1
    $ENV{'QMAILINJECT'} = 'f';
d404 1
a404 1
    open(MAIL, $MAIL_CMD);
d461 1
a461 1
$db = new Helm::Database;
@


1.3
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.2
date: 2000/04/21 09:17:34;  author: manoj;  state: Exp;  lines: +1 -1
fix location of helm perl stuff
=============================================================================
@
text
@d35 1
a35 1
$CVSWEB = "http://www.tigris.org/source/browse/";
@


1.2
log
@
merge revision history for cvspatches/root/log_accum.in
----------------------------
revision 1.1
date: 2000/04/20 21:51:52;  author: jrobbins;  state: Exp;
initial checkin of new commit logging script
=============================================================================
@
text
@d18 1
a18 1
use lib "__SANDBOX__/perl";
@


1.1
log
@Moved here from sandbox/tigrisc/repository/CVSROOT and redone.
@
text
@d18 1
a18 1
use lib "__SANDBOX__/helm/perl";
d34 3
a36 3
# If you are using CVS web then set this to some value... if not set it to ""
# NOTE: Not currently used.
#$CVSWEB = "http://test.__DOMAIN__/source/browse";
d67 1
a67 1
$CVSBIN        = '/usr/bin';
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@a10 19
# IMPORTANT: what the above means is, this script interacts with
# commit_prep, in that they have to agree on the tmpfile name to use.
# See $LAST_FILE below. 
#
# How this works: CVS triggers this script once for each directory
# involved in the commit -- in other words, a single commit can invoke
# this script N times.  It knows when it's on the last invocation by
# examining the contents of $LAST_FILE.  Between invocations, it
# caches information for its future incarnations in various temporary
# files in /tmp, which are named according to the process group and
# the committer (by themselves, neither of these are unique, but
# together they almost always are, unless the same user is doing two
# commits simultaneously).  The final invocation is the one that
# actually sends the mail -- it gathers up the cached information,
# combines that with what it found out on this pass, and sends a
# commit message to the appropriate mailing list.
#
# (Ask Karl Fogel <kfogel@@collab.net> if questions.)
#
d30 1
a30 1
# 2 = in both mail and logs.
d34 7
a40 2
#if you are using CVS web then set this to some value... if not set it to ""
$CVSWEB = "http://__HOSTNAME__/source/browse/";
a41 6
# Set this to a domain to have CVS pretend that all users who make
# commits have mail accounts within that domain.
$EMULATE_LOCAL_MAIL_USER="__DOMAIN__"; 

# Set this to '-c' for context diffs; defaults to '-u' for unidiff format.
$difftype = '-u';
d57 2
a58 4
$LAST_FILE     = "$TMPDIR/${FILE_PREFIX}lastdir";  # Created by commit_prep!
### <npm:removed>
#$CHANGED_FILE  = "$TMPDIR/${FILE_PREFIX}files.changed";
### </npm>
a62 1
$MLIST_FILE    = "$TMPDIR/${FILE_PREFIX}files.mlist";
d71 1
d82 70
d170 1
a170 1
    push(@@files, grep(/^${FILE_PREFIX}.*\.${id}\.${cvs_user}$/, readdir(DIR)));
a222 13
sub read_file_lines {
    local($filename) = @@_;
    local(@@text) = ();

    open(FILE, "<$filename") || return ();
    while (<FILE>) {
        chomp;
        push(@@text, $_);
    }
    close(FILE);
    @@text;
}

a327 2
                  $diff .= "(In the diff below, changes in quantity "
                      . "of whitespace are not shown.)\n\n";
d329 2
a330 2
                        || exec "$cvsbin/cvs", '-Qn', 'diff', "$difftype",
                                '-b', "-r$prev_rev", "-r$rev", $file;
d373 1
a373 18
### <npm:removed>
#sub do_changes_file
#{
#    local($category, @@text) = @@_;
#    local($changes);
#
#    $changes = "$CVSROOT/CVSROOT/commitlogs/$category";
#    if (open(CHANGES, ">>$changes")) {
#        print(CHANGES join("\n", @@text), "\n\n");
#        close(CHANGES);
#    }
#    else { 
#        warn "Cannot open $changes: $!\n";
#    }
#}
### </npm>

sub derive_subject_from_changes_file ()
d375 2
a376 1
  my $subj = "";
d378 8
a385 68
  for ($i = 0; ; $i++)
  {
    open (CH, "<$CHANGED_FILE.$i.$id.$cvs_user") or last;

    while (my $change = <CH>)
    {
      # A changes file looks like this:
      #
      #  src      foo.c newfile.html
      #  www      index.html project_nav.html
      #
      # Each line is " Dir File1 File2 ..."
      # We only care about Dir, since the subject line should
      # summarize. 
      
      $change =~ s/^[ \t]*//;
      $change =~ /^([^ \t]+)[ \t]*/;
      my $dir = $1;
      # Fold to rightmost directory component
      $dir =~ /([^\/]+)$/;
      $dir = $1;
      if ($subj eq "") {
        $subj = $dir;
      } else {
        $subj .= ", $dir"; 
      }
    }
    close (CH);
  }

###<npm:added>
  if ($subj ne "") {
      $subj = "MODIFIED: $subj ..."; 
  }
  else {
      # NPM: See if there's any file-addition notifications.
      my $added = &read_line_nodie("$ADDED_FILE.$i.$id.$cvs_user");
      if ($added ne "") {
          $subj .= "ADDED: $added "; 
      }
    
#    print "derive_subject_from_changes_file().. added== $added \n";
    
       ## NPM: See if there's any file-removal notications.
      my $removed = &read_line_nodie("$REMOVED_FILE.$i.$id.$cvs_user");
      if ($removed ne "") {
          $subj .= "REMOVED: $removed "; 
      }
    
#    print "derive_subject_from_changes_file().. removed== $removed \n";
    
      ## NPM: See if there's any branch notifications.
      my $branched = &read_line_nodie("$BRANCH_FILE.$i.$id.$cvs_user");
      if ($branched ne "") {
          $subj .= "BRANCHED: $branched"; 
      }
    
#    print "derive_subject_from_changes_file().. branched== $branched \n";
    
      ## NPM: DEFAULT: DIRECTORY CREATION (c.f. "Check for a new directory first" in main mody)
      if ($subj eq "") {
          my $subject = join("/", @@path);
          $subj = "NEW: $subject"; 
      }    
  }
###</npm>

  return $subj;
d390 1
a390 4
    local($addr_list, @@text) = @@_;
    local($mail_to);

    my $subj = &derive_subject_from_changes_file ();
d393 1
d395 1
d398 1
a398 3
    $mail_to = join(", ", @@{$addr_list});

    print "Mailing the commit message to $mail_to (from $MAIL_FROM)\n";
d401 1
a401 2
    # Commented out on hocus, so comment it out here.  -kff
    # $ENV{'QMAILINJECT'} = 'f';
d403 1
a403 1
    open(MAIL, "$MAIL_CMD -f$MAIL_FROM");
d405 2
a406 2
    print MAIL "To: $mail_to\n";
    print MAIL "Subject: $SUBJECT_PRE $subj\n\n";
a462 7
###<npm:add>
# NPM: derive host's domain name from DB, setup EMULATE_LOCAL_MAIL_USER so
# that commitlogger mail is sent as if from <cvsuser>@@<hostdomain>
$HOST_DOMAIN = $db->config('domain_dns');
$EMULATE_LOCAL_MAIL_USER = "$HOST_DOMAIN";
###</npm>

d489 5
a493 5
# (dead code) Uncomment the following if we ever have per-repository cvs mail
#
# if (defined($mlist)) {
#     $MAIL_TO = $mlist
# }
d507 2
a508 4
###<npm:remove>
##    &do_changes_file($mlist, @@text);
###</npm>
    &mail_notification([ $mlist ], @@text);
d567 2
a568 2
    last if (! -e "$LOG_FILE.$i.$id.$cvs_user");
    @@text = &read_logfile("$LOG_FILE.$i.$id.$cvs_user", "");
d576 5
a580 6
&write_logfile("$LOG_FILE.$i.$id.$cvs_user", @@log_lines);
&append_to_file("$BRANCH_FILE.$i.$id.$cvs_user",  $dir, @@branch_lines);
&append_to_file("$ADDED_FILE.$i.$id.$cvs_user",   $dir, @@added_files);
&append_to_file("$CHANGED_FILE.$i.$id.$cvs_user", $dir, @@changed_files);
&append_to_file("$REMOVED_FILE.$i.$id.$cvs_user", $dir, @@removed_files);
&append_line("$MLIST_FILE.$i.$id.$cvs_user", $mlist);
d582 1
a582 1
    &change_summary("$SUMMARY_FILE.$i.$id.$cvs_user", (@@changed_files, @@added_files));
d588 2
a589 2
if (-e "$LAST_FILE.$id.$cvs_user") {
   $_ = &read_line("$LAST_FILE.$id.$cvs_user");
a608 1
@@mlist_list = ();
d612 5
a616 5
    last if (! -e "$LOG_FILE.$i.$id.$cvs_user");
    push(@@text, &read_file("$BRANCH_FILE.$i.$id.$cvs_user", "Branch:"));
    push(@@text, &read_file("$CHANGED_FILE.$i.$id.$cvs_user", "Modified:"));
    push(@@text, &read_file("$ADDED_FILE.$i.$id.$cvs_user", "Added:"));
    push(@@text, &read_file("$REMOVED_FILE.$i.$id.$cvs_user", "Removed:"));
d618 1
a618 2
    push(@@text, &read_logfile("$LOG_FILE.$i.$id.$cvs_user", "  "));
    push(@@mlist_list, &read_file_lines("$MLIST_FILE.$i.$id.$cvs_user"));
d620 1
a620 1
        if (-e "$SUMMARY_FILE.$i.$id.$cvs_user") {
d623 1
a623 1
            push(@@text, &read_logfile("$SUMMARY_FILE.$i.$id.$cvs_user", "  "));
a627 2

###<npm:remove>
d631 1
a631 3
#&do_changes_file($mlist, @@text);
###</npm>

d638 2
a639 2
        last if (! -e "$LOG_FILE.$i.$id.$cvs_user");
        if (-e "$SUMMARY_FILE.$i.$id.$cvs_user") {
d643 1
a643 1
            push(@@text, &read_logfile("$SUMMARY_FILE.$i.$id.$cvs_user", ""));
a649 5

%mlist_hash = ();

foreach (@@mlist_list) { $mlist_hash{ $_ } = 1; }

d653 1
a653 1
&mail_notification([ keys(%mlist_hash) ], @@text);
@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d38 1
d54 1
a54 7
$CVSWEB_SCHEME = "__HTTP_SCHEME__";
$CVSWEB_DOMAIN = "__DOMAIN__";
$CVSWEB_PORT = "__APACHE_PORT__";
$CVSWEB_URI = "source/browse/";
$SEND_URL = "__LOG_ACCUM_SEND_URL__";
$SEND_DIFF = "__LOG_ACCUM_SEND_DIFF__";

a174 13
#<npm:added>
sub read_line_nodie {
    local($filename) = @@_;
    local($line);
    open(FILE, "<$filename") || return ("");

    $line = <FILE>;
    close(FILE);
    chomp($line);
    $line;
}
#</npm>

d221 1
a221 1
    local($file, $rev, $rcsfile, $line, $vhost, $cvsweb_base);
a263 10
        $vhost = @@path[0];
        if ($CVSWEB_PORT eq "80") {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN/$CVSWEB_URI";
        }
        else {
          $cvsweb_base = "$CVSWEB_SCHEME://$vhost.$CVSWEB_DOMAIN:$CVSWEB_PORT/$CVSWEB_URI";
        }
        if ($SEND_URL eq "true") {
          $diff .= $cvsweb_base . join("/", @@path) . "/$file";
        }
a271 4
          if ($SEND_URL eq "true") {
            $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
          }
          if ($SEND_DIFF eq "true") {
a272 1
          }
a286 4
                  if ($SEND_URL eq "true") {
                    $diff .= "?rev=$rev&content-type=text/x-cvsweb-markup\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
d288 1
a288 1
                      || exec "$cvsbin/cvs", '-Qn', 'update', '-p', '-r1.1', $file;
d290 1
a290 2
                      . "=================================\n";
                  }
d293 1
a293 5
                  if ($SEND_URL eq "true") {
                    $diff .= ".diff?r1=$prev_rev&r2=$rev\n\n";
                  }
                  if ($SEND_DIFF eq "true") {
                    $diff .= "(In the diff below, changes in quantity "
d296 2
a297 3
                      || exec "$cvsbin/cvs", '-Qn', 'diff', "$difftype",
                      '-b', "-r$prev_rev", "-r$rev", $file;
                  }
d300 1
a300 2
                if ($SEND_DIFF eq "true") {
                  while (<DIFF>) {
a301 2
                  }
                  close(DIFF);
d303 1
d331 1
a331 1
    my $domain = "__DOMAIN__";
d507 2
a508 1
$cvsbin = "/usr/bin";
d513 1
a513 1
$HOST_DOMAIN = "__DOMAIN__";
@


