Commit | Line | Data |
---|---|---|
fcee87cf CM |
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 | import sys, os | |
20 | from optparse import OptionParser, make_option | |
21 | ||
19ac8fe4 | 22 | import stgit.commands.common |
fcee87cf CM |
23 | from stgit.commands.common import * |
24 | from stgit.utils import * | |
5e888f30 | 25 | from stgit.out import * |
fcee87cf CM |
26 | from stgit import stack, git |
27 | ||
28 | ||
29 | help = 'print the patch series' | |
0aebdb85 | 30 | usage = """%prog [options] [<patch-range>] |
26aab5b0 | 31 | |
0aebdb85 | 32 | Show all the patches in the series or just those in the given |
ca8b854c CM |
33 | range. The applied patches are prefixed with a '+', the unapplied ones |
34 | with a '-' and the hidden ones with a '!'. The current patch is | |
35 | prefixed with a '>'. Empty patches are prefixed with a '0'.""" | |
fcee87cf | 36 | |
6dd8fafa | 37 | directory = DirectoryHasRepository() |
2f7c8b0b | 38 | options = [make_option('-b', '--branch', |
2f206b8f | 39 | help = 'use BRANCH instead of the default one'), |
841c7b2a CM |
40 | make_option('-a', '--all', |
41 | help = 'show all patches, including the hidden ones', | |
42 | action = 'store_true'), | |
43 | make_option('-i', '--invisible', | |
44 | help = 'show the hidden patches only', | |
45 | action = 'store_true'), | |
19ac8fe4 CM |
46 | make_option('-m', '--missing', metavar = 'BRANCH', |
47 | help = 'show patches in BRANCH missing in current'), | |
948dae34 CL |
48 | make_option('-c', '--count', |
49 | help = 'print the number of patches in the series', | |
50 | action = 'store_true'), | |
f82e85bc | 51 | make_option('-d', '--description', |
d33c40f1 | 52 | help = 'show a short description for each patch', |
f82e85bc | 53 | action = 'store_true'), |
54fac8e6 CM |
54 | make_option('--author', |
55 | help = 'show the author name for each patch', | |
56 | action = 'store_true'), | |
2f206b8f | 57 | make_option('-e', '--empty', |
9f00453e PBG |
58 | help = 'check whether patches are empty ' |
59 | '(much slower)', | |
47d6ad47 | 60 | action = 'store_true'), |
f483998b CM |
61 | make_option('--showbranch', |
62 | help = 'append the branch name to the listed patches', | |
63 | action = 'store_true'), | |
64 | make_option('--noprefix', | |
65 | help = 'do not show the patch status prefix', | |
66 | action = 'store_true'), | |
47d6ad47 CL |
67 | make_option('-s', '--short', |
68 | help = 'list just the patches around the topmost patch', | |
43e97a20 CM |
69 | action = 'store_true'), |
70 | make_option('-g', '--graphical', | |
71 | help = 'run gitk instead of printing', | |
72 | action = 'store_true')] | |
fcee87cf CM |
73 | |
74 | ||
f82e85bc CL |
75 | def __get_description(patch): |
76 | """Extract and return a patch's short description | |
77 | """ | |
78 | p = crt_series.get_patch(patch) | |
d2a327a8 | 79 | descr = (p.get_description() or '').strip() |
f82e85bc CL |
80 | descr_lines = descr.split('\n') |
81 | return descr_lines[0].rstrip() | |
82 | ||
54fac8e6 CM |
83 | def __get_author(patch): |
84 | """Extract and return a patch's short description | |
85 | """ | |
86 | p = crt_series.get_patch(patch) | |
87 | return p.get_authname(); | |
88 | ||
ca8b854c | 89 | def __print_patch(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 = '' | |
94 | elif options.empty and crt_series.empty_patch(patch): | |
f82e85bc | 95 | prefix = empty_prefix |
f483998b CM |
96 | |
97 | patch_str = patch + branch_str | |
98 | ||
54fac8e6 CM |
99 | if options.description or options.author: |
100 | patch_str = patch_str.ljust(length) | |
101 | ||
f82e85bc | 102 | if options.description: |
809f4f1c | 103 | out.stdout(prefix + patch_str + ' # ' + __get_description(patch)) |
54fac8e6 | 104 | elif options.author: |
809f4f1c | 105 | out.stdout(prefix + patch_str + ' # ' + __get_author(patch)) |
f82e85bc | 106 | else: |
27ac2b7e | 107 | out.stdout(prefix + patch_str) |
f82e85bc | 108 | |
fcee87cf CM |
109 | def func(parser, options, args): |
110 | """Show the patch series | |
111 | """ | |
19ac8fe4 CM |
112 | global crt_series |
113 | ||
1f396835 YD |
114 | if options.all and options.short: |
115 | raise CmdException, 'combining --all and --short is meaningless' | |
116 | ||
ca8b854c CM |
117 | # current series patches |
118 | if options.invisible: | |
119 | applied = unapplied = [] | |
120 | hidden = crt_series.get_hidden() | |
121 | elif options.all: | |
122 | applied = crt_series.get_applied() | |
123 | unapplied = crt_series.get_unapplied() | |
124 | hidden = crt_series.get_hidden() | |
125 | else: | |
126 | applied = crt_series.get_applied() | |
127 | unapplied = crt_series.get_unapplied() | |
128 | hidden = [] | |
129 | ||
19ac8fe4 CM |
130 | if options.missing: |
131 | # switch the series, the one specified with --missing should | |
132 | # become the current | |
133 | cmp_series = crt_series | |
134 | crt_series = stack.Series(options.missing) | |
135 | stgit.commands.common.crt_series = crt_series | |
136 | ||
ca8b854c CM |
137 | cmp_patches = applied + unapplied + hidden |
138 | ||
139 | # new current series patches | |
140 | if options.invisible: | |
141 | applied = unapplied = [] | |
142 | hidden = crt_series.get_hidden() | |
143 | elif options.all: | |
144 | applied = crt_series.get_applied() | |
145 | unapplied = crt_series.get_unapplied() | |
146 | hidden = crt_series.get_hidden() | |
147 | else: | |
148 | applied = crt_series.get_applied() | |
149 | unapplied = crt_series.get_unapplied() | |
150 | hidden = [] | |
19ac8fe4 CM |
151 | else: |
152 | cmp_patches = [] | |
153 | ||
0aebdb85 CM |
154 | # the filtering range covers the whole series |
155 | if args: | |
ca8b854c CM |
156 | show_patches = parse_patches(args, applied + unapplied + hidden, |
157 | len(applied)) | |
0aebdb85 | 158 | else: |
ca8b854c | 159 | show_patches = applied + unapplied + hidden |
0aebdb85 | 160 | |
841c7b2a CM |
161 | # missing filtering |
162 | show_patches = [p for p in show_patches if p not in cmp_patches] | |
163 | ||
0aebdb85 | 164 | # filter the patches |
841c7b2a CM |
165 | applied = [p for p in applied if p in show_patches] |
166 | unapplied = [p for p in unapplied if p in show_patches] | |
ca8b854c | 167 | hidden = [p for p in hidden if p in show_patches] |
948dae34 | 168 | |
47d6ad47 | 169 | if options.short: |
c73e63b7 | 170 | nr = int(config.get('stgit.shortnr')) |
c6f366f6 CM |
171 | if len(applied) > nr: |
172 | applied = applied[-(nr+1):] | |
ca8b854c CM |
173 | n = len(unapplied) |
174 | if n > nr: | |
c6f366f6 | 175 | unapplied = unapplied[:nr] |
ca8b854c CM |
176 | elif n < nr: |
177 | hidden = hidden[:nr-n] | |
47d6ad47 | 178 | |
ca8b854c | 179 | patches = applied + unapplied + hidden |
0aebdb85 CM |
180 | |
181 | if options.count: | |
27ac2b7e | 182 | out.stdout(len(patches)) |
0aebdb85 CM |
183 | return |
184 | ||
43e97a20 CM |
185 | if not patches: |
186 | return | |
187 | ||
f483998b | 188 | if options.showbranch: |
d37ff079 | 189 | branch_str = '@' + crt_series.get_name() |
f483998b CM |
190 | else: |
191 | branch_str = '' | |
192 | ||
43e97a20 | 193 | if options.graphical: |
19ac8fe4 CM |
194 | if options.missing: |
195 | raise CmdException, '--graphical not supported with --missing' | |
196 | ||
e2c86cde | 197 | gitk_args = [] |
43e97a20 | 198 | if applied: |
e2c86cde CM |
199 | gitk_args.append('%s^..%s' |
200 | % (git_id(crt_series, applied[0]), | |
201 | git_id(crt_series, applied[-1]))) | |
43e97a20 | 202 | for p in unapplied: |
6972fd6b | 203 | patch_id = git_id(crt_series, p) |
e2c86cde | 204 | gitk_args.append('%s^..%s' % (patch_id, patch_id)) |
43e97a20 | 205 | |
e2c86cde CM |
206 | # discard the exit codes generated by SIGINT, SIGKILL, SIGTERM |
207 | Run('gitk', *gitk_args).returns([0, -2, -9, -15]).run() | |
43e97a20 CM |
208 | else: |
209 | max_len = 0 | |
210 | if len(patches) > 0: | |
f483998b | 211 | max_len = max([len(i + branch_str) for i in patches]) |
841c7b2a | 212 | |
ca8b854c CM |
213 | if applied: |
214 | for p in applied[:-1]: | |
215 | __print_patch(p, branch_str, '+ ', '0 ', max_len, options) | |
216 | __print_patch(applied[-1], branch_str, '> ', '0>', max_len, | |
217 | options) | |
f82e85bc | 218 | |
43e97a20 | 219 | for p in unapplied: |
ca8b854c CM |
220 | __print_patch(p, branch_str, '- ', '0 ', max_len, options) |
221 | ||
222 | for p in hidden: | |
2270bc4d | 223 | __print_patch(p, branch_str, '! ', '! ', max_len, options) |