From 7e862c3ec029d3cdfdd07483e31843c8f3b48a68 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 15 Sep 2018 01:23:02 +1000 Subject: [PATCH 1/3] check-changes: Check bugfix version formatting Check that bugfix versions in changes files look like Tor versions from the versions spec. Part of ticket 27761. --- changes/ticket27761 | 3 +++ scripts/maint/lintChanges.py | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 changes/ticket27761 diff --git a/changes/ticket27761 b/changes/ticket27761 new file mode 100644 index 0000000000..ef4686bdca --- /dev/null +++ b/changes/ticket27761 @@ -0,0 +1,3 @@ + o Minor features (changelogs): + - Check that bugfix versions in changes files look like Tor versions + from the versions spec. Closes ticket 27761. diff --git a/scripts/maint/lintChanges.py b/scripts/maint/lintChanges.py index d5b8fcae5c..5c5d45da1d 100755 --- a/scripts/maint/lintChanges.py +++ b/scripts/maint/lintChanges.py @@ -87,6 +87,12 @@ def lintfile(fname): warn("Bugfix does not say 'Fixes bug X; bugfix on Y'") elif re.search('tor-([0-9]+)', contents): warn("Do not prefix versions with 'tor-'. ('0.1.2', not 'tor-0.1.2'.)") + else: + bugfix_match = re.search('bugfix on ([0-9]+\.[0-9]+\.[0-9]+)', contents) + if bugfix_match is None: + warn("Versions must have at least 3 digits. ('0.1.2', '0.3.4.8', or '0.3.5.1-alpha'.)") + elif bugfix_match.group(0) is None: + warn("Versions must have at least 3 digits. ('0.1.2', '0.3.4.8', or '0.3.5.1-alpha'.)") return have_warned != [] From 3eafa61f6324c91b4bb8c02a6e54db0f12ef42c2 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 18 Sep 2018 20:39:03 +1000 Subject: [PATCH 2/3] check-changes: Warn about bugfixes on future releases Warn when bugfix changes files say that the bug is in a future release. Closes ticket 27761. --- Makefile.am | 2 +- changes/ticket27761 | 3 ++- scripts/maint/lintChanges.py | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 36a5dd2e9e..9a65e083a5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -408,7 +408,7 @@ endif check-changes: if USEPYTHON @if test -d "$(top_srcdir)/changes"; then \ - $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \ + PACKAGE_VERSION=$(PACKAGE_VERSION) $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \ fi endif diff --git a/changes/ticket27761 b/changes/ticket27761 index ef4686bdca..35106ee9c6 100644 --- a/changes/ticket27761 +++ b/changes/ticket27761 @@ -1,3 +1,4 @@ o Minor features (changelogs): - Check that bugfix versions in changes files look like Tor versions - from the versions spec. Closes ticket 27761. + from the versions spec. Warn when bugfixes claim to be on a future + release. Closes ticket 27761. diff --git a/scripts/maint/lintChanges.py b/scripts/maint/lintChanges.py index 5c5d45da1d..39fa08bb4a 100755 --- a/scripts/maint/lintChanges.py +++ b/scripts/maint/lintChanges.py @@ -35,6 +35,36 @@ NEEDS_SUBCATEGORIES = set([ "Major features", ]) +def split_tor_version(version): + ''' + Return the initial numeric components of the Tor version as a list of ints. + For versions earlier than 0.1.0, returns MAJOR, MINOR, and MICRO. + For versions 0.1.0 and later, returns MAJOR, MINOR, MICRO, and PATCHLEVEL if present. + + If the version is malformed, returns None. + ''' + version_match = re.search('([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?', version) + if version_match is None: + return None + + version_groups = version_match.groups() + if version_groups is None: + return None + if len(version_groups) < 3: + return None + + if len(version_groups) != 5: + return None + version_components = version_groups[0:3] + version_components += version_groups[4:5] + + try: + version_list = [int(v) for v in version_components if v is not None] + except ValueError: + return None + + return version_list + def lintfile(fname): have_warned = [] @@ -93,6 +123,26 @@ def lintfile(fname): warn("Versions must have at least 3 digits. ('0.1.2', '0.3.4.8', or '0.3.5.1-alpha'.)") elif bugfix_match.group(0) is None: warn("Versions must have at least 3 digits. ('0.1.2', '0.3.4.8', or '0.3.5.1-alpha'.)") + else: + bugfix_match = re.search('bugfix on ([0-9a-z][-.0-9a-z]+[0-9a-z])', contents) + bugfix_group = bugfix_match.groups(0) if bugfix_match is not None else None + bugfix_version = bugfix_group[0] if bugfix_group is not None else None + package_version = os.environ.get('PACKAGE_VERSION', None) + if bugfix_version is None: + # This should be unreachable, unless the patterns are out of sync + warn("Malformed bugfix version.") + elif package_version is not None: + # If $PACKAGE_VERSION isn't set, skip this check + bugfix_split = split_tor_version(bugfix_version) + package_split = split_tor_version(package_version) + if bugfix_split is None: + # This should be unreachable, unless the patterns are out of sync + warn("Malformed bugfix version: '{}'.".format(bugfix_version)) + elif package_split is None: + # This should be unreachable, unless the patterns are out of sync, or the package versioning scheme has changed + warn("Malformed $PACKAGE_VERSION: '{}'.".format(package_version)) + elif bugfix_split > package_split: + warn("Bugfixes must be made on earlier versions (or this version). (Bugfix on version: '{}', current tor package version: '{}'.)".format(bugfix_version, package_version)) return have_warned != [] From 7e1f89346022a4e90d416dad84ffdda483dbd3b5 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 17 Jan 2019 08:46:06 -0500 Subject: [PATCH 3/3] lintChanges.py: Two python re usage fixes --- scripts/maint/lintChanges.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/maint/lintChanges.py b/scripts/maint/lintChanges.py index 39fa08bb4a..82c118f07e 100755 --- a/scripts/maint/lintChanges.py +++ b/scripts/maint/lintChanges.py @@ -43,7 +43,7 @@ def split_tor_version(version): If the version is malformed, returns None. ''' - version_match = re.search('([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?', version) + version_match = re.match('([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?', version) if version_match is None: return None @@ -125,7 +125,7 @@ def lintfile(fname): warn("Versions must have at least 3 digits. ('0.1.2', '0.3.4.8', or '0.3.5.1-alpha'.)") else: bugfix_match = re.search('bugfix on ([0-9a-z][-.0-9a-z]+[0-9a-z])', contents) - bugfix_group = bugfix_match.groups(0) if bugfix_match is not None else None + bugfix_group = bugfix_match.groups() if bugfix_match is not None else None bugfix_version = bugfix_group[0] if bugfix_group is not None else None package_version = os.environ.get('PACKAGE_VERSION', None) if bugfix_version is None: