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/>.
|
|
|
|
|
2023-01-30 23:10:31 +01:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
# pylint: enable=invalid-name
|
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
import sys
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2019-09-04 19:02:21 -03:00
|
|
|
from debian.changelog import Changelog
|
2019-09-04 19:01:41 -03:00
|
|
|
|
2018-10-12 18:54:07 -04:00
|
|
|
from ubuntutools import getLogger
|
2023-01-30 19:45:36 +01:00
|
|
|
|
2021-02-01 18:26:13 -05:00
|
|
|
Logger = getLogger()
|
2018-10-12 18:54:07 -04:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
def usage(exit_code=1):
|
2023-01-30 19:45:36 +01:00
|
|
|
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.
|
2023-01-30 19:45:36 +01:00
|
|
|
"""
|
|
|
|
)
|
2010-12-27 21:54:31 +01:00
|
|
|
sys.exit(exit_code)
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
|
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."""
|
|
|
|
|
2023-01-31 15:51:29 +01:00
|
|
|
with open(left_changelog, encoding="utf-8") as f:
|
2019-09-04 19:02:21 -03:00
|
|
|
left_cl = Changelog(f)
|
2023-01-31 15:51:29 +01:00
|
|
|
with open(right_changelog, encoding="utf-8") as f:
|
2019-09-04 19:02:21 -03:00
|
|
|
right_cl = Changelog(f)
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2019-09-04 19:02:21 -03: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
|
|
|
|
2021-03-17 00:45:04 +01:00
|
|
|
clist = sorted(left_versions | right_versions, reverse=True)
|
2023-01-30 23:10:31 +01:00
|
|
|
remaining = len(clist)
|
2021-03-17 00:45:04 +01:00
|
|
|
for version in clist:
|
2023-01-30 23:10:31 +01:00
|
|
|
remaining -= 1
|
2019-09-04 19:02:21 -03:00
|
|
|
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
|
|
|
|
2019-09-04 19:02:21 -03:00
|
|
|
assert block.version == version
|
2010-02-15 09:32:55 -05:00
|
|
|
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("%s%s", str(block).strip(), "\n" if remaining else "")
|
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():
|
2023-01-30 19:45:36 +01: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
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
if __name__ == "__main__":
|
2010-12-27 16:54:23 +01:00
|
|
|
main()
|