Slightly modify the "publish" command description
[stgit] / stgit / commands / series.py
1
2 __copyright__ = """
3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4
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.
8
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.
13
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
17 """
18
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
24 from stgit import argparse
25
26 help = 'Print the patch series'
27 kind = 'stack'
28 usage = ['[options] [<patch-range>]']
29 description = """
30 Show all the patches in the series, or just those in the given range,
31 ordered from top to bottom.
32
33 The applied patches are prefixed with a +++ (except the current patch,
34 which is prefixed with a +>+), the unapplied patches with a +-+, and
35 the hidden patches with a +!+.
36
37 Empty patches are prefixed with a '0'."""
38
39 args = [argparse.patch_range(argparse.applied_patches,
40 argparse.unapplied_patches,
41 argparse.hidden_patches)]
42 options = [
43 opt('-b', '--branch', args = [argparse.stg_branches],
44 short = 'Use BRANCH instead of the default branch'),
45 opt('-a', '--all', action = 'store_true',
46 short = 'Show all patches, including the hidden ones'),
47 opt('-A', '--applied', action = 'store_true',
48 short = 'Show the applied patches only'),
49 opt('-U', '--unapplied', action = 'store_true',
50 short = 'Show the unapplied patches only'),
51 opt('-H', '--hidden', action = 'store_true',
52 short = 'Show the hidden patches only'),
53 opt('-m', '--missing', metavar = 'BRANCH', args = [argparse.stg_branches],
54 short = 'Show patches in BRANCH missing in current'),
55 opt('-c', '--count', action = 'store_true',
56 short = 'Print the number of patches in the series'),
57 opt('-d', '--description', action = 'store_true',
58 short = 'Show a short description for each patch'),
59 opt('--author', action = 'store_true',
60 short = 'Show the author name for each patch'),
61 opt('-e', '--empty', action = 'store_true',
62 short = 'Check whether patches are empty', long = """
63 Before the +++, +>+, +-+, and +!+ prefixes, print a column
64 that contains either +0+ (for empty patches) or a space (for
65 non-empty patches)."""),
66 opt('--showbranch', action = 'store_true',
67 short = 'Append the branch name to the listed patches'),
68 opt('--noprefix', action = 'store_true',
69 short = 'Do not show the patch status prefix'),
70 opt('-s', '--short', action = 'store_true',
71 short = 'List just the patches around the topmost patch')]
72
73 directory = common.DirectoryHasRepositoryLib()
74
75 def __get_description(stack, patch):
76 """Extract and return a patch's short description
77 """
78 cd = stack.patches.get(patch).commit.data
79 descr = cd.message.strip()
80 descr_lines = descr.split('\n')
81 return descr_lines[0].rstrip()
82
83 def __get_author(stack, patch):
84 """Extract and return a patch's short description
85 """
86 cd = stack.patches.get(patch).commit.data
87 return cd.author.name
88
89 def __print_patch(stack, patch, branch_str, prefix, length, options):
90 """Print a patch name, description and various markers.
91 """
92 if options.noprefix:
93 prefix = ''
94 elif options.empty:
95 if stack.patches.get(patch).is_empty():
96 prefix = '0' + prefix
97 else:
98 prefix = ' ' + prefix
99
100 patch_str = branch_str + patch
101
102 if options.description or options.author:
103 patch_str = patch_str.ljust(length)
104
105 if options.description:
106 out.stdout(prefix + patch_str + ' # ' + __get_description(stack, patch))
107 elif options.author:
108 out.stdout(prefix + patch_str + ' # ' + __get_author(stack, patch))
109 else:
110 out.stdout(prefix + patch_str)
111
112 def func(parser, options, args):
113 """Show the patch series
114 """
115 if options.all and options.short:
116 raise common.CmdException, 'combining --all and --short is meaningless'
117
118 stack = directory.repository.get_stack(options.branch)
119 if options.missing:
120 cmp_stack = stack
121 stack = directory.repository.get_stack(options.missing)
122
123 # current series patches
124 applied = unapplied = hidden = ()
125 if options.applied or options.unapplied or options.hidden:
126 if options.all:
127 raise common.CmdException, \
128 '--all cannot be used with --applied/unapplied/hidden'
129 if options.applied:
130 applied = stack.patchorder.applied
131 if options.unapplied:
132 unapplied = stack.patchorder.unapplied
133 if options.hidden:
134 hidden = stack.patchorder.hidden
135 elif options.all:
136 applied = stack.patchorder.applied
137 unapplied = stack.patchorder.unapplied
138 hidden = stack.patchorder.hidden
139 else:
140 applied = stack.patchorder.applied
141 unapplied = stack.patchorder.unapplied
142
143 if options.missing:
144 cmp_patches = cmp_stack.patchorder.all
145 else:
146 cmp_patches = ()
147
148 # the filtering range covers the whole series
149 if args:
150 show_patches = parse_patches(args, applied + unapplied + hidden,
151 len(applied))
152 else:
153 show_patches = applied + unapplied + hidden
154
155 # missing filtering
156 show_patches = [p for p in show_patches if p not in cmp_patches]
157
158 # filter the patches
159 applied = [p for p in applied if p in show_patches]
160 unapplied = [p for p in unapplied if p in show_patches]
161 hidden = [p for p in hidden if p in show_patches]
162
163 if options.short:
164 nr = int(config.get('stgit.shortnr'))
165 if len(applied) > nr:
166 applied = applied[-(nr+1):]
167 n = len(unapplied)
168 if n > nr:
169 unapplied = unapplied[:nr]
170 elif n < nr:
171 hidden = hidden[:nr-n]
172
173 patches = applied + unapplied + hidden
174
175 if options.count:
176 out.stdout(len(patches))
177 return
178
179 if not patches:
180 return
181
182 if options.showbranch:
183 branch_str = stack.name + ':'
184 else:
185 branch_str = ''
186
187 max_len = 0
188 if len(patches) > 0:
189 max_len = max([len(i + branch_str) for i in patches])
190
191 if applied:
192 for p in applied[:-1]:
193 __print_patch(stack, p, branch_str, '+ ', max_len, options)
194 __print_patch(stack, applied[-1], branch_str, '> ', max_len,
195 options)
196
197 for p in unapplied:
198 __print_patch(stack, p, branch_str, '- ', max_len, options)
199
200 for p in hidden:
201 __print_patch(stack, p, branch_str, '! ', max_len, options)