2019-09-04 19:01:41 -03:00
|
|
|
#!/usr/bin/python3
|
2010-02-15 09:32:55 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-04-08 13:30:49 +02:00
|
|
|
# Copyright © 2008 Canonical Ltd.
|
2010-02-15 09:32:55 -05:00
|
|
|
# Author: Scott James Remnant <scott at ubuntu.com>.
|
|
|
|
# Hacked up by: Bryce Harrington <bryce at ubuntu.com>
|
2010-02-15 16:34:10 -05:00
|
|
|
# Change merge_changelog to merge-changelog: Ryan Kavanagh
|
|
|
|
# <ryanakca@kubuntu.org>
|
2010-02-15 09:32:55 -05:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of version 3 of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
import re
|
|
|
|
import sys
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2019-09-04 19:01:41 -03:00
|
|
|
from debian.debian_support import Version
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
def usage(exit_code=1):
|
2019-09-04 19:01:41 -03:00
|
|
|
print('''Usage: merge-changelog <left changelog> <right changelog>
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2010-12-03 00:06:43 +01:00
|
|
|
merge-changelog takes two changelogs that once shared a common source,
|
2010-02-15 09:32:55 -05:00
|
|
|
merges them back together, and prints the merged result to stdout. This
|
|
|
|
is useful if you need to manually merge a ubuntu package with a new
|
|
|
|
Debian release of the package.
|
2019-09-04 19:01:41 -03:00
|
|
|
''')
|
2010-12-27 21:54:31 +01:00
|
|
|
sys.exit(exit_code)
|
2010-02-15 09:32:55 -05:00
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Changelog Management
|
|
|
|
########################################################################
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-02-15 09:32:55 -05:00
|
|
|
# Regular expression for top of debian/changelog
|
|
|
|
CL_RE = re.compile(r'^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-0-9a-z]+)+)\;',
|
|
|
|
re.IGNORECASE)
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-02-15 09:32:55 -05:00
|
|
|
def merge_changelog(left_changelog, right_changelog):
|
|
|
|
"""Merge a changelog file."""
|
|
|
|
|
|
|
|
left_cl = read_changelog(left_changelog)
|
|
|
|
right_cl = read_changelog(right_changelog)
|
|
|
|
|
|
|
|
for right_ver, right_text in right_cl:
|
|
|
|
while len(left_cl) and left_cl[0][0] > right_ver:
|
|
|
|
(left_ver, left_text) = left_cl.pop(0)
|
2019-09-04 19:01:41 -03:00
|
|
|
print(left_text)
|
2010-02-15 09:32:55 -05:00
|
|
|
|
|
|
|
while len(left_cl) and left_cl[0][0] == right_ver:
|
|
|
|
(left_ver, left_text) = left_cl.pop(0)
|
|
|
|
|
2019-09-04 19:01:41 -03:00
|
|
|
print(right_text)
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
for _, left_text in left_cl:
|
2019-09-04 19:01:41 -03:00
|
|
|
print(left_text)
|
2010-12-03 00:06:43 +01:00
|
|
|
|
2010-02-15 09:32:55 -05:00
|
|
|
return False
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-02-15 09:32:55 -05:00
|
|
|
def read_changelog(filename):
|
|
|
|
"""Return a parsed changelog file."""
|
|
|
|
entries = []
|
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
changelog_file = open(filename)
|
2010-02-15 09:32:55 -05:00
|
|
|
try:
|
|
|
|
(ver, text) = (None, "")
|
2010-12-27 21:54:31 +01:00
|
|
|
for line in changelog_file:
|
2010-02-15 09:32:55 -05:00
|
|
|
match = CL_RE.search(line)
|
|
|
|
if match:
|
|
|
|
try:
|
|
|
|
ver = Version(match.group(2))
|
|
|
|
except ValueError:
|
|
|
|
ver = None
|
|
|
|
|
|
|
|
text += line
|
|
|
|
elif line.startswith(" -- "):
|
|
|
|
if ver is None:
|
|
|
|
ver = Version("0")
|
|
|
|
|
|
|
|
text += line
|
|
|
|
entries.append((ver, text))
|
|
|
|
(ver, text) = (None, "")
|
|
|
|
elif len(line.strip()) or ver is not None:
|
|
|
|
text += line
|
|
|
|
finally:
|
2010-12-27 21:54:31 +01:00
|
|
|
changelog_file.close()
|
2010-02-15 09:32:55 -05:00
|
|
|
|
|
|
|
if len(text):
|
|
|
|
entries.append((ver, text))
|
|
|
|
|
|
|
|
return entries
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 16:54:23 +01:00
|
|
|
def main():
|
2010-12-22 16:53:58 +02:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'):
|
2010-12-27 21:54:31 +01:00
|
|
|
usage(0)
|
2010-02-15 09:32:55 -05:00
|
|
|
if len(sys.argv) != 3:
|
2010-12-27 21:54:31 +01:00
|
|
|
usage(1)
|
2010-12-03 00:06:43 +01:00
|
|
|
|
2010-02-15 09:32:55 -05:00
|
|
|
left_changelog = sys.argv[1]
|
|
|
|
right_changelog = sys.argv[2]
|
|
|
|
|
|
|
|
merge_changelog(left_changelog, right_changelog)
|
|
|
|
sys.exit(0)
|
2010-12-27 16:54:23 +01:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 16:54:23 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|