From ca8b854cbf353ed87fd9284d50f69229bf40e22d Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Fri, 8 Jun 2007 23:13:34 +0100 Subject: [PATCH] Fix the hidden patches functionality (bug #9077) Organization: Straylight/Edgeware From: Catalin Marinas This patch fixes the misleading functionality of hiding/unhiding patches. Only unapplied patches can be hidden and they are now on a separate list. Commands like 'stg push --all' will not push hidden patches. Signed-off-by: Catalin Marinas --- contrib/stgit-completion.bash | 11 ++++- stgit/commands/hide.py | 19 ++++---- stgit/commands/series.py | 88 +++++++++++++++++++---------------- stgit/commands/unhide.py | 19 ++++---- stgit/stack.py | 56 ++++++++++++---------- t/t1600-delete-one.sh | 13 +----- 6 files changed, 110 insertions(+), 96 deletions(-) diff --git a/contrib/stgit-completion.bash b/contrib/stgit-completion.bash index d497098..a843db4 100644 --- a/contrib/stgit-completion.bash +++ b/contrib/stgit-completion.bash @@ -81,6 +81,13 @@ _unapplied_patches () [ "$g" ] && cat "$g/patches/$(_current_branch)/unapplied" } +# List of all applied patches. +_hidden_patches () +{ + local g=$(_gitdir) + [ "$g" ] && cat "$g/patches/$(_current_branch)/hidden" +} + # List of all patches. _all_patches () { @@ -203,12 +210,12 @@ _stg () # stack commands float) _stg_patches $command _all_patches ;; goto) _stg_patches $command _all_other_patches ;; - hide) _stg_patches $command _all_patches ;; + hide) _stg_patches $command _unapplied_patches ;; pop) _stg_patches $command _applied_patches ;; push) _stg_patches $command _unapplied_patches ;; series) _stg_patches $command _all_patches ;; sink) _stg_patches $command _all_patches ;; - unhide) _stg_patches $command _all_patches ;; + unhide) _stg_patches $command _hidden_patches ;; # patch commands delete) _stg_patches $command _all_patches ;; export) _stg_patches $command _applied_patches ;; diff --git a/stgit/commands/hide.py b/stgit/commands/hide.py index 3cb08e8..39cbd67 100644 --- a/stgit/commands/hide.py +++ b/stgit/commands/hide.py @@ -24,10 +24,10 @@ from stgit import stack, git help = 'hide a patch in the series' -usage = """%prog [options] [] +usage = """%prog [options] -Hide a range of patches or the current one so that they are no longer -shown in the plain 'series' command output.""" +Hide a range of unapplied patches so that they are no longer shown in +the plain 'series' command output.""" options = [make_option('-b', '--branch', help = 'use BRANCH instead of the default one')] @@ -35,14 +35,13 @@ options = [make_option('-b', '--branch', def func(parser, options, args): """Hide a range of patch in the series """ - if not args: - patches = [crt_series.get_current()] + if args: + # parsing all the patches for a more meaningful error reporting + all_patches = crt_series.get_applied() + crt_series.get_unapplied() \ + + crt_series.get_hidden() + patches = parse_patches(args, all_patches) else: - applied = crt_series.get_applied() - unapplied = crt_series.get_unapplied() - patches = parse_patches(args, applied + unapplied, len(applied)) - - patches = [p for p in patches if p not in crt_series.get_hidden()] + parser.error('No patches specified') for patch in patches: crt_series.hide_patch(patch) diff --git a/stgit/commands/series.py b/stgit/commands/series.py index b699902..402356c 100644 --- a/stgit/commands/series.py +++ b/stgit/commands/series.py @@ -29,10 +29,9 @@ help = 'print the patch series' usage = """%prog [options] [] Show all the patches in the series or just those in the given -range. The applied patches are prefixed with a '+' and the unapplied -ones with a '-'. The current patch is prefixed with a '>'. Empty -patches are prefixed with a '0'. The '*' postfix is appended to hidden -patches.""" +range. The applied patches are prefixed with a '+', the unapplied ones +with a '-' and the hidden ones with a '!'. The current patch is +prefixed with a '>'. Empty patches are prefixed with a '0'.""" options = [make_option('-b', '--branch', help = 'use BRANCH instead of the default one'), @@ -85,8 +84,7 @@ def __get_author(patch): p = crt_series.get_patch(patch) return p.get_authname(); -def __print_patch(patch, hidden, branch_str, prefix, empty_prefix, length, - options): +def __print_patch(patch, branch_str, prefix, empty_prefix, length, options): """Print a patch name, description and various markers. """ if options.noprefix: @@ -95,8 +93,6 @@ def __print_patch(patch, hidden, branch_str, prefix, empty_prefix, length, prefix = empty_prefix patch_str = patch + branch_str - if not options.noprefix and patch in hidden: - patch_str += '*' if options.description or options.author: patch_str = patch_str.ljust(length) @@ -113,6 +109,19 @@ def func(parser, options, args): """ global crt_series + # current series patches + if options.invisible: + applied = unapplied = [] + hidden = crt_series.get_hidden() + elif options.all: + applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() + hidden = crt_series.get_hidden() + else: + applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() + hidden = [] + if options.missing: # switch the series, the one specified with --missing should # become the current @@ -120,41 +129,49 @@ def func(parser, options, args): crt_series = stack.Series(options.missing) stgit.commands.common.crt_series = crt_series - cmp_patches = cmp_series.get_applied() + cmp_series.get_unapplied() + cmp_patches = applied + unapplied + hidden + + # new current series patches + if options.invisible: + applied = unapplied = [] + hidden = crt_series.get_hidden() + elif options.all: + applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() + hidden = crt_series.get_hidden() + else: + applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() + hidden = [] else: cmp_patches = [] - applied = crt_series.get_applied() - unapplied = crt_series.get_unapplied() - # the filtering range covers the whole series if args: - show_patches = parse_patches(args, applied + unapplied, len(applied)) + show_patches = parse_patches(args, applied + unapplied + hidden, + len(applied)) else: - show_patches = applied + unapplied + show_patches = applied + unapplied + hidden # missing filtering show_patches = [p for p in show_patches if p not in cmp_patches] - # hidden patches filtering - hidden = crt_series.get_hidden() - if options.invisible: - show_patches = [p for p in show_patches if p in hidden] - elif not options.all: - show_patches = [p for p in show_patches if p not in hidden] - # filter the patches applied = [p for p in applied if p in show_patches] unapplied = [p for p in unapplied if p in show_patches] + hidden = [p for p in hidden if p in show_patches] if options.short: nr = int(config.get('stgit.shortnr')) if len(applied) > nr: applied = applied[-(nr+1):] - if len(unapplied) > nr: + n = len(unapplied) + if n > nr: unapplied = unapplied[:nr] + elif n < nr: + hidden = hidden[:nr-n] - patches = applied + unapplied + patches = applied + unapplied + hidden if options.count: out.stdout(len(patches)) @@ -187,22 +204,15 @@ def func(parser, options, args): max_len = 0 if len(patches) > 0: max_len = max([len(i + branch_str) for i in patches]) - max_len += 1 - - if len(applied) > 0: - current = crt_series.get_current() - if applied[-1] == current: - del applied[-1] - else: - current = None - for p in applied: - __print_patch(p, hidden, branch_str, '+ ', '0 ', max_len, - options) - - if current: - __print_patch(current, hidden, branch_str, '> ', '0>', max_len, - options) + if applied: + for p in applied[:-1]: + __print_patch(p, branch_str, '+ ', '0 ', max_len, options) + __print_patch(applied[-1], branch_str, '> ', '0>', max_len, + options) for p in unapplied: - __print_patch(p, hidden, branch_str, '- ', '0 ', max_len, options) + __print_patch(p, branch_str, '- ', '0 ', max_len, options) + + for p in hidden: + __print_patch(p, branch_str, '! ', '0 ', max_len, options) diff --git a/stgit/commands/unhide.py b/stgit/commands/unhide.py index 74e4743..b6a2297 100644 --- a/stgit/commands/unhide.py +++ b/stgit/commands/unhide.py @@ -24,10 +24,10 @@ from stgit import stack, git help = 'unhide a hidden patch in the series' -usage = """%prog [options] [] +usage = """%prog [options] -Unhide a hidden range of patches or the current one if hidden so that -they are shown in the plain 'series' command output.""" +Unhide a hidden range of patches so that they are shown in the plain +'series' command output.""" options = [make_option('-b', '--branch', help = 'use BRANCH instead of the default one')] @@ -35,14 +35,13 @@ options = [make_option('-b', '--branch', def func(parser, options, args): """Unhide a range of patches in the series """ - if not args: - patches = [crt_series.get_current()] + if args: + # parsing all the patches for a more meaningful error reporting + all_patches = crt_series.get_applied() + crt_series.get_unapplied() \ + + crt_series.get_hidden() + patches = parse_patches(args, all_patches) else: - applied = crt_series.get_applied() - unapplied = crt_series.get_unapplied() - patches = parse_patches(args, applied + unapplied, len(applied)) - - patches = [p for p in patches if p in crt_series.get_hidden()] + parser.error('No patches specified') for patch in patches: crt_series.unhide_patch(patch) diff --git a/stgit/stack.py b/stgit/stack.py index f4782a4..9338f2b 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -553,7 +553,8 @@ class Series(StgitObject): def patch_exists(self, name): """Return true if there is a patch with the given name, false otherwise.""" - return self.patch_applied(name) or self.patch_unapplied(name) + return self.patch_applied(name) or self.patch_unapplied(name) \ + or self.patch_hidden(name) def head_top_equal(self): """Return true if the head and the top are the same @@ -825,7 +826,7 @@ class Series(StgitObject): if name != None: self.__patch_name_valid(name) - if self.patch_applied(name) or self.patch_unapplied(name): + if self.patch_exists(name): raise StackException, 'Patch "%s" already exists' % name if not message and can_edit: @@ -896,9 +897,6 @@ class Series(StgitObject): # save the commit id to a trash file write_string(os.path.join(self.__trash_dir, name), patch.get_top()) - if self.patch_hidden(name): - self.unhide_patch(name) - patch.delete() unapplied = self.get_unapplied() @@ -1168,12 +1166,6 @@ class Series(StgitObject): if newname in applied or newname in unapplied: raise StackException, 'Patch "%s" already exists' % newname - if self.patch_hidden(oldname): - self.unhide_patch(oldname) - was_hidden=True - else: - was_hidden=False - if oldname in unapplied: Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname) unapplied[unapplied.index(oldname)] = newname @@ -1192,9 +1184,6 @@ class Series(StgitObject): else: raise StackException, 'Unknown patch "%s"' % oldname - if was_hidden: - self.hide_patch(newname) - def log_patch(self, patch, message): """Generate a log commit for a patch """ @@ -1215,24 +1204,43 @@ class Series(StgitObject): def hide_patch(self, name): """Add the patch to the hidden list. """ - if not self.patch_exists(name): - raise StackException, 'Unknown patch "%s"' % name - elif self.patch_hidden(name): - raise StackException, 'Patch "%s" already hidden' % name + unapplied = self.get_unapplied() + if name not in unapplied: + # keep the checking order for backward compatibility with + # the old hidden patches functionality + if self.patch_applied(name): + raise StackException, 'Cannot hide applied patch "%s"' % name + elif self.patch_hidden(name): + raise StackException, 'Patch "%s" already hidden' % name + else: + raise StackException, 'Unknown patch "%s"' % name - append_string(self.__hidden_file, name) + if not self.patch_hidden(name): + # check needed for backward compatibility with the old + # hidden patches functionality + append_string(self.__hidden_file, name) + + unapplied.remove(name) + f = file(self.__unapplied_file, 'w+') + f.writelines([line + '\n' for line in unapplied]) + f.close() def unhide_patch(self, name): - """Add the patch to the hidden list. + """Remove the patch from the hidden list. """ - if not self.patch_exists(name): - raise StackException, 'Unknown patch "%s"' % name hidden = self.get_hidden() if not name in hidden: - raise StackException, 'Patch "%s" not hidden' % name + if self.patch_applied(name) or self.patch_unapplied(name): + raise StackException, 'Patch "%s" not hidden' % name + else: + raise StackException, 'Unknown patch "%s"' % name hidden.remove(name) - f = file(self.__hidden_file, 'w+') f.writelines([line + '\n' for line in hidden]) f.close() + + if not self.patch_applied(name) and not self.patch_unapplied(name): + # check needed for backward compatibility with the old + # hidden patches functionality + append_string(self.__unapplied_file, name) diff --git a/t/t1600-delete-one.sh b/t/t1600-delete-one.sh index d59d4ba..df03d79 100755 --- a/t/t1600-delete-one.sh +++ b/t/t1600-delete-one.sh @@ -81,15 +81,6 @@ test_expect_success \ [ $(stg applied | wc -l) -eq 2 ] ' -test_expect_success \ - 'Hide the topmost patch and try to delete it' \ - ' - [ $(stg applied | wc -l) -eq 2 ] && - stg hide bar && - stg delete bar && - [ $(stg applied | wc -l) -eq 1 ] - ' - test_expect_success \ 'Create another branch, and put one patch in each branch' \ ' @@ -108,10 +99,10 @@ test_expect_success \ test_expect_success \ 'Delete a patch in another branch' \ ' - [ $(stg applied | wc -l) -eq 2 ] && + [ $(stg applied | wc -l) -eq 3 ] && [ $(stg applied -b br | wc -l) -eq 1 ] && stg delete -b br baz && - [ $(stg applied | wc -l) -eq 2 ] && + [ $(stg applied | wc -l) -eq 3 ] && [ $(stg applied -b br | wc -l) -eq 0 ] ' -- [mdw]