File:  [NetBSD Developer Wiki] / CVSROOT / commit_prep
Revision 1.5: download - view: text, annotated - select for diffs
Sun Dec 22 10:17:40 2013 UTC (8 years, 1 month ago) by spz
Branches: MAIN
CVS tags: HEAD
fix for new usage

#! /usr/pkg/bin/perl
# -*-Perl-*-
#
# Copyright (c) 2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#        This product includes software developed by the NetBSD
#        Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#ident	"@(#)cvs/contrib:$NetBSD: commit_prep,v 1.5 2013/12/22 10:17:40 spz Exp $"
#
# Perl filter to handle pre-commit checking of files.  This program
# records the last directory where commits will be taking place for
# use by the log_accum.pl script.  Also check for unresolved merge
# conflicts.
#
# Contributed by David Hampton <hampton@cisco.com>
# Hacked on lots by Greg A. Woods <woods@web.net>
# Further hacked by Charles M. Hannum <mycroft@netbsd.org>

#
#	Configurable options
#

# Check each file (except dot files)
#
$check_conflicts = 0;

# Constants (remember to protect strings from RCS keyword substitution)
#
$LAST_FILE     = "/tmp/#cvs.lastdir"; # must match name in log_accum.pl

#
#	Subroutines
#

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

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

sub check_conflicts {
    local($directory, $filename) = @_;

    if (open(FILE, "<$filename")) {
	while (<FILE>) {
	    if (/^<<<<<<<$/ || /^>>>>>>>$/) {
		print $directory . "/" . $filename . ":\n";
		print "  This file contains unresolved merge conflicts.\n";
		return(1);
	    }
	}
    }
    close(FILE);
    return(0);
}

#
#	Main Body	
#

$id = getpgrp();		# You *must* use a shell that does setpgrp()!

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

# Get the root of the CVS tree.
#
$cvsroot = $ENV{'CVSROOT'};
#printf "root = " . $cvsroot . "\n";

# parse command line arguments
#
while (@ARGV) {
    $arg = shift @ARGV;

    if ($arg eq '-d') {
	$debug = 1;
	print STDERR "Debug turned on...\n";
    } elsif ($arg eq '-c') {
	$check_conflicts = 1;
    } elsif ($arg eq '-r') {
	$record_directory = 1;
    } else {
	push(@files, split(' ', $arg));
    }
}

$directory = shift @files;
$directory =~ s,$cvsroot/,,;

if ($debug != 0) {
    print STDERR "dir   - ", $directory, "\n";
    print STDERR "files - ", join(":", @files), "\n";
    print STDERR "id    - ", $id, "\n";
}

# Now check each file name passed in for unresolved merge conflicts.
#
if ($check_conflicts != 0) {
    $failed = 0;
    foreach $filename (@files) {
	$failed += &check_conflicts($directory, $filename);
    }
    if ($failed != 0) {
	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);

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb