5 # Perl filter to handle pre-commit checking of files. This program
6 # records the last directory where commits will be taking place for
7 # use by the log_accum.pl script. For new files, it forces the
8 # existence of a RCS "Id" keyword in the first ten lines of the file.
9 # For existing files, it checks version number in the "Id" line to
10 # prevent losing changes because an old version of a file was copied
13 # Possible future enhancements:
15 # Check for cruft left by unresolved conflicts. Search for
16 # "^<<<<<<<$", "^-------$", and "^>>>>>>>$".
18 # Look for a copyright and automagically update it to the
19 # current year. [[ bad idea! -- woods ]]
22 # Contributed by David Hampton <hampton@cisco.com>
24 # Hacked on lots by Greg A. Woods <woods@web.net>
27 # Configurable options
30 # Constants (remember to protect strings from RCS keyword substitution)
32 $LAST_FILE = "/tmp/#cvs.lastdir"; # must match name in log_accum.pl
33 $ENTRIES = "CVS/Entries";
35 # Patterns to find $Log keywords in files
37 $LogString1 = "\\\$\\Log: .* \\\$";
38 $LogString2 = "\\\$\\Log\\\$";
39 $NoLog = "%s - contains an RCS \$Log keyword. It must not!\n";
41 # pattern to match an RCS Id keyword line with an existing ID
43 $IDstring = "\"@\\(#\\)[^:]*:.*\\\$\Id: .*\\\$\"";
45 %s - Does not contain a properly formatted line with the keyword \"Id:\".
46 I.e. no lines match \"" . $IDstring . "\".
47 Please see the template files for an example.\n";
49 # pattern to match an RCS Id keyword line for a new file (i.e. un-expanded)
51 $NewId = "\"@(#)[^:]*:.*\\$\Id\\$\"";
54 %s - The ID line should contain only \"@(#)module/path:\$Name\$:\$\Id\$\"
55 for a newly created file.\n";
58 %s - The file name '%s' in the ID line does not match
59 the actual filename.\n";
62 %s - How dare you!!! You replaced your copy of the file '%s',
63 which was based upon version %s, with an %s version based
64 upon %s. Please move your '%s' out of the way, perform an
65 update to get the current version, and them merge your changes
66 into that file, then try the commit again.\n";
73 local($filename, $line) = @_;
74 open(FILE
, ">$filename") || die("Cannot open $filename, stopped");
75 print(FILE
$line, "\n");
80 local($i, $id, $rname, $version);
81 local($filename, $cvsversion) = @_;
83 open(FILE
, "<$filename") || return(0);
88 for ($i = 0; <FILE
>; $i++) {
91 if ($_ =~ /$IDstring/) {
99 if (grep(/$LogString1/, @all_lines) || grep(/$LogString2/, @all_lines)) {
100 print STDERR
sprintf($NoLog, $filename);
105 print STDERR
sprintf("file = %s, version = %d.\n", $filename, $cvsversion{$filename});
108 if ($cvsversion{$filename} == 0) {
109 if ($newidpos != -1 && $all_lines[$newidpos] !~ /$NewId/) {
110 print STDERR
sprintf($NoName, $filename);
117 print STDERR
sprintf($NoId, $filename);
121 $line = $all_lines[$idpos];
122 $pos = index($line, "Id: ");
124 print STDERR
sprintf("%d in '%s'.\n", $pos, $line);
126 ($id, $rname, $version) = split(' ', substr($line, $pos));
127 if ($rname ne "$filename,v") {
128 print STDERR
sprintf($BadName, $filename, substr($rname, 0, length($rname)-2));
131 if ($cvsversion{$filename} < $version) {
132 print STDERR
sprintf($BadVersion, $filename, $filename, $cvsversion{$filename},
133 "newer", $version, $filename);
136 if ($cvsversion{$filename} > $version) {
137 print STDERR
sprintf($BadVersion, $filename, $filename, $cvsversion{$filename},
138 "older", $version, $filename);
148 $id = getpgrp(); # You *must* use a shell that does setpgrp()!
150 # Check each file (except dot files) for an RCS "Id" keyword.
154 # Record the directory for later use by the log_accumulate stript.
156 $record_directory = 0;
158 # parse command line arguments
165 print STDERR
"Debug turned on...\n";
166 } elsif ($arg eq '-c') {
168 } elsif ($arg eq '-r') {
169 $record_directory = 1;
175 $directory = shift @files;
178 print STDERR
"dir - ", $directory, "\n";
179 print STDERR
"files - ", join(":", @files), "\n";
180 print STDERR
"id - ", $id, "\n";
183 # Suck in the CVS/Entries file
185 open(ENTRIES
, $ENTRIES) || die("Cannot open $ENTRIES.\n");
187 local($filename, $version) = split('/', substr($_, 1));
188 $cvsversion{$filename} = $version;
191 # Now check each file name passed in, except for dot files. Dot files
192 # are considered to be administrative files by this script.
194 if ($check_id != 0) {
196 foreach $arg (@files) {
197 if (index($arg, ".") == 0) {
200 $failed += &check_version
($arg);
208 # Record this directory as the last one checked. This will be used
209 # by the log_accumulate script to determine when it is processing
210 # the final directory of a multi-directory commit.
212 if ($record_directory != 0) {
213 &write_line
("$LAST_FILE.$id", $directory);