[BACK]Return to commit_prep.pl CVS log [TXT][DIR] Up to [local] / CVSROOT

File: [local] / CVSROOT / commit_prep.pl (download)

Revision 1.7, Sat Sep 27 14:24:42 2003 UTC (20 years, 7 months ago) by maekawa
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +2 -2 lines

fix CVSROOT.

#!/usr/bin/perl -w
#
# $OpenXM: CVSROOT/commit_prep.pl,v 1.7 2003/09/27 14:24:42 maekawa Exp $
#
# Most parts obtained from FreeBSD.org and modified for OpenXM
#

require 5.003;	# to be sure.  log_accum needs perl5

############################################################
#
# Configurable options
#
############################################################
#
# Check each file (except dot files) for an RCS "OpenXM" keyword.
#
$check_id = 0;

#
# Record the directory for later use by the log_accumulate stript.
#
$record_directory = 1;

############################################################
#
# Constants
#
############################################################
$LAST_FILE     = "/tmp/#cvs.files.lastdir";
$ENTRIES       = "CVS/Entries";

$NoId = "
%s - Does not contain a line with the keyword \"\$OpenXM:\".\n";

# Protect string from substitution by RCS.
$NoName = "
%s - The ID line should contain only \"\$\OpenXM\$\" for a newly created file.\n";

$BadId = "%s - The \$\OpenXM\$ is mangled.\n";

#$BadName = "
#%s - The pathname '%s'
#    in the \$\OpenXM\$ line does not match the actual filename.\n";

$BadVersion = "
%s - GRRR!!  You spammed your copy of the file
    which was based upon version %s, with a different version based
    upon %s.  Please move your '%s' out of the way,
    perform an update to get the current version, and then
    CAREFULLY merge your changes into that file.\n";

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

sub write_line {
    local($filename, $line) = @_;
    open(FILE, ">$filename") || die("Cannot open $filename, stopped");
    print(FILE $line, "\n");
    close(FILE);
}

sub check_version {
    local($id, $rname, $version, $bareid);
    local($filename, $directory, $hastag, $cvsversion) = @_;

    if (! -f $filename) {
	return(0);	# not present - either removed or let cvs deal with it.
    }
    open(FILE, $filename) || die("Cannot open $filename, stopped");
    # requiring the header within the first 'n' lines isn't useful.
    while (1) {
	$pos = -1;
	last if eof(FILE);
	$line = <FILE>;
	$pos = index($line, "\$\OpenXM");
	last if ($pos >= 0);
    }

    if ($pos == -1) {
	printf($NoId, $filename);
	return(0);
    }
    $bareid = (index($line, "\$\OpenXM: \$") >= 0 ||
		index($line, "\$\OpenXM\$") >= 0);
    if (!$bareid && $line !~ /\$\OpenXM: .* \$/) {
	printf($BadId, $filename);
	return(1);
    }
    # Ignore version mismatches (MFC spamming etc) on branches.
    if ($hastag) {
	return (0);
    }
    ($id, $rname, $version) = split(' ', substr($line, $pos));
    if ($cvsversion{$filename} == 0) {
	if (!$bareid) {
	    printf($NoName, $filename);
	    return(1);
	}
	return(0);
    }
    if ($bareid) {
	return (0);
    }
    if ($cvsversion{$filename} ne $version) {
	printf($BadVersion, $filename, $cvsversion{$filename},
	       $version, $filename);
	return(1);
    }
    return(0);
}

#############################################################
#
# Main Body
#
############################################################

$id = getpgrp();
#print("ARGV - ", join(":", @ARGV), "\n");
#print("id   - ", id, "\n");

#
# Suck in the Entries file
#
open(ENTRIES, $ENTRIES) || die("Cannot open $ENTRIES.\n");
while (<ENTRIES>) {
    chop;
    next if (/^D/);
    local($filename, $version, $stamp, $opt, $tag) = split('/', substr($_, 1));
    $cvsversion{$filename} = $version;
    $cvstag{$filename} = $tag;
    $stamp = $opt;	#silence -w
}
close(ENTRIES);

$directory = $ARGV[0];
shift @ARGV;

$cvsroot=$ENV{'CVSROOT'} || "/home/cvsroot/openxm";
$directory =~ s,^$cvsroot[/]+,,;

if ($directory =~ /^OpenXM/) {
	$check_id = 1;
}
if ($check_id != 0 && $ENV{'CVSFUBAR'}) {
	$check_id = 0;
	print "CVS VERSION CHECK BYPASSED!\n";
	system("ps -xww | mail -s 'version check override used' cvs");
}
#
# Now check each file name passed in, except for dot files.  Dot files
# are considered to be administrative files by this script.
#
if ($check_id != 0) {
    $failed = 0;
    foreach $arg (@ARGV) {
	local($hastag) = ($cvstag{$arg} ne '');
	next if (index($arg, ".") == 0);
	next if (index($arg, "pkg-") == 0);
	next if ($arg =~ /^distinfo$/);
	$failed += &check_version($arg, $directory, $hastag, $cvsversion);
    }
    if ($failed) {
	print "\n";
	unlink("$LAST_FILE.$id");
	exit(1);
    }
}

#
# Record this directory as the last one checked.  This will be used
# by the log_accumulate script to determine when it is processing
# the final directory of a multi-directory commit.
#
if ($record_directory != 0) {
    &write_line("$LAST_FILE.$id", $directory);
}
exit(0);