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' | |
26aab5b0 CM |
29 | usage = """%prog [options] |
30 | ||
31 | Show all the patches in the series. The applied patches are prefixed | |
32 | with a '+' and the unapplied ones with a '-'. The current patch is | |
33 | prefixed with a '>'. Empty patches are prefixed with a '0'.""" | |
fcee87cf | 34 | |
2f7c8b0b | 35 | options = [make_option('-b', '--branch', |
2f206b8f | 36 | help = 'use BRANCH instead of the default one'), |
19ac8fe4 CM |
37 | make_option('-m', '--missing', metavar = 'BRANCH', |
38 | help = 'show patches in BRANCH missing in current'), | |
948dae34 CL |
39 | make_option('-c', '--count', |
40 | help = 'print the number of patches in the series', | |
41 | action = 'store_true'), | |
f82e85bc | 42 | make_option('-d', '--description', |
d33c40f1 | 43 | help = 'show a short description for each patch', |
f82e85bc | 44 | action = 'store_true'), |
2f206b8f | 45 | make_option('-e', '--empty', |
9f00453e PBG |
46 | help = 'check whether patches are empty ' |
47 | '(much slower)', | |
47d6ad47 CL |
48 | action = 'store_true'), |
49 | make_option('-s', '--short', | |
50 | help = 'list just the patches around the topmost patch', | |
43e97a20 CM |
51 | action = 'store_true'), |
52 | make_option('-g', '--graphical', | |
53 | help = 'run gitk instead of printing', | |
54 | action = 'store_true')] | |
fcee87cf CM |
55 | |
56 | ||
f82e85bc CL |
57 | def __get_description(patch): |
58 | """Extract and return a patch's short description | |
59 | """ | |
60 | p = crt_series.get_patch(patch) | |
d2a327a8 | 61 | descr = (p.get_description() or '').strip() |
f82e85bc CL |
62 | descr_lines = descr.split('\n') |
63 | return descr_lines[0].rstrip() | |
64 | ||
65 | def __print_patch(patch, prefix, empty_prefix, length, options): | |
66 | if options.empty and crt_series.empty_patch(patch): | |
67 | prefix = empty_prefix | |
68 | if options.description: | |
69 | print prefix + patch.ljust(length) + ' | ' + __get_description(patch) | |
70 | else: | |
71 | print prefix + patch | |
72 | ||
fcee87cf CM |
73 | def func(parser, options, args): |
74 | """Show the patch series | |
75 | """ | |
19ac8fe4 CM |
76 | global crt_series |
77 | ||
fcee87cf CM |
78 | if len(args) != 0: |
79 | parser.error('incorrect number of arguments') | |
80 | ||
19ac8fe4 CM |
81 | if options.missing: |
82 | # switch the series, the one specified with --missing should | |
83 | # become the current | |
84 | cmp_series = crt_series | |
85 | crt_series = stack.Series(options.missing) | |
86 | stgit.commands.common.crt_series = crt_series | |
87 | ||
88 | cmp_patches = cmp_series.get_applied() + cmp_series.get_unapplied() | |
89 | else: | |
90 | cmp_patches = [] | |
91 | ||
92 | applied = [p for p in crt_series.get_applied() if p not in cmp_patches] | |
93 | unapplied = [p for p in crt_series.get_unapplied() if p not in cmp_patches] | |
47d6ad47 | 94 | |
948dae34 CL |
95 | if options.count: |
96 | print len(applied) + len(unapplied) | |
97 | return | |
98 | ||
47d6ad47 CL |
99 | if options.short: |
100 | if len(applied) > 5: | |
101 | applied = applied[-6:] | |
102 | if len(unapplied) > 5: | |
103 | unapplied = unapplied[:5] | |
104 | ||
f82e85bc | 105 | patches = applied + unapplied |
43e97a20 CM |
106 | if not patches: |
107 | return | |
108 | ||
109 | if options.graphical: | |
19ac8fe4 CM |
110 | if options.missing: |
111 | raise CmdException, '--graphical not supported with --missing' | |
112 | ||
43e97a20 CM |
113 | if applied: |
114 | gitk_args = ' %s^..%s' % (git_id(applied[0]), git_id(applied[-1])) | |
115 | else: | |
116 | gitk_args = '' | |
f82e85bc | 117 | |
43e97a20 CM |
118 | for p in unapplied: |
119 | patch_id = git_id(p) | |
120 | gitk_args += ' %s^..%s' % (patch_id, patch_id) | |
121 | ||
122 | if os.system('gitk%s' % gitk_args) != 0: | |
123 | raise CmdException, 'gitk execution failed' | |
124 | else: | |
125 | max_len = 0 | |
126 | if len(patches) > 0: | |
127 | max_len = max([len(i) for i in patches]) | |
f82e85bc | 128 | |
43e97a20 CM |
129 | if len(applied) > 0: |
130 | for p in applied [0:-1]: | |
131 | __print_patch(p, '+ ', '0 ', max_len, options) | |
f82e85bc | 132 | |
43e97a20 | 133 | __print_patch(applied[-1], '> ', '0>', max_len, options) |
f82e85bc | 134 | |
43e97a20 CM |
135 | for p in unapplied: |
136 | __print_patch(p, '- ', '0 ', max_len, options) |