$Text::Wrap::unexpand = 0;
# Global variables
-my (@files) = ();
-my (@ebuilds) = ();
-my (@conflicts) = ();
-my (@unknown) = ();
+my (@files, @ebuilds, @conflicts, @trivial, @unknown, @new_versions, %actions);
my ($input, $editor, $entry, $user, $date, $text, $version, $year);
-my (@new_versions) = ();
-my (%actions) = ();
# Read the current ChangeLog
if (-f 'ChangeLog') {
# Figure out what has changed around here
open C, 'cvs -fn up 2>&1 |' or die "Can't run cvs -fn up: $!\n";
while (<C>) {
- /ChangeLog/ and next;
- /^\? (\S+)/ and do { push @unknown, $1; next; };
- /^C (\S+)/ and do { push @conflicts, $1; next; };
- /^([ARM]) (\S+)/ or next;
- push @files, $2;
- ($actions{$2} = $1) =~ tr/ARM/+-/d;
+ if (/^C (\S+)/) {
+ push @conflicts, $1;
+ next;
+ } elsif (/^\? (\S+)/) {
+ push @unknown, $1;
+ $actions{$1} = '+';
+ next;
+ } elsif (/^([ARM]) (\S+)/) {
+ push @files, $2;
+ ($actions{$2} = $1) =~ tr/ARM/+-/d;
+ }
}
+
+# Separate out the trivial files for now
+@files = grep {
+ !/files.digest|Manifest|ChangeLog/ or do { push @trivial, $_; 0; }
+} @files;
+@unknown = grep {
+ !/files.digest|Manifest|ChangeLog/ or do { push @trivial, $_; 0; }
+} @unknown;
+
+# Don't allow any conflicts
if (@conflicts) {
print STDERR <<EOT;
Cvs reports the following conflicts. Please resolve them before
print STDERR map "C $_\n", @conflicts;
exit 1;
}
-@unknown = grep !/files.digest|Manifest/, @unknown;
+
+# Don't allow unknown files (other than the trivial files that were separated
+# out above)
if (@unknown) {
print STDERR <<EOT;
Cvs reports the following unknown files. Please use "cvs add" before
# Allow ChangeLog entries with no changed files, but give a fat warning
unless (@files) {
print STDERR "**\n";
- print STDERR "** NOTE: No changed files found. Normally echangelog should\n";
- print STDERR "** be run after all affected files have been added and/or\n";
+ print STDERR "** NOTE: No non-trivial changed files found. Normally echangelog\n";
+ print STDERR "** should be run after all affected files have been added and/or\n";
print STDERR "** modified. Did you forget to cvs add?\n";
print STDERR "**\n";
- @files = qw/ChangeLog/; # per request from Donnie Berkholz
+ @files = sort sortfunc @trivial;
+ @files = qw/ChangeLog/ unless @files; # last resort to put something in the list
}
# Get the input from the cmdline, editor or stdin
$editor = defined($ENV{'ECHANGELOG_EDITOR'}) ? $ENV{'ECHANGELOG_EDITOR'} :
$ENV{'EDITOR'} || undef;
if ($editor) {
- system("$editor .#ChangeLog");
+ system("$editor ChangeLog.new");
if ($? != 0) {
# This usually happens when the editor got forcefully killed; and
# the terminal is probably messed up: so we reset things.
print STDERR "Editor died! Reverting to stdin method.\n";
undef $editor;
} else {
- if (open I, "<.#ChangeLog") {
+ if (open I, "<ChangeLog.new") {
local $/ = undef;
$input = <I>;
close I;
} else {
- print STDERR "Error opening .#ChangeLog: $!\n";
+ print STDERR "Error opening ChangeLog.new: $!\n";
print STDERR "Reverting to stdin method.\n";
undef $editor;
}
- unlink '.#ChangeLog';
+ unlink 'ChangeLog.new';
}
}
unless ($editor) {
die "Please set ECHANGELOG_USER or run as non-root\n" if $user =~ /<root@/;
$date = strftime("%d %b %Y", gmtime);
$entry = "$date; $user ";
-$entry .= join ', ', map "$actions{$_}$_", grep !/files.digest|Manifest/, @files;
+$entry .= join ', ', map "$actions{$_}$_", @files;
$entry .= ':';
$entry = Text::Wrap::fill(' ', ' ', $entry); # does not append a \n
$entry .= "\n$input"; # append user input