aboutsummaryrefslogtreecommitdiffstats
path: root/CVSROOT/cvsedit
blob: 89010cf89ee551b0ddfe14a758733a2b1440e96f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/perl
# 
# This crude hack is to sanitise the results of what the user may have
# "done" while editing the commit log message.. :-)   Peter Wemm.
#
# To use this, make it executable, and set your editinfo DEFAULT line:
# DEFAULT   /path/to/this/program
#
# $Id: cvsedit,v 1.5 1995/08/13 16:38:07 peter Exp $
#

# same rules as CVS
$editor="vi";
if (defined $ENV{'EDITOR'}) {       # $EDITOR overrides default
    $editor = $ENV{'EDITOR'};
}
if (defined $ENV{'CVSEDITOR'}) {    # $CVSEDITOR overrises $EDITOR
    $editor = $ENV{'CVSEDITOR'};
}

if (!@ARGV) {
    die "Usage: cvsedit filename\n";
}
$filename = $ARGV[0];
$tmpfile = $filename . "tmp";

$retcode = system("$editor $filename");
$retcode /= 256;

if ($retcode) {
    # Kaboom!
    exit($retcode);
}

open(IN, "< $filename") ||
    die "cvsedit: Cannot open for reading: $filename: $!\n";

open(OUT, "> $tmpfile") ||
    die "cvsedit: Cannot open for writing: $tmpfile: $!\n";

# In-place edit the result of the user's edit on the file.
$blank = 0; # true if the last line was blank
$first = 0; # true if we have seen the first real text
while(<IN>) {

    # Dont let CVS: lines upset things, but maintain them in case
    # the editor is re-entered.  NO CHANGES!!
    if (/^CVS:/) {
        print OUT;
        next;
    }

    chop;       # strip trailing newline
    s/[\s]+$//; # strip trailing whitespace

    # collapse multiple blank lines, and trailing blank lines.
    if (/^$/) {
        # Blank line. Remember in case more text follows.
        $blank = 1;
        next;
    } else {
        # Delete if they only have whitespace after them.
        if (/^Reviewed by:$/i ||
            /^Submitted by:$/i ||
            /^Obtained from:$/i ||
            /^CC:$/i) {
            next;
        }
        if ($blank && $first) {
            # Previous line(s) was blank, this isn't. Close the
            # collapsed section.
            print OUT "\n";
        }
        $blank = 0; # record non-blank
        $first = 1; # record first line
        print OUT "$_\n";
    }
}
close(IN);
close(OUT);

# sanity check...
if (!$first) {
    die("cvsedit: Empty log message not permitted!\n");
}

unlink($filename . "~");    # Nuke likely editor backups..
unlink($filename . ".bak"); # Nuke likely editor backups..

# Check to see if any differences. preserve stat() info if not.
$different = system("cmp -s $tmpfile $filename");
if (!$different) {
    unlink($tmpfile);
    exit(0);
}

rename("$tmpfile", "$filename") ||
    die("cvsedit: Could not rename $tmpfile to $filename: $!");

exit(0);