3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 from stgit.argparse import opt
20 from stgit.commands import common
21 from stgit.commands.common import parse_patches
22 from stgit.out import out
23 from stgit.config import config
25 help = 'Print the patch series'
26 usage = ['[options] [<patch-range>]']
28 Show all the patches in the series or just those in the given
29 range. The applied patches are prefixed with a '+', the unapplied ones
30 with a '-' and the hidden ones with a '!'. The current patch is
31 prefixed with a '>'. Empty patches are prefixed with a '0'."""
35 short = 'Use BRANCH instead of the default branch'),
36 opt('-a', '--all', action = 'store_true',
37 short = 'Show all patches, including the hidden ones'),
38 opt('-A', '--applied', action = 'store_true',
39 short = 'Show the applied patches only'),
40 opt('-U', '--unapplied', action = 'store_true',
41 short = 'Show the unapplied patches only'),
42 opt('-H', '--hidden', action = 'store_true',
43 short = 'Show the hidden patches only'),
44 opt('-m', '--missing', metavar = 'BRANCH',
45 short = 'Show patches in BRANCH missing in current'),
46 opt('-c', '--count', action = 'store_true',
47 short = 'Print the number of patches in the series'),
48 opt('-d', '--description', action = 'store_true',
49 short = 'Show a short description for each patch'),
50 opt('--author', action = 'store_true',
51 short = 'Show the author name for each patch'),
52 opt('-e', '--empty', action = 'store_true',
53 short = 'Check whether patches are empty'),
54 opt('--showbranch', action = 'store_true',
55 short = 'Append the branch name to the listed patches'),
56 opt('--noprefix', action = 'store_true',
57 short = 'Do not show the patch status prefix'),
58 opt('-s', '--short', action = 'store_true',
59 short = 'List just the patches around the topmost patch')]
61 directory = common.DirectoryHasRepositoryLib()
63 def __get_description(stack, patch):
64 """Extract and return a patch's short description
66 cd = stack.patches.get(patch).commit.data
67 descr = cd.message.strip()
68 descr_lines = descr.split('\n')
69 return descr_lines[0].rstrip()
71 def __get_author(stack, patch):
72 """Extract and return a patch's short description
74 cd = stack.patches.get(patch).commit.data
77 def __print_patch(stack, patch, branch_str, prefix, empty_prefix, length, options):
78 """Print a patch name, description and various markers.
82 elif options.empty and stack.patches.get(patch).is_empty():
85 patch_str = branch_str + patch
87 if options.description or options.author:
88 patch_str = patch_str.ljust(length)
90 if options.description:
91 out.stdout(prefix + patch_str + ' # ' + __get_description(stack, patch))
93 out.stdout(prefix + patch_str + ' # ' + __get_author(stack, patch))
95 out.stdout(prefix + patch_str)
97 def func(parser, options, args):
98 """Show the patch series
100 if options.all and options.short:
101 raise common.CmdException, 'combining --all and --short is meaningless'
103 stack = directory.repository.get_stack(options.branch)
106 stack = directory.repository.get_stack(options.missing)
108 # current series patches
109 applied = unapplied = hidden = ()
110 if options.applied or options.unapplied or options.hidden:
112 raise common.CmdException, \
113 '--all cannot be used with --applied/unapplied/hidden'
115 applied = stack.patchorder.applied
116 if options.unapplied:
117 unapplied = stack.patchorder.unapplied
119 hidden = stack.patchorder.hidden
121 applied = stack.patchorder.applied
122 unapplied = stack.patchorder.unapplied
123 hidden = stack.patchorder.hidden
125 applied = stack.patchorder.applied
126 unapplied = stack.patchorder.unapplied
129 cmp_patches = cmp_stack.patchorder.all
133 # the filtering range covers the whole series
135 show_patches = parse_patches(args, applied + unapplied + hidden,
138 show_patches = applied + unapplied + hidden
141 show_patches = [p for p in show_patches if p not in cmp_patches]
144 applied = [p for p in applied if p in show_patches]
145 unapplied = [p for p in unapplied if p in show_patches]
146 hidden = [p for p in hidden if p in show_patches]
149 nr = int(config.get('stgit.shortnr'))
150 if len(applied) > nr:
151 applied = applied[-(nr+1):]
154 unapplied = unapplied[:nr]
156 hidden = hidden[:nr-n]
158 patches = applied + unapplied + hidden
161 out.stdout(len(patches))
167 if options.showbranch:
168 branch_str = stack.name + ':'
174 max_len = max([len(i + branch_str) for i in patches])
177 for p in applied[:-1]:
178 __print_patch(stack, p, branch_str, '+ ', '0 ', max_len, options)
179 __print_patch(stack, applied[-1], branch_str, '> ', '0>', max_len,
183 __print_patch(stack, p, branch_str, '- ', '0 ', max_len, options)
186 __print_patch(stack, p, branch_str, '! ', '! ', max_len, options)