ubuntu-dev-tools/merge-changelog

85 lines
2.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python3
2010-02-15 09:32:55 -05:00
# -*- coding: utf-8 -*-
# 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>
# 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 sys
2010-02-15 09:32:55 -05:00
from debian.changelog import Changelog
from ubuntutools import getLogger
Logger = getLogger()
2017-05-01 00:20:03 +02:00
2010-12-27 21:54:31 +01:00
def usage(exit_code=1):
Logger.info('''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.
''')
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
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)
2010-02-15 09:32:55 -05:00
left_versions = set(left_cl.versions)
right_versions = set(right_cl.versions)
left_blocks = iter(left_cl)
right_blocks = iter(right_cl)
2010-02-15 09:32:55 -05:00
for version in sorted(left_versions | right_versions, reverse=True):
if version in left_versions:
block = next(left_blocks)
if version in right_versions:
next(right_blocks)
else:
block = next(right_blocks)
2010-02-15 09:32:55 -05:00
assert block.version == version
2010-02-15 09:32:55 -05:00
Logger.info(str(block).strip() + '\n\n')
2010-02-15 09:32:55 -05:00
2017-05-01 00:20:03 +02:00
2010-12-27 16:54:23 +01:00
def main():
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()