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