From 214a8453c91d1ba54b85d44cbfc49810b34fae80 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Sat, 8 Nov 2008 21:18:09 +0000 Subject: [PATCH] Generate a different patch name if it already exists This is a fix for bug #12518. If the patch name already exists, the pick command generates another by appending a numbered suffix. Signed-off-by: Catalin Marinas --- stgit/commands/pick.py | 9 ++++++++- stgit/utils.py | 16 ++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py index 0fc54b8..ee08c01 100644 --- a/stgit/commands/pick.py +++ b/stgit/commands/pick.py @@ -64,6 +64,8 @@ def __pick_commit(commit_id, patchname, options): if options.name: patchname = options.name + if patchname: + patchname = find_patch_name(patchname, crt_series.patch_exists) if options.parent: parent = git_id(crt_series, options.parent) @@ -181,7 +183,12 @@ def func(parser, options, args): raise CmdException, 'No patches applied' if commit_id: - __pick_commit(commit_id, None, options) + # Try to guess a patch name if the argument was : + try: + patchname = args[0].split(':')[1] + except IndexError: + patchname = None + __pick_commit(commit_id, patchname, options) else: if options.unapplied: patches.reverse() diff --git a/stgit/utils.py b/stgit/utils.py index 751cb4a..81035a5 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -200,6 +200,15 @@ def edit_string(s, filename): os.remove(filename) return s +def find_patch_name(patchname, unacceptable): + """Find a patch name which is acceptable.""" + if unacceptable(patchname): + suffix = 0 + while unacceptable('%s-%d' % (patchname, suffix)): + suffix += 1 + patchname = '%s-%d' % (patchname, suffix) + return patchname + def patch_name_from_msg(msg): """Return a string to be used as a patch name. This is generated from the top line of the string passed as argument.""" @@ -220,12 +229,7 @@ def make_patch_name(msg, unacceptable, default_name = 'patch'): patchname = patch_name_from_msg(msg) if not patchname: patchname = default_name - if unacceptable(patchname): - suffix = 0 - while unacceptable('%s-%d' % (patchname, suffix)): - suffix += 1 - patchname = '%s-%d' % (patchname, suffix) - return patchname + return find_patch_name(patchname, unacceptable) # any and all functions are builtin in Python 2.5 and higher, but not # in 2.4. -- 2.11.0