ubuntu-dev-tools/merge-changelog
Krytarik Raido a1b56ac31f
merge-changelog: Fix setting of newlines.
Signed-off-by: Mattia Rizzolo <mattia@debian.org>
2021-09-08 19:44:15 +02:00

88 lines
2.6 KiB
Python
Executable File

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright © 2008 Canonical Ltd.
# Author: Scott James Remnant <scott at ubuntu.com>.
# Hacked up by: Bryce Harrington <bryce at ubuntu.com>
# Change merge_changelog to merge-changelog: Ryan Kavanagh
# <ryanakca@kubuntu.org>
#
# 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/>.
import sys
from debian.changelog import Changelog
from ubuntutools import getLogger
Logger = getLogger()
def usage(exit_code=1):
Logger.info('''Usage: merge-changelog <left changelog> <right changelog>
merge-changelog takes two changelogs that once shared a common source,
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.
''')
sys.exit(exit_code)
########################################################################
# Changelog Management
########################################################################
def merge_changelog(left_changelog, right_changelog):
"""Merge a changelog file."""
with open(left_changelog) as f:
left_cl = Changelog(f)
with open(right_changelog) as f:
right_cl = Changelog(f)
left_versions = set(left_cl.versions)
right_versions = set(right_cl.versions)
left_blocks = iter(left_cl)
right_blocks = iter(right_cl)
clist = sorted(left_versions | right_versions, reverse=True)
ci = len(clist)
for version in clist:
ci -= 1
if version in left_versions:
block = next(left_blocks)
if version in right_versions:
next(right_blocks)
else:
block = next(right_blocks)
assert block.version == version
Logger.info(str(block).strip() + ('\n' if ci else ''))
def main():
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'):
usage(0)
if len(sys.argv) != 3:
usage(1)
left_changelog = sys.argv[1]
right_changelog = sys.argv[2]
merge_changelog(left_changelog, right_changelog)
sys.exit(0)
if __name__ == '__main__':
main()