Merge ubuntu-dev-tools:py3debian-changelog into ubuntu-dev-tools:master

Proposed by Stefano Rivera
Status: Merged
Merged at revision: c7b2149e1a6b9abf541581cec65d58f7f2236588
Proposed branch: ubuntu-dev-tools:py3debian-changelog
Merge into: ubuntu-dev-tools:master
Diff against target: 99 lines (+18/-54)
1 file modified
merge-changelog (+18/-54)
Reviewer Review Type Date Requested Status
Mattia Rizzolo Pending
Review via email: mp+372620@code.launchpad.net

Commit message

Rewrite merge-changelog using python3-debian

Description of the change

While I was making this use python_debian's Version class, I realised we could outsource the changelog handling, too.

I didn't push this with the Python 3 changes, because I'm not sure what the downsides of this change are. merge-changelog is a nice, old tool, that doesn't get much development because it "just works".

I tested this with a dpkg changelog (nice and messy, full of legacy) and it seemed to do the right thing. But not sure what else I need to test it on...

To post a comment you must log in.
Revision history for this message
Mattia Rizzolo (mapreri) wrote :

please let me keep this MR for a next possible-breaking upload, keeping the next one with fixes only.

Revision history for this message
Mattia Rizzolo (mapreri) wrote :

It seems indeed to work, mh. Well, I'll just merge it and we'll see if anybody reports bugs. "Obviously", the real good way would be for some testcases to appear, sadly ubuntutools is somewhat lacking in that regard :(

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/merge-changelog b/merge-changelog
2index b2ad12a..9d0b67e 100755
3--- a/merge-changelog
4+++ b/merge-changelog
5@@ -18,10 +18,9 @@
6 # You should have received a copy of the GNU General Public License
7 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
9-import re
10 import sys
11
12-from debian.debian_support import Version
13+from debian.changelog import Changelog
14
15
16 def usage(exit_code=1):
17@@ -39,65 +38,30 @@ Debian release of the package.
18 ########################################################################
19
20
21-# Regular expression for top of debian/changelog
22-CL_RE = re.compile(r'^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-0-9a-z]+)+)\;',
23- re.IGNORECASE)
24-
25-
26 def merge_changelog(left_changelog, right_changelog):
27 """Merge a changelog file."""
28
29- left_cl = read_changelog(left_changelog)
30- right_cl = read_changelog(right_changelog)
31-
32- for right_ver, right_text in right_cl:
33- while len(left_cl) and left_cl[0][0] > right_ver:
34- (left_ver, left_text) = left_cl.pop(0)
35- print(left_text)
36-
37- while len(left_cl) and left_cl[0][0] == right_ver:
38- (left_ver, left_text) = left_cl.pop(0)
39-
40- print(right_text)
41-
42- for _, left_text in left_cl:
43- print(left_text)
44-
45- return False
46-
47-
48-def read_changelog(filename):
49- """Return a parsed changelog file."""
50- entries = []
51-
52- changelog_file = open(filename)
53- try:
54- (ver, text) = (None, "")
55- for line in changelog_file:
56- match = CL_RE.search(line)
57- if match:
58- try:
59- ver = Version(match.group(2))
60- except ValueError:
61- ver = None
62+ with open(left_changelog) as f:
63+ left_cl = Changelog(f)
64+ with open(right_changelog) as f:
65+ right_cl = Changelog(f)
66
67- text += line
68- elif line.startswith(" -- "):
69- if ver is None:
70- ver = Version("0")
71+ left_versions = set(left_cl.versions)
72+ right_versions = set(right_cl.versions)
73+ left_blocks = iter(left_cl)
74+ right_blocks = iter(right_cl)
75
76- text += line
77- entries.append((ver, text))
78- (ver, text) = (None, "")
79- elif len(line.strip()) or ver is not None:
80- text += line
81- finally:
82- changelog_file.close()
83+ for version in sorted(left_versions | right_versions, reverse=True):
84+ if version in left_versions:
85+ block = next(left_blocks)
86+ if version in right_versions:
87+ next(right_blocks)
88+ else:
89+ block = next(right_blocks)
90
91- if len(text):
92- entries.append((ver, text))
93+ assert block.version == version
94
95- return entries
96+ print(str(block).strip(), end='\n\n')
97
98
99 def main():

Subscribers

People subscribed via source and target branches