[ "$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 ()
{
# 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 ;;
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')]
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)
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'),
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:
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)
"""
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
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))
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)
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')]
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)
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
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:
# 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()
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
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
"""
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)
[ $(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' \
'
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 ]
'