aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2011-09-06 09:45:12 +0800
committerCatalin Marinas <catalin.marinas@gmail.com>2011-09-08 15:19:07 +0100
commit7b76a9d3b8943d6ce4b7e74ef28e3717d9ac6ed1 (patch)
tree0944bc65a00c9659205b8c3711c5af49a9d43362
parentc6174ba789255e92838a56d75dd2e434a29476d8 (diff)
downloadstgit-7b76a9d3b8943d6ce4b7e74ef28e3717d9ac6ed1.tar.gz
add fuzzy patch name lookup support for 'goto' command
With this patch, we can now specify part of a long patch name, and it will try to match the correct one. Signed-off-by: Lu Guanqun <guanqun.lu@gmail.com> Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r--stgit/commands/common.py10
-rw-r--r--stgit/commands/goto.py11
2 files changed, 18 insertions, 3 deletions
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 2c525ba..fa46510 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -192,6 +192,16 @@ def pop_patches(crt_series, patches, keep = False):
crt_series.pop_patch(p, keep)
out.done()
+def get_patch_from_list(part_name, patch_list):
+ candidates = [full for full in patch_list if str.find(full, part_name) != -1]
+ if len(candidates) >= 2:
+ out.info('Possible patches:\n %s' % '\n '.join(candidates))
+ raise CmdException, 'Ambiguous patch name "%s"' % part_name
+ elif len(candidates) == 1:
+ return candidates[0]
+ else:
+ return None
+
def parse_patches(patch_args, patch_list, boundary = 0, ordered = False):
"""Parse patch_args list for patch names in patch_list and return
a list. The names can be individual patches and/or in the
diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py
index d201a91..608763f 100644
--- a/stgit/commands/goto.py
+++ b/stgit/commands/goto.py
@@ -42,6 +42,13 @@ def func(parser, options, args):
clean_iw = (not options.keep and iw) or None
trans = transaction.StackTransaction(stack, 'goto',
check_clean_iw = clean_iw)
+
+ if not patch in trans.all_patches:
+ candidate = common.get_patch_from_list(patch, trans.all_patches)
+ if candidate is None:
+ raise common.CmdException('Patch "%s" does not exist' % patch)
+ patch = candidate
+
if patch in trans.applied:
to_pop = set(trans.applied[trans.applied.index(patch)+1:])
assert not trans.pop_patches(lambda pn: pn in to_pop)
@@ -57,8 +64,6 @@ def func(parser, options, args):
already_merged = pn in merged)
except transaction.TransactionHalted:
pass
- elif patch in trans.hidden:
- raise common.CmdException('Cannot goto a hidden patch')
else:
- raise common.CmdException('Patch "%s" does not exist' % patch)
+ raise common.CmdException('Cannot goto a hidden patch')
return trans.run(iw)