3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
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.
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.
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
20 from optparse import OptionParser, make_option
22 import stgit.commands.common
23 from stgit.commands.common import *
24 from stgit.utils import *
25 from stgit.out import *
26 from stgit import stack, git
29 help = 'print the patch series'
30 usage = """%prog [options] [<patch-range>]
32 Show all the patches in the series or just those in the given
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'."""
37 directory = DirectoryHasRepository()
38 options = [make_option('-b', '--branch',
39 help = 'use BRANCH instead of the default one'),
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'),
46 make_option('-m', '--missing', metavar = 'BRANCH',
47 help = 'show patches in BRANCH missing in current'),
48 make_option('-c', '--count',
49 help = 'print the number of patches in the series',
50 action = 'store_true'),
51 make_option('-d', '--description',
52 help = 'show a short description for each patch',
53 action = 'store_true'),
54 make_option('--author',
55 help = 'show the author name for each patch',
56 action = 'store_true'),
57 make_option('-e', '--empty',
58 help = 'check whether patches are empty '
60 action = 'store_true'),
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'),
67 make_option('-s', '--short',
68 help = 'list just the patches around the topmost patch',
69 action = 'store_true'),
70 make_option('-g', '--graphical',
71 help = 'run gitk instead of printing',
72 action = 'store_true')]
75 def __get_description(patch):
76 """Extract and return a patch's short description
78 p = crt_series.get_patch(patch)
79 descr = (p.get_description() or '').strip()
80 descr_lines = descr.split('\n')
81 return descr_lines[0].rstrip()
83 def __get_author(patch):
84 """Extract and return a patch's short description
86 p = crt_series.get_patch(patch)
87 return p.get_authname();
89 def __print_patch(patch, branch_str, prefix, empty_prefix, length, options):
90 """Print a patch name, description and various markers.
94 elif options.empty and crt_series.empty_patch(patch):
97 patch_str = patch + branch_str
99 if options.description or options.author:
100 patch_str = patch_str.ljust(length)
102 if options.description:
103 out.stdout(prefix + patch_str + ' | ' + __get_description(patch))
105 out.stdout(prefix + patch_str + ' | ' + __get_author(patch))
107 out.stdout(prefix + patch_str)
109 def func(parser, options, args):
110 """Show the patch series
114 if options.all and options.short:
115 raise CmdException, 'combining --all and --short is meaningless'
117 # current series patches
118 if options.invisible:
119 applied = unapplied = []
120 hidden = crt_series.get_hidden()
122 applied = crt_series.get_applied()
123 unapplied = crt_series.get_unapplied()
124 hidden = crt_series.get_hidden()
126 applied = crt_series.get_applied()
127 unapplied = crt_series.get_unapplied()
131 # switch the series, the one specified with --missing should
133 cmp_series = crt_series
134 crt_series = stack.Series(options.missing)
135 stgit.commands.common.crt_series = crt_series
137 cmp_patches = applied + unapplied + hidden
139 # new current series patches
140 if options.invisible:
141 applied = unapplied = []
142 hidden = crt_series.get_hidden()
144 applied = crt_series.get_applied()
145 unapplied = crt_series.get_unapplied()
146 hidden = crt_series.get_hidden()
148 applied = crt_series.get_applied()
149 unapplied = crt_series.get_unapplied()
154 # the filtering range covers the whole series
156 show_patches = parse_patches(args, applied + unapplied + hidden,
159 show_patches = applied + unapplied + hidden
162 show_patches = [p for p in show_patches if p not in cmp_patches]
165 applied = [p for p in applied if p in show_patches]
166 unapplied = [p for p in unapplied if p in show_patches]
167 hidden = [p for p in hidden if p in show_patches]
170 nr = int(config.get('stgit.shortnr'))
171 if len(applied) > nr:
172 applied = applied[-(nr+1):]
175 unapplied = unapplied[:nr]
177 hidden = hidden[:nr-n]
179 patches = applied + unapplied + hidden
182 out.stdout(len(patches))
188 if options.showbranch:
189 branch_str = '@' + crt_series.get_name()
193 if options.graphical:
195 raise CmdException, '--graphical not supported with --missing'
198 gitk_args = ' %s^..%s' % (git_id(applied[0]), git_id(applied[-1]))
204 gitk_args += ' %s^..%s' % (patch_id, patch_id)
206 if os.system('gitk%s' % gitk_args) != 0:
207 raise CmdException, 'gitk execution failed'
211 max_len = max([len(i + branch_str) for i in patches])
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,
220 __print_patch(p, branch_str, '- ', '0 ', max_len, options)
223 __print_patch(p, branch_str, '! ', '! ', max_len, options)