chiark / gitweb /
Fix the hidden patches functionality (bug #9077)
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 8 Jun 2007 22:13:34 +0000 (23:13 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 8 Jun 2007 22:13:34 +0000 (23:13 +0100)
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 <catalin.marinas@gmail.com>
contrib/stgit-completion.bash
stgit/commands/hide.py
stgit/commands/series.py
stgit/commands/unhide.py
stgit/stack.py
t/t1600-delete-one.sh

index d4970989435805c42a7e557f6b8c8378092a70ea..a843db4407140dd68179950e51b82ba08cefe34e 100644 (file)
@@ -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 ;;
index 3cb08e89586631f1c65506f16744e1cd6c6e2086..39cbd6718ade7d7442887883e02a54301001735d 100644 (file)
@@ -24,10 +24,10 @@ from stgit import stack, git
 
 
 help = 'hide a patch in the series'
-usage = """%prog [options] [<patch-range>]
+usage = """%prog [options] <patch-range>
 
-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)
index b699902f8d4020eb964f53aa1a33a2734eae28a1..402356ccae3a53c458d270e5953a976c9806b171 100644 (file)
@@ -29,10 +29,9 @@ help = 'print the patch series'
 usage = """%prog [options] [<patch-range>]
 
 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)
index 74e4743e0fc474818b89b35817d657bc2e80c138..b6a229711229fedfec1cc89070f3e174677ca85d 100644 (file)
@@ -24,10 +24,10 @@ from stgit import stack, git
 
 
 help = 'unhide a hidden patch in the series'
-usage = """%prog [options] [<patch-range>]
+usage = """%prog [options] <patch-range>
 
-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)
index f4782a42b619821625c11002c361e0048dde4b9e..9338f2b9f6a0366aa9c1824ccbaf0c9098095e8b 100644 (file)
@@ -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)
index d59d4baffc3b05d68c800d1016d499d0c5f611e3..df03d79c860db85377e3bac80eab8c1aca83f6ab 100755 (executable)
@@ -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 ]
     '