[StGit PATCH 02/10] Add property with a list of all patch names
This simplifies the code in a number of places.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/coalesce.py | 3 +--
stgit/commands/commit.py | 6 ++----
stgit/commands/delete.py | 4 +---
stgit/commands/uncommit.py | 2 +-
stgit/lib/stack.py | 1 +
5 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/stgit/commands/coalesce.py b/stgit/commands/coalesce.py
index bf40427..9a46097 100644
--- a/stgit/commands/coalesce.py
+++ b/stgit/commands/coalesce.py
@@ -115,8 +115,7 @@ def _coalesce(stack, iw, name, msg, save_template, patches):
def func(parser, options, args):
stack = directory.repository.current_stack
- patches = common.parse_patches(args, (list(stack.patchorder.applied)
- + list(stack.patchorder.unapplied)))
+ patches = common.parse_patches(args, list(stack.patchorder.all))
if len(patches) < 2:
raise common.CmdException('Need at least two patches')
return _coalesce(stack, stack.repository.default_iw, options.name,
diff --git a/stgit/commands/commit.py b/stgit/commands/commit.py
index ee95836..ab89590 100644
--- a/stgit/commands/commit.py
+++ b/stgit/commands/commit.py
@@ -45,13 +45,11 @@ options = [make_option('-n', '--number', type = 'int',
def func(parser, options, args):
"""Commit a number of patches."""
stack = directory.repository.current_stack
- args = common.parse_patches(args, (list(stack.patchorder.applied)
- + list(stack.patchorder.unapplied)))
+ args = common.parse_patches(args, list(stack.patchorder.all))
if len([x for x in [args, options.number != None, options.all] if x]) > 1:
parser.error('too many options')
if args:
- patches = [pn for pn in (stack.patchorder.applied
- + stack.patchorder.unapplied) if pn in args]
+ patches = [pn for pn in stack.patchorder.all if pn in args]
bad = set(args) - set(patches)
if bad:
raise common.CmdException('Bad patch names: %s'
diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py
index 14bf442..872ed77 100644
--- a/stgit/commands/delete.py
+++ b/stgit/commands/delete.py
@@ -41,9 +41,7 @@ def func(parser, options, args):
stack = directory.repository.current_stack
iw = stack.repository.default_iw
if args:
- patches = set(common.parse_patches(
- args, (list(stack.patchorder.applied)
- + list(stack.patchorder.unapplied))))
+ patches = set(common.parse_patches(args, list(stack.patchorder.all)))
else:
parser.error('No patches specified')
def allow_conflicts(trans):
diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index b6765bc..9ab178c 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py
@@ -116,7 +116,7 @@ def func(parser, options, args):
next_commit = get_parent(next_commit)
patch_nr = len(commits)
- taken_names = set(stack.patchorder.applied + stack.patchorder.unapplied)
+ taken_names = set(stack.patchorder.all)
if patchnames:
for pn in patchnames:
if pn in taken_names:
diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py
index 3de3776..af1c994 100644
--- a/stgit/lib/stack.py
+++ b/stgit/lib/stack.py
@@ -96,6 +96,7 @@ class PatchOrder(object):
lambda self, val: self.__set_list('applied', val))
unapplied = property(lambda self: self.__get_list('unapplied'),
lambda self, val: self.__set_list('unapplied', val))
+ all = property(lambda self: self.applied + self.unapplied)
class Patches(object):
"""Creates Patch objects."""