From 13b26f1a18467e94b444d30d26b3e573c49ebfb3 Mon Sep 17 00:00:00 2001 Message-Id: <13b26f1a18467e94b444d30d26b3e573c49ebfb3.1746782188.git.mdw@distorted.org.uk> From: Mark Wooding Date: Wed, 28 May 2008 22:02:01 +0100 Subject: [PATCH] Allow the Repository.get_stack() to get a default argument Organization: Straylight/Edgeware From: Catalin Marinas If no argument or if it is None, it returns the current stack. This is useful for many of the functions taking a --branch option. Signed-off-by: Catalin Marinas --- stgit/commands/applied.py | 5 +---- stgit/commands/delete.py | 3 +-- stgit/commands/series.py | 5 +---- stgit/commands/unapplied.py | 5 +---- stgit/lib/stack.py | 6 ++++-- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/stgit/commands/applied.py b/stgit/commands/applied.py index 522425b..e57c796 100644 --- a/stgit/commands/applied.py +++ b/stgit/commands/applied.py @@ -42,10 +42,7 @@ def func(parser, options, args): if len(args) != 0: parser.error('incorrect number of arguments') - if options.branch: - s = directory.repository.get_stack(options.branch) - else: - s = directory.repository.current_stack + s = directory.repository.get_stack(options.branch) if options.count: out.stdout(len(s.patchorder.applied)) diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py index de46085..c5d3754 100644 --- a/stgit/commands/delete.py +++ b/stgit/commands/delete.py @@ -34,11 +34,10 @@ options = [make_option('-b', '--branch', def func(parser, options, args): """Delete one or more patches.""" + stack = directory.repository.get_stack(options.branch) if options.branch: - stack = directory.repository.get_stack(options.branch) iw = None # can't use index/workdir to manipulate another branch else: - stack = directory.repository.current_stack iw = stack.repository.default_iw if args: patches = set(common.parse_patches(args, list(stack.patchorder.all))) diff --git a/stgit/commands/series.py b/stgit/commands/series.py index c525b9a..04183bd 100644 --- a/stgit/commands/series.py +++ b/stgit/commands/series.py @@ -106,10 +106,7 @@ def func(parser, options, args): if options.all and options.short: raise common.CmdException, 'combining --all and --short is meaningless' - if options.branch: - stack = directory.repository.get_stack(options.branch) - else: - stack = directory.repository.current_stack + stack = directory.repository.get_stack(options.branch) if options.missing: cmp_stack = stack stack = directory.repository.get_stack(options.missing) diff --git a/stgit/commands/unapplied.py b/stgit/commands/unapplied.py index 7702207..7323346 100644 --- a/stgit/commands/unapplied.py +++ b/stgit/commands/unapplied.py @@ -41,10 +41,7 @@ def func(parser, options, args): if len(args) != 0: parser.error('incorrect number of arguments') - if options.branch: - s = directory.repository.get_stack(options.branch) - else: - s = directory.repository.current_stack + s = directory.repository.get_stack(options.branch) if options.count: out.stdout(len(s.patchorder.unapplied)) diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py index f82562d..6a2b40d 100644 --- a/stgit/lib/stack.py +++ b/stgit/lib/stack.py @@ -172,8 +172,10 @@ class Repository(git.Repository): return utils.strip_leading('refs/heads/', self.head) @property def current_stack(self): - return self.get_stack(self.current_branch) - def get_stack(self, name): + return self.get_stack() + def get_stack(self, name = None): + if not name: + name = self.current_branch if not name in self.__stacks: self.__stacks[name] = Stack(self, name) return self.__stacks[name] -- [mdw]