From d466fd8b8d91b05ea6f7be393e5ef4cd13bf97e4 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Thu, 25 Apr 2013 10:37:29 +0200
Subject: [PATCH] Improve check for  "unreleased" versions in NEWS

Currently this is checked only when distcheck-release is called.
Check it in check-news instead, for all versions before the "current"
one (as defined by configure.ac)

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
---
 Makefile.am          | 10 ++--------
 autotools/check-news | 28 ++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 66c15dafc..3d902209c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1624,7 +1624,7 @@ check-local: check-dirs $(GENERATED_FILES)
 	$(CHECK_PYTHON_CODE) $(check_python_code)
 	PYTHONPATH=. $(CHECK_HEADER) $(check_python_code)
 	$(CHECK_VERSION) $(VERSION) $(top_srcdir)/NEWS
-	$(CHECK_NEWS) < $(top_srcdir)/NEWS
+	RELEASE=$(PACKAGE_VERSION) $(CHECK_NEWS) < $(top_srcdir)/NEWS
 	PYTHONPATH=. $(RUN_IN_TEMPDIR) $(CURDIR)/$(CHECK_IMPORTS) . $(standalone_python_modules)
 	@expver=$(VERSION_MAJOR).$(VERSION_MINOR); \
 	error= ; \
@@ -1765,18 +1765,12 @@ distcheck-hook:
 	  echo "Found empty files or directories in final archive." 1>&2; \
 	  exit 1; \
 	fi
-	if test -n "$(BUILD_RELEASE)" && \
-	   grep -n -H -E '^\*.*unreleased' $(top_distdir)/NEWS; then \
-	   echo "Found unreleased version in NEWS." >&2; \
-	   exit 1; \
-	fi
 	if test -e $(top_distdir)/doc/man-html; then \
 	  echo "Found documentation including man pages in final archive" >&2; \
 	  exit 1; \
 	fi
 
-# When building a release, stricter checks should be used
-distcheck-release dist-release: export BUILD_RELEASE = 1
+# Backwards compatible distcheck-release target
 distcheck-release: distcheck
 
 distrebuildcheck: dist
diff --git a/autotools/check-news b/autotools/check-news
index cb5ac9a41..0ad8d6335 100755
--- a/autotools/check-news
+++ b/autotools/check-news
@@ -32,13 +32,14 @@ import datetime
 import locale
 import fileinput
 import re
+import os
 
 
 DASHES_RE = re.compile(r"^\s*-+\s*$")
 RELEASED_RE = re.compile(r"^\*\(Released (?P<day>[A-Z][a-z]{2}),"
                          r" (?P<date>.+)\)\*$")
 UNRELEASED_RE = re.compile(r"^\*\(unreleased\)\*$")
-VERSION_RE = re.compile(r"^Version \d+(\.\d+)+( (beta|rc)\d+)?$")
+VERSION_RE = re.compile(r"^Version (\d+(\.\d+)+( (beta|rc)\d+)?)$")
 
 #: How many days release timestamps may be in the future
 TIMESTAMP_FUTURE_DAYS_MAX = 3
@@ -73,17 +74,36 @@ def main():
   if curlocale != (None, None):
     Error("Invalid locale %s" % curlocale)
 
+  # Get the release version, but replace "~" with " " as the version
+  # in the NEWS file uses spaces for beta and rc releases.
+  release = os.environ.get('RELEASE', "").replace("~", " ")
+
   prevline = None
   expect_date = False
   count_empty = 0
+  allow_unreleased = True
+  found_versions = set()
 
   for line in fileinput.input():
     line = line.rstrip("\n")
 
-    if VERSION_RE.match(line):
+    version_match = VERSION_RE.match(line)
+    if version_match:
       ReqNLines(2, count_empty, fileinput.filelineno(), line)
-
-    if UNRELEASED_RE.match(line) or RELEASED_RE.match(line):
+      version = version_match.group(1)
+      if version in found_versions:
+        Error("Line %s: Duplicate release %s found" %
+              (fileinput.filelineno(), version))
+      found_versions.add(version)
+      if version == release:
+        allow_unreleased = False
+
+    unreleased_match = UNRELEASED_RE.match(line)
+    if unreleased_match and not allow_unreleased:
+      Error("Line %s: Unreleased version after current release %s" %
+            (fileinput.filelineno(), release))
+
+    if unreleased_match or RELEASED_RE.match(line):
       ReqNLines(1, count_empty, fileinput.filelineno(), line)
 
     if line:
-- 
GitLab