Add some useful informations when using $EDITOR.
authoridl0r <idl0r@gentoo.org>
Tue, 5 May 2009 03:50:36 +0000 (03:50 -0000)
committeridl0r <idl0r@gentoo.org>
Tue, 5 May 2009 03:50:36 +0000 (03:50 -0000)
svn path=/; revision=587

trunk/src/echangelog/echangelog

index 7a7cbf4e3aec84076748e202121fbb7805d9cbd5..551d9b9a461d1afbad6cdf3406a4546757ca0388 100755 (executable)
@@ -94,6 +94,14 @@ sub getenv($) {
 # The only modified thing is:
 # We trim _just_ tab/space etc. but not \n/\r.
 # \s treats even \n/\r as whitespace.
+# BUGS:
+# ' test'
+# ' test'
+# Will end up in:
+# ' test'
+# ''
+# 'test'
+# See 'my $ps = ($ip eq $xp) ? "\n\n" : "\n";'
 sub text_fill {
        my ($ip, $xp, @raw) = @_;
        my @para;
@@ -111,6 +119,31 @@ sub text_fill {
        return join ($ps, @para);
 }
 
+sub changelog_info(%) {
+       my %changed = @_;
+
+       open(INFO, '>', 'ChangeLog.new');
+
+       print(INFO "\n");
+       print(INFO "# Please enter the ChangeLog message for your changes. Lines starting\n");
+       print(INFO "# with '#' will be ignored, and an empty message aborts the ChangeLog.\n");
+       print(INFO "#\n# Changes:\n");
+
+       foreach my $key (keys(%changed)) {
+               if ($changed{$key} eq "+") {
+                       printf(INFO "# new file:\t%s\n", $key);
+               }
+               elsif ($changed{$key} eq "-") {
+                       printf(INFO "# deleted:\t%s\n", $key);
+               }
+               else {
+                       printf(INFO "# modified:\t%s\n", $key);
+               }
+       }
+
+       close(INFO);
+}
+
 GetOptions(
        'help' => \$opt_help,
        'strict' => \$opt_strict,
@@ -497,6 +530,9 @@ if ($ARGV[0]) {
        $editor = getenv('ECHANGELOG_EDITOR') ? getenv('ECHANGELOG_EDITOR') : getenv('EDITOR') || undef;
 
        if ($editor) {
+               # Append some informations.
+               changelog_info(%actions);
+
                system("$editor ChangeLog.new");
 
                if ($? != 0) {
@@ -509,15 +545,19 @@ if ($ARGV[0]) {
                        if (open I, "<ChangeLog.new") {
                                local $/ = undef;
                                $input = <I>;
-                               close I;
+                               close(I);
+
+                               # Remove comments from changelog_info().
+                               local $/ = "\n";
+                               $input =~ s/^#.*//mg;
+                               local $/ = undef;
                        } else {
                                print STDERR "Error opening ChangeLog.new: $!\n";
                                print STDERR "Reverting to stdin method.\n";
                                undef $editor;
                        }
-
-                       unlink('ChangeLog.new') if -f 'ChangeLog.new';
                }
+               unlink('ChangeLog.new') if -f 'ChangeLog.new';
        }
 
        unless ($editor) {