diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-05-11 10:56:17 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-06-05 14:20:04 +0300 |
commit | 2674486b099317fb5db314bc8743614998af63bd (patch) | |
tree | 03bae28009e0509c1fe974b5df0fb24e2a0c23fa /gbp/scripts/common | |
parent | b3d964ebbc7b55aa692f03ed98a592ee775f6f83 (diff) | |
download | git-buildpackage-2674486b099317fb5db314bc8743614998af63bd.tar.gz git-buildpackage-2674486b099317fb5db314bc8743614998af63bd.tar.bz2 git-buildpackage-2674486b099317fb5db314bc8743614998af63bd.zip |
gbp-pq: readiness to configure the pq branch name
All other gbp branches have configurable names. This commit adds the
readiness for user to configure/change the name of the patch-queue
branches, as well.
Patch-queue is defined in options as a format string, where '%(branch)s'
refers to the debian/packaging branch. If the pq-branch format string
does not contain '%(branch)s', there is only one patch-queue branch and
the debian/packaging branch is used as its base branch. That is, e.g. a
'gbp-pq switch' operation from the patch-queue branch always switches to
the debian/packaging branch.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Olev Kartau <olev.kartau@intel.com>
Diffstat (limited to 'gbp/scripts/common')
-rw-r--r-- | gbp/scripts/common/pq.py | 107 |
1 files changed, 82 insertions, 25 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index 8d92a170..89683dd7 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -34,43 +34,99 @@ from gbp.git.modifier import GitModifier, GitTz from gbp.errors import GbpError import gbp.log -PQ_BRANCH_PREFIX = "patch-queue/" +DEFAULT_PQ_BRANCH_NAME = "patch-queue/%(branch)s" -def is_pq_branch(branch): +def is_pq_branch(branch, options): """ is branch a patch-queue branch? - >>> is_pq_branch("foo") + >>> from optparse import OptionParser + >>> (opts, args) = OptionParser().parse_args([]) + >>> is_pq_branch("foo", opts) False - >>> is_pq_branch("patch-queue/foo") + >>> is_pq_branch("patch-queue/foo", opts) + True + >>> opts.pq_branch = "%(branch)s/development" + >>> is_pq_branch("foo/development/bar", opts) + False + >>> is_pq_branch("bar/foo/development", opts) + True + >>> opts.pq_branch = "development" + >>> is_pq_branch("development", opts) + True + >>> opts.pq_branch = "my/%(branch)s/pq" + >>> is_pq_branch("my/foo/pqb", opts) + False + >>> is_pq_branch("my/foo/pq", opts) True """ - return [False, True][branch.startswith(PQ_BRANCH_PREFIX)] + pq_format_str = DEFAULT_PQ_BRANCH_NAME + if hasattr(options, 'pq_branch'): + pq_format_str = options.pq_branch + pq_re = re.compile(r'^%s$' % (pq_format_str % dict(branch="(?P<base>\S+)"))) + if pq_re.match(branch): + return True + return False -def pq_branch_name(branch): + +def pq_branch_name(branch, options): """ get the patch queue branch corresponding to branch - >>> pq_branch_name("patch-queue/master") - >>> pq_branch_name("foo") + >>> from optparse import OptionParser + >>> (opts, args) = OptionParser().parse_args([]) + >>> pq_branch_name("patch-queue/master", opts) + >>> pq_branch_name("foo", opts) 'patch-queue/foo' + >>> opts.pq_branch = "%(branch)s/development" + >>> pq_branch_name("foo", opts) + 'foo/development' + >>> opts.pq_branch = "development" + >>> pq_branch_name("foo", opts) + 'development' """ - if not is_pq_branch(branch): - return PQ_BRANCH_PREFIX + branch + pq_format_str = DEFAULT_PQ_BRANCH_NAME + if hasattr(options, 'pq_branch'): + pq_format_str = options.pq_branch + if not is_pq_branch(branch, options): + return pq_format_str % dict(branch=branch) -def pq_branch_base(pq_branch): - """ - get the branch corresponding to the given patch queue branch - >>> pq_branch_base("patch-queue/master") +def pq_branch_base(pq_branch, options): + """ + Get the branch corresponding to the given patch queue branch. + Returns the packaging/debian branch if pq format string doesn't contain + '%(branch)s' key. + + >>> from optparse import OptionParser + >>> (opts, args) = OptionParser().parse_args([]) + >>> opts.packaging_branch = "packaging" + >>> pq_branch_base("patch-queue/master", opts) 'master' - >>> pq_branch_base("foo") + >>> pq_branch_base("foo", opts) + >>> opts.pq_branch = "my/%(branch)s/development" + >>> pq_branch_base("foo/development", opts) + >>> pq_branch_base("my/foo/development/bar", opts) + >>> pq_branch_base("my/foo/development", opts) + 'foo' + >>> opts.pq_branch = "development" + >>> pq_branch_base("foo/development", opts) + >>> pq_branch_base("development", opts) + 'packaging' """ - if is_pq_branch(pq_branch): - return pq_branch[len(PQ_BRANCH_PREFIX):] + pq_format_str = DEFAULT_PQ_BRANCH_NAME + if hasattr(options, 'pq_branch'): + pq_format_str = options.pq_branch + + pq_re = re.compile(r'^%s$' % (pq_format_str % dict(branch="(?P<base>\S+)"))) + m = pq_re.match(pq_branch) + if m: + if 'base' in m.groupdict(): + return m.group('base') + return options.packaging_branch def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds): @@ -256,15 +312,15 @@ def get_maintainer_from_control(repo): return GitModifier() -def switch_to_pq_branch(repo, branch): +def switch_to_pq_branch(repo, branch, options): """ Switch to patch-queue branch if not already there, create it if it doesn't exist yet """ - if is_pq_branch(branch): + if is_pq_branch(branch, options): return - pq_branch = pq_branch_name(branch) + pq_branch = pq_branch_name(branch, options) if not repo.has_branch(pq_branch): try: repo.create_branch(pq_branch) @@ -276,8 +332,9 @@ def switch_to_pq_branch(repo, branch): repo.set_branch(pq_branch) -def apply_single_patch(repo, branch, patch, fallback_author, topic=None): - switch_to_pq_branch(repo, branch) +def apply_single_patch(repo, branch, patch, fallback_author, options): + switch_to_pq_branch(repo, branch, options) + topic = None if not hasattr(options, 'topic') else options.topic apply_and_commit_patch(repo, patch, fallback_author, topic) @@ -306,12 +363,12 @@ def apply_and_commit_patch(repo, patch, fallback_author, topic=None): repo.update_ref('HEAD', commit, msg="gbp-pq import %s" % patch.path) -def drop_pq(repo, branch): - if is_pq_branch(branch): +def drop_pq(repo, branch, options): + if is_pq_branch(branch, options): gbp.log.err("On a patch-queue branch, can't drop it.") raise GbpError else: - pq_branch = pq_branch_name(branch) + pq_branch = pq_branch_name(branch, options) if repo.has_branch(pq_branch): repo.delete_branch(pq_branch) |