Hello, Ok, I include a combined patches on top of experimental, my git branch[1] has two commits.
I provided a poor named[2] function to modify cp with the user configuration and call it from after testing if we need a new section to avoid conflicting with it and in "do_snapshot". Regards. commit 9155655270dc3854cc045f1f27cd6ddf8d7ee0a0 Author: Daniel Dehennin <daniel.dehen...@baby-gnu.org> Date: Mon Nov 21 19:57:18 2011 +0100 Add urgency management. * git-dch (apply_options_to_changelog_entry): Add "urgency" with default value "low". (main): Add version_group option "-U" and "--urgency" to set the urgency level of the entry. commit b39a5866f85a1794a00cc873b52292334f96d7a1 Author: Daniel Dehennin <daniel.dehen...@baby-gnu.org> Date: Mon Nov 21 15:44:41 2011 +0100 Add option to manage distribution fields. * git-dch (apply_options_to_changelog_entry): New function to factorize changelog entry mangling by user parameters. (main): Add version_group option "-D" and "--distribution" to specify the distribution name. It's default value is calculated in apply_options_to_changelog_entry conflicting with add_section test. Add version_group option "--force-distribution" to force the provided distribution to be used, used by "dch". Apply user configuration to changelog entry calling 'add_section_entry' to switch the distribution when user request it. Update "add_changelog_section" calls to pass the user defined distribution. (do_snapshot): Apply user configuration to changelog entry, pass options instead of just "new_snapshot" version. Closes: #646684 --- gbp/scripts/dch.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index a82c1bd..05fa32d 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -195,6 +195,26 @@ def mangle_changelog(changelog, cp, snapshot=''): raise GbpError, "Error mangling changelog %s" % e +def apply_options_to_changelog_entry(cp, options): + """ + Modify the changelog entry accordingly with user options. + Actual options is 'distributions' and 'urgency'. + """ + used_options = {'distribution':'UNRELEASED', 'urgency':'low'} + for opt, default in used_options.items(): + if hasattr(options, opt) and cp[ opt.capitalize() ] != getattr(options, opt): + gbp.log.debug("Replace changelog '%s' from '%s' to '%s'" \ + % (opt.capitalize(), cp[opt.capitalize()], getattr(options, opt))) + del(cp[ opt.capitalize() ]) + cp[ opt.capitalize() ] = getattr(options, opt) + elif not hasattr(options, opt): + # Set default value here to avoid conflict with + # add_section test in main + setattr(options, opt, default) + + return cp + + def do_release(changelog, repo, cp, git_author, dch_options): "remove the snapshot header and set the distribution" author, email = get_author_email(repo, git_author) @@ -205,7 +225,7 @@ def do_release(changelog, repo, cp, git_author, dch_options): spawn_dch(release=True, author=author, email=email, dch_options=dch_options) -def do_snapshot(changelog, repo, next_snapshot): +def do_snapshot(changelog, repo, options): """ Add new snapshot banner to most recent changelog section. The next snapshot number is calculated by eval()'ing next_snapshot @@ -213,8 +233,10 @@ def do_snapshot(changelog, repo, next_snapshot): commit = repo.head cp = parse_changelog(filename=changelog) + cp = apply_options_to_changelog_entry(cp, options) + (release, snapshot) = snapshot_version(cp['Version']) - snapshot = int(eval(next_snapshot)) + snapshot = int(eval(options.snapshot_number)) suffix = "%d.gbp%s" % (snapshot, "".join(commit[0:6])) cp['MangledVersion'] = "%s~%s" % (release, suffix) @@ -281,6 +303,9 @@ def process_options(options, parser): else: dch_options += " --nomultimaint" + if options.force_distribution: + dch_options += " --force-distribution" + get_customizations(options.customization_file) return dch_options @@ -342,8 +367,12 @@ def main(argv): help="mark as release") version_group.add_option("-S", "--snapshot", action="store_true", dest="snapshot", default=False, help="mark as snapshot build") + version_group.add_option("-D", "--distribution", dest="distribution", help="Set distribution") + version_group.add_option("--force-distribution", action="store_true", dest="force_distribution", default=False, + help="Force the provided distribution to be used, even if it doesn't match the list of known distributions") version_group.add_option("-N", "--new-version", dest="new_version", help="use this as base for the new version number") + version_group.add_option("-U", "--urgency", dest="urgency", help="Set urgency level") version_group.add_option("--bpo", dest="bpo", action="store_true", default=False, help="Increment the Debian release number for an upload to lenny-backports, and add a backport upload changelog comment.") version_group.add_option("--nmu", dest="nmu", action="store_true", default=False, @@ -433,6 +462,9 @@ def main(argv): else: add_section = False + # Apply user option here to avoid clash with add_section test above + cp = apply_options_to_changelog_entry(cp, options) + i = 0 for c in commits: i += 1 @@ -446,7 +478,7 @@ def main(argv): if add_section: # Add a section containing just this message (we can't # add an empty section with dch) - add_changelog_section(distribution="UNRELEASED", msg=commit_msg, + add_changelog_section(distribution=options.distribution, msg=commit_msg, version=version_change, author=commit_author, email=commit_email, @@ -468,7 +500,7 @@ def main(argv): if add_section: # If we end up here, then there were no commits to include, # so we put a dummy message in the new section. - add_changelog_section(distribution="UNRELEASED", msg=["UNRELEASED"], + add_changelog_section(distribution=options.distribution, msg=["UNRELEASED"], version=version_change, dch_options=dch_options, repo=repo, @@ -482,7 +514,7 @@ def main(argv): do_release(changelog, repo, cp, git_author=options.git_author, dch_options=dch_options) elif options.snapshot: - (snap, version) = do_snapshot(changelog, repo, options.snapshot_number) + (snap, version) = do_snapshot(changelog, repo, options) gbp.log.info("Changelog has been prepared for snapshot #%d at %s" % (snap, version)) if editor_cmd: Footnotes: [1] git pull git://git.baby-gnu.net/git-buildpackage dad/dch-configurable-changelog-entry [2] I thought about "mangle_changelog" but it's already used and my mind is stuck on that :-/ -- Daniel Dehennin Récupérer ma clef GPG: gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1
pgpWclcCwix67.pgp
Description: PGP signature