Remove the applied/unapplied commands
[stgit] / stgit / commands / series.py
CommitLineData
fcee87cf
CM
1
2__copyright__ = """
3Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License version 2 as
7published by the Free Software Foundation.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17"""
18
448e5d9d 19from optparse import make_option
fcee87cf 20
448e5d9d
CM
21from stgit.commands import common
22from stgit.commands.common import parse_patches
23from stgit.out import out
fcee87cf
CM
24
25help = 'print the patch series'
0aebdb85 26usage = """%prog [options] [<patch-range>]
26aab5b0 27
0aebdb85 28Show all the patches in the series or just those in the given
ca8b854c
CM
29range. The applied patches are prefixed with a '+', the unapplied ones
30with a '-' and the hidden ones with a '!'. The current patch is
31prefixed with a '>'. Empty patches are prefixed with a '0'."""
fcee87cf 32
448e5d9d
CM
33directory = common.DirectoryHasRepositoryLib()
34
2f7c8b0b 35options = [make_option('-b', '--branch',
2f206b8f 36 help = 'use BRANCH instead of the default one'),
841c7b2a
CM
37 make_option('-a', '--all',
38 help = 'show all patches, including the hidden ones',
39 action = 'store_true'),
f9d9a062
CM
40 make_option('-A', '--applied',
41 help = 'show the applied patches only',
42 action = 'store_true'),
43 make_option('-U', '--unapplied',
44 help = 'show the unapplied patches only',
45 action = 'store_true'),
46 make_option('-H', '--hidden',
841c7b2a
CM
47 help = 'show the hidden patches only',
48 action = 'store_true'),
19ac8fe4
CM
49 make_option('-m', '--missing', metavar = 'BRANCH',
50 help = 'show patches in BRANCH missing in current'),
948dae34
CL
51 make_option('-c', '--count',
52 help = 'print the number of patches in the series',
53 action = 'store_true'),
f82e85bc 54 make_option('-d', '--description',
d33c40f1 55 help = 'show a short description for each patch',
f82e85bc 56 action = 'store_true'),
54fac8e6
CM
57 make_option('--author',
58 help = 'show the author name for each patch',
59 action = 'store_true'),
2f206b8f 60 make_option('-e', '--empty',
9f00453e
PBG
61 help = 'check whether patches are empty '
62 '(much slower)',
47d6ad47 63 action = 'store_true'),
f483998b
CM
64 make_option('--showbranch',
65 help = 'append the branch name to the listed patches',
66 action = 'store_true'),
67 make_option('--noprefix',
68 help = 'do not show the patch status prefix',
69 action = 'store_true'),
47d6ad47
CL
70 make_option('-s', '--short',
71 help = 'list just the patches around the topmost patch',
43e97a20 72 action = 'store_true')]
fcee87cf
CM
73
74
448e5d9d 75def __get_description(stack, patch):
f82e85bc
CL
76 """Extract and return a patch's short description
77 """
448e5d9d
CM
78 cd = stack.patches.get(patch).commit.data
79 descr = cd.message.strip()
f82e85bc
CL
80 descr_lines = descr.split('\n')
81 return descr_lines[0].rstrip()
82
448e5d9d 83def __get_author(stack, patch):
54fac8e6
CM
84 """Extract and return a patch's short description
85 """
448e5d9d
CM
86 cd = stack.patches.get(patch).commit.data
87 return cd.author.name
54fac8e6 88
448e5d9d 89def __print_patch(stack, patch, branch_str, prefix, empty_prefix, length, options):
841c7b2a
CM
90 """Print a patch name, description and various markers.
91 """
f483998b
CM
92 if options.noprefix:
93 prefix = ''
448e5d9d 94 elif options.empty and stack.patches.get(patch).is_empty():
f82e85bc 95 prefix = empty_prefix
f483998b 96
e4560d7e 97 patch_str = branch_str + patch
f483998b 98
54fac8e6
CM
99 if options.description or options.author:
100 patch_str = patch_str.ljust(length)
101
f82e85bc 102 if options.description:
448e5d9d 103 out.stdout(prefix + patch_str + ' # ' + __get_description(stack, patch))
54fac8e6 104 elif options.author:
448e5d9d 105 out.stdout(prefix + patch_str + ' # ' + __get_author(stack, patch))
f82e85bc 106 else:
27ac2b7e 107 out.stdout(prefix + patch_str)
f82e85bc 108
fcee87cf
CM
109def func(parser, options, args):
110 """Show the patch series
111 """
1f396835 112 if options.all and options.short:
448e5d9d
CM
113 raise common.CmdException, 'combining --all and --short is meaningless'
114
13b26f1a 115 stack = directory.repository.get_stack(options.branch)
448e5d9d
CM
116 if options.missing:
117 cmp_stack = stack
118 stack = directory.repository.get_stack(options.missing)
119
ca8b854c 120 # current series patches
f9d9a062
CM
121 applied = unapplied = hidden = ()
122 if options.applied or options.unapplied or options.hidden:
123 if options.all:
124 raise common.CmdException, \
125 '--all cannot be used with --applied/unapplied/hidden'
126 if options.applied:
127 applied = stack.patchorder.applied
128 if options.unapplied:
129 unapplied = stack.patchorder.unapplied
130 if options.hidden:
131 hidden = stack.patchorder.hidden
132 elif options.all:
448e5d9d
CM
133 applied = stack.patchorder.applied
134 unapplied = stack.patchorder.unapplied
135 hidden = stack.patchorder.hidden
ca8b854c 136 else:
448e5d9d
CM
137 applied = stack.patchorder.applied
138 unapplied = stack.patchorder.unapplied
ca8b854c 139
19ac8fe4 140 if options.missing:
448e5d9d 141 cmp_patches = cmp_stack.patchorder.all
19ac8fe4 142 else:
448e5d9d 143 cmp_patches = ()
19ac8fe4 144
0aebdb85
CM
145 # the filtering range covers the whole series
146 if args:
ca8b854c
CM
147 show_patches = parse_patches(args, applied + unapplied + hidden,
148 len(applied))
0aebdb85 149 else:
ca8b854c 150 show_patches = applied + unapplied + hidden
0aebdb85 151
841c7b2a
CM
152 # missing filtering
153 show_patches = [p for p in show_patches if p not in cmp_patches]
154
0aebdb85 155 # filter the patches
841c7b2a
CM
156 applied = [p for p in applied if p in show_patches]
157 unapplied = [p for p in unapplied if p in show_patches]
ca8b854c 158 hidden = [p for p in hidden if p in show_patches]
948dae34 159
47d6ad47 160 if options.short:
c73e63b7 161 nr = int(config.get('stgit.shortnr'))
c6f366f6
CM
162 if len(applied) > nr:
163 applied = applied[-(nr+1):]
ca8b854c
CM
164 n = len(unapplied)
165 if n > nr:
c6f366f6 166 unapplied = unapplied[:nr]
ca8b854c
CM
167 elif n < nr:
168 hidden = hidden[:nr-n]
47d6ad47 169
ca8b854c 170 patches = applied + unapplied + hidden
0aebdb85
CM
171
172 if options.count:
27ac2b7e 173 out.stdout(len(patches))
0aebdb85
CM
174 return
175
43e97a20
CM
176 if not patches:
177 return
178
f483998b 179 if options.showbranch:
e4560d7e 180 branch_str = stack.name + ':'
f483998b
CM
181 else:
182 branch_str = ''
183
448e5d9d
CM
184 max_len = 0
185 if len(patches) > 0:
186 max_len = max([len(i + branch_str) for i in patches])
841c7b2a 187
448e5d9d
CM
188 if applied:
189 for p in applied[:-1]:
190 __print_patch(stack, p, branch_str, '+ ', '0 ', max_len, options)
191 __print_patch(stack, applied[-1], branch_str, '> ', '0>', max_len,
192 options)
f82e85bc 193
448e5d9d
CM
194 for p in unapplied:
195 __print_patch(stack, p, branch_str, '- ', '0 ', max_len, options)
ca8b854c 196
448e5d9d
CM
197 for p in hidden:
198 __print_patch(stack, p, branch_str, '! ', '! ', max_len, options)