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 | |
34 | patches are prefixed with a '0'.""" | |
fcee87cf | 35 | |
2f7c8b0b | 36 | options = [make_option('-b', '--branch', |
2f206b8f | 37 | help = 'use BRANCH instead of the default one'), |
19ac8fe4 CM |
38 | make_option('-m', '--missing', metavar = 'BRANCH', |
39 | help = 'show patches in BRANCH missing in current'), | |
948dae34 CL |
40 | make_option('-c', '--count', |
41 | help = 'print the number of patches in the series', | |
42 | action = 'store_true'), | |
f82e85bc | 43 | make_option('-d', '--description', |
d33c40f1 | 44 | help = 'show a short description for each patch', |
f82e85bc | 45 | action = 'store_true'), |
2f206b8f | 46 | make_option('-e', '--empty', |
9f00453e PBG |
47 | help = 'check whether patches are empty ' |
48 | '(much slower)', | |
47d6ad47 | 49 | action = 'store_true'), |
f483998b CM |
50 | make_option('--showbranch', |
51 | help = 'append the branch name to the listed patches', | |
52 | action = 'store_true'), | |
53 | make_option('--noprefix', | |
54 | help = 'do not show the patch status prefix', | |
55 | action = 'store_true'), | |
47d6ad47 CL |
56 | make_option('-s', '--short', |
57 | help = 'list just the patches around the topmost patch', | |
43e97a20 CM |
58 | action = 'store_true'), |
59 | make_option('-g', '--graphical', | |
60 | help = 'run gitk instead of printing', | |
61 | action = 'store_true')] | |
fcee87cf CM |
62 | |
63 | ||
f82e85bc CL |
64 | def __get_description(patch): |
65 | """Extract and return a patch's short description | |
66 | """ | |
67 | p = crt_series.get_patch(patch) | |
d2a327a8 | 68 | descr = (p.get_description() or '').strip() |
f82e85bc CL |
69 | descr_lines = descr.split('\n') |
70 | return descr_lines[0].rstrip() | |
71 | ||
f483998b CM |
72 | def __print_patch(patch, branch_str, prefix, empty_prefix, length, options): |
73 | if options.noprefix: | |
74 | prefix = '' | |
75 | elif options.empty and crt_series.empty_patch(patch): | |
f82e85bc | 76 | prefix = empty_prefix |
f483998b CM |
77 | |
78 | patch_str = patch + branch_str | |
79 | ||
f82e85bc | 80 | if options.description: |
f483998b CM |
81 | print prefix + patch_str.ljust(length) + ' | ' \ |
82 | + __get_description(patch) | |
f82e85bc | 83 | else: |
f483998b | 84 | print prefix + patch_str |
f82e85bc | 85 | |
fcee87cf CM |
86 | def func(parser, options, args): |
87 | """Show the patch series | |
88 | """ | |
19ac8fe4 CM |
89 | global crt_series |
90 | ||
19ac8fe4 CM |
91 | if options.missing: |
92 | # switch the series, the one specified with --missing should | |
93 | # become the current | |
94 | cmp_series = crt_series | |
95 | crt_series = stack.Series(options.missing) | |
96 | stgit.commands.common.crt_series = crt_series | |
97 | ||
98 | cmp_patches = cmp_series.get_applied() + cmp_series.get_unapplied() | |
99 | else: | |
100 | cmp_patches = [] | |
101 | ||
0aebdb85 CM |
102 | applied = crt_series.get_applied() |
103 | unapplied = crt_series.get_unapplied() | |
47d6ad47 | 104 | |
0aebdb85 CM |
105 | # the filtering range covers the whole series |
106 | if args: | |
107 | show_patches = parse_patches(args, applied + unapplied, len(applied)) | |
108 | else: | |
109 | show_patches = applied + unapplied | |
110 | ||
111 | # filter the patches | |
112 | applied = [p for p in applied | |
113 | if p in show_patches and p not in cmp_patches] | |
114 | unapplied = [p for p in unapplied | |
115 | if p in show_patches and p not in cmp_patches] | |
948dae34 | 116 | |
47d6ad47 CL |
117 | if options.short: |
118 | if len(applied) > 5: | |
119 | applied = applied[-6:] | |
120 | if len(unapplied) > 5: | |
121 | unapplied = unapplied[:5] | |
122 | ||
f82e85bc | 123 | patches = applied + unapplied |
0aebdb85 CM |
124 | |
125 | if options.count: | |
126 | print len(patches) | |
127 | return | |
128 | ||
43e97a20 CM |
129 | if not patches: |
130 | return | |
131 | ||
f483998b CM |
132 | if options.showbranch: |
133 | branch_str = '@' + crt_series.get_branch() | |
134 | else: | |
135 | branch_str = '' | |
136 | ||
43e97a20 | 137 | if options.graphical: |
19ac8fe4 CM |
138 | if options.missing: |
139 | raise CmdException, '--graphical not supported with --missing' | |
140 | ||
43e97a20 CM |
141 | if applied: |
142 | gitk_args = ' %s^..%s' % (git_id(applied[0]), git_id(applied[-1])) | |
143 | else: | |
144 | gitk_args = '' | |
f82e85bc | 145 | |
43e97a20 CM |
146 | for p in unapplied: |
147 | patch_id = git_id(p) | |
148 | gitk_args += ' %s^..%s' % (patch_id, patch_id) | |
149 | ||
150 | if os.system('gitk%s' % gitk_args) != 0: | |
151 | raise CmdException, 'gitk execution failed' | |
152 | else: | |
153 | max_len = 0 | |
154 | if len(patches) > 0: | |
f483998b | 155 | max_len = max([len(i + branch_str) for i in patches]) |
f82e85bc | 156 | |
43e97a20 CM |
157 | if len(applied) > 0: |
158 | for p in applied [0:-1]: | |
f483998b | 159 | __print_patch(p, branch_str, '+ ', '0 ', max_len, options) |
f82e85bc | 160 | |
f483998b CM |
161 | __print_patch(applied[-1], branch_str, '> ', '0>', max_len, |
162 | options) | |
f82e85bc | 163 | |
43e97a20 | 164 | for p in unapplied: |
f483998b | 165 | __print_patch(p, branch_str, '- ', '0 ', max_len, options) |