chiark / gitweb /
Add property with a list of all patch names
authorKarl Hasselström <kha@treskal.com>
Tue, 20 May 2008 21:33:25 +0000 (23:33 +0200)
committerKarl Hasselström <kha@treskal.com>
Tue, 20 May 2008 21:33:25 +0000 (23:33 +0200)
This simplifies the code in a number of places.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/coalesce.py
stgit/commands/commit.py
stgit/commands/delete.py
stgit/commands/uncommit.py
stgit/lib/stack.py

index 07a9753e5e526198aa5002d2286712c6b0d8c165..412968ad5b796b9ebed63b106b297396a28b654b 100644 (file)
@@ -115,8 +115,7 @@ def _coalesce(stack, iw, name, msg, save_template, patches):
 
 def func(parser, options, args):
     stack = directory.repository.current_stack
 
 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,
     if len(patches) < 2:
         raise common.CmdException('Need at least two patches')
     return _coalesce(stack, stack.repository.default_iw, options.name,
index e95b67f1c5a6aa2b1c0254669b021e9a80d93f0a..cc2f13a4b3a8db5521eba8e02b8a60077eacf7b0 100644 (file)
@@ -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
 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:
     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'
         bad = set(args) - set(patches)
         if bad:
             raise common.CmdException('Bad patch names: %s'
index 13a23c6946317a6000c59b12ef0aaf4c50952acb..de46085f871d5768c57f39ebed45b08e41696b8d 100644 (file)
@@ -41,9 +41,7 @@ def func(parser, options, args):
         stack = directory.repository.current_stack
         iw = stack.repository.default_iw
     if 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):
     else:
         parser.error('No patches specified')
     def allow_conflicts(trans):
index 05e49e01f952268fd571211e9f95adb79f61d300..eb39fcc0a3ffa4a7004cde22af25f42579a438e2 100644 (file)
@@ -116,7 +116,7 @@ def func(parser, options, args):
             next_commit = get_parent(next_commit)
         patch_nr = len(commits)
 
             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:
     if patchnames:
         for pn in patchnames:
             if pn in taken_names:
index 3de3776900755c1f28c96fc6b87dd5c344e168f3..af1c9944f24188412a13f3d7cad84fcdfc1127b8 100644 (file)
@@ -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))
                        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."""
 
 class Patches(object):
     """Creates Patch objects."""