bug-vc-dwim
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-vc-dwim] [PATCH 1/2] vc-dwim: don't include a ChangeLog header in t


From: Jim Meyering
Subject: [Bug-vc-dwim] [PATCH 1/2] vc-dwim: don't include a ChangeLog header in the commit log
Date: Thu, 05 May 2011 13:48:14 +0200

FYI,
Here's a fix for a bug that's been nagging me for a long time.
The second (albeit earlier ;-) patch adds a test to exercise the fix.

>From 64d688199b94a74948620ef792fde1f1aeb64ea9 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 5 May 2011 13:45:49 +0200
Subject: [PATCH 1/2] vc-dwim: don't include a ChangeLog header in the commit
 log

* NEWS (Bug fixes): Mention it.
* vc-dwim.pl (main): Recognize and omit the offending lines
from @log_lines.
---
 NEWS       |    7 +++++++
 vc-dwim.pl |   60 +++++++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/NEWS b/NEWS
index fc3371a..4505a57 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ vc-dwim NEWS                                          -*- 
outline -*-

 * Noteworthy changes in release ?.? (????-??-??) [?]

+** Bug fixes
+
+  vc-dwim: when the added ChangeLog date-name-email header is identical
+  to the preceding one, vc-dwim would put that line at the end of the
+  commit log whenever diff output listed the new, topmost, header only
+  as context lines in the ChangeLog diff output.  That bug is fixed.
+

 * Noteworthy changes in release 1.4 (2011-03-18) [stable]

diff --git a/vc-dwim.pl b/vc-dwim.pl
index ee08d01..abe65ce 100755
--- a/vc-dwim.pl
+++ b/vc-dwim.pl
@@ -849,28 +849,50 @@ sub main
       # 2006-08-19  Jim Meyering  <address@hidden>
       # Ignore the following one, too, which should be blank.
       my $n_log_lines = @log_lines;
-      if (3 <= $n_log_lines
-          && $log_lines[0] =~ /^\+\d{4}-\d\d-\d\d  (.*)/)
+      if (3 <= $n_log_lines)
         {
-          my $name_and_email = $1;
-          check_attribution $name_and_email, \$author;
-          shift @log_lines;
-
-          # Accept and ignore a second ChangeLog attribution line.  E.g.,
-          # 2006-09-29  user one  <address@hidden>
-          #         and user two  <address@hidden>
-          # The "and " on the second line is optional.
-          $log_lines[0] =~ /^\+\t(?:and )?[^<]+<.*>$/
-            and shift @log_lines;
-
-          if ($log_lines[0] ne '+')
+          if ($log_lines[0] =~ /^\+\d{4}-\d\d-\d\d  (.*)/)
+            {
+              my $name_and_email = $1;
+              check_attribution $name_and_email, \$author;
+              shift @log_lines;
+
+              # Accept and ignore a second ChangeLog attribution line.  E.g.,
+              # 2006-09-29  user one  <address@hidden>
+              #         and user two  <address@hidden>
+              # The "and " on the second line is optional.
+              $log_lines[0] =~ /^\+\t(?:and )?[^<]+<.*>$/
+                and shift @log_lines;
+
+              if ($log_lines[0] ne '+')
+                {
+                  $log_lines[0] =~ s/^\+//;
+                  die "$ME:$log: unexpected, non-blank line after first:\n"
+                    . $log_lines[0] . "\n";
+                }
+              shift @log_lines;
+              $offset += ($n_log_lines - @log_lines);
+            }
+          elsif (address@hidden =~ /^\+\d{4}-\d\d-\d\d  (.*)/
+                 && address@hidden =~ /^\+ ?$/)
             {
-              $log_lines[0] =~ s/^\+//;
-              die "$ME:$log: unexpected, non-blank line after first:\n"
-                . $log_lines[0] . "\n";
+              # Handle the case in which the latest ChangeLog entry
+              # has a header that is identical to the previous one.
+              # That could result in diff output like this:
+              #
+              # @@ -1,3 +1,7 @@
+              #  2011-03-04  Joe Random  <address@hidden>
+              #
+              # +       * x: y
+              # +
+              # +2011-03-04  Joe Random  <address@hidden>
+              # +
+              #
+              # Before the 2011-05-05 fix, vc-dwim would include
+              # that header line at the end of the commit log.
+              pop @log_lines;
+              pop @log_lines;
             }
-          shift @log_lines;
-          $offset += ($n_log_lines - @log_lines);
         }

       # FIXME: now that we have this find_author function,
--
1.7.5.320.g20a15


>From 601f2130f8de502a4b9cd56c4ac6e187167ca183 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 4 May 2011 18:25:16 +0200
Subject: [PATCH 2/2] tests: test for the ChangeLog-header-in-commit-log bug

* tests/changelog-header-at-end-of-log: Test for the bug whereby
a ChangeLog header is inserted at the end of a commit log.
This would happen when the latest ChangeLog entry has exactly
the same header as the previous ChangeLog header and the diff
output includes the first header and following blank line
only as context.
* tests/Makefile.am (TESTS): Add it.
---
 tests/Makefile.am                    |    1 +
 tests/changelog-header-at-end-of-log |   40 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100755 tests/changelog-header-at-end-of-log

diff --git a/tests/Makefile.am b/tests/Makefile.am
index fa95a29..307851d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ EXTRA_DIST = $(TESTS) \
   init.sh

 TESTS = \
+  changelog-header-at-end-of-log \
   git-log-summary \
   author \
   subdir-middle \
diff --git a/tests/changelog-header-at-end-of-log 
b/tests/changelog-header-at-end-of-log
new file mode 100755
index 0000000..82de1df
--- /dev/null
+++ b/tests/changelog-header-at-end-of-log
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Demonstrate that with two identical ChangeLog headers, vc-dwim
+# no longer mistakenly emits one at the end of the log message.
+
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ..
+print_ver_ vc-dwim
+require_git_
+
+header='2011-03-04  Joe Random  <address@hidden>'
+git init > /dev/null                            \
+  && printf "$header\n\n\tfirst\n"> ChangeLog   \
+  && touch x                                    \
+  && git add .                                  \
+  && git commit -m m . > /dev/null              \
+    || framework_failure_
+
+printf "$header\n\n\t* x: y\n\n$header\n\n\tfirst\n" > ChangeLog \
+    || framework_failure_
+echo foo > x || framework_failure_
+
+vc-dwim --c > out || fail=1
+grep "$header" out && fail=1
+cat out
+
+Exit $fail
--
1.7.5.320.g20a15



reply via email to

[Prev in Thread] Current Thread [Next in Thread]