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
19 from optparse import make_option
21 from stgit.commands import common
22 from stgit.commands.common import parse_patches
23 from stgit.out import out
25 help = 'print the patch series'
26 usage = """%prog [options] [<patch-range>]
28 Show all the patches in the series or just those in the given
29 range. The applied patches are prefixed with a '+', the unapplied ones
30 with a '-' and the hidden ones with a '!'. The current patch is
31 prefixed with a '>'. Empty patches are prefixed with a '0'."""
33 directory = common.DirectoryHasRepositoryLib()
35 options = [make_option('-b', '--branch',
36 help = 'use BRANCH instead of the default one'),
37 make_option('-a', '--all',
38 help = 'show all patches, including the hidden ones',
39 action = 'store_true'),
40 make_option('--hidden',
41 help = 'show the hidden patches only',
42 action = 'store_true'),
43 make_option('-m', '--missing', metavar = 'BRANCH',
44 help = 'show patches in BRANCH missing in current'),
45 make_option('-c', '--count',
46 help = 'print the number of patches in the series',
47 action = 'store_true'),
48 make_option('-d', '--description',
49 help = 'show a short description for each patch',
50 action = 'store_true'),
51 make_option('--author',
52 help = 'show the author name for each patch',
53 action = 'store_true'),
54 make_option('-e', '--empty',
55 help = 'check whether patches are empty '
57 action = 'store_true'),
58 make_option('--showbranch',
59 help = 'append the branch name to the listed patches',
60 action = 'store_true'),
61 make_option('--noprefix',
62 help = 'do not show the patch status prefix',
63 action = 'store_true'),
64 make_option('-s', '--short',
65 help = 'list just the patches around the topmost patch',
66 action = 'store_true')]
69 def __get_description(stack, patch):
70 """Extract and return a patch's short description
72 cd = stack.patches.get(patch).commit.data
73 descr = cd.message.strip()
74 descr_lines = descr.split('\n')
75 return descr_lines[0].rstrip()
77 def __get_author(stack, patch):
78 """Extract and return a patch's short description
80 cd = stack.patches.get(patch).commit.data
83 def __print_patch(stack, patch, branch_str, prefix, empty_prefix, length, options):
84 """Print a patch name, description and various markers.
88 elif options.empty and stack.patches.get(patch).is_empty():
91 patch_str = patch + branch_str
93 if options.description or options.author:
94 patch_str = patch_str.ljust(length)
96 if options.description:
97 out.stdout(prefix + patch_str + ' # ' + __get_description(stack, patch))
99 out.stdout(prefix + patch_str + ' # ' + __get_author(stack, patch))
101 out.stdout(prefix + patch_str)
103 def func(parser, options, args):
104 """Show the patch series
106 if options.all and options.short:
107 raise common.CmdException, 'combining --all and --short is meaningless'
109 stack = directory.repository.get_stack(options.branch)
112 stack = directory.repository.get_stack(options.missing)
114 # current series patches
116 applied = stack.patchorder.applied
117 unapplied = stack.patchorder.unapplied
118 hidden = stack.patchorder.hidden
120 applied = unapplied = ()
121 hidden = stack.patchorder.hidden
123 applied = stack.patchorder.applied
124 unapplied = stack.patchorder.unapplied
128 cmp_patches = cmp_stack.patchorder.all
132 # the filtering range covers the whole series
134 show_patches = parse_patches(args, applied + unapplied + hidden,
137 show_patches = applied + unapplied + hidden
140 show_patches = [p for p in show_patches if p not in cmp_patches]
143 applied = [p for p in applied if p in show_patches]
144 unapplied = [p for p in unapplied if p in show_patches]
145 hidden = [p for p in hidden if p in show_patches]
148 nr = int(config.get('stgit.shortnr'))
149 if len(applied) > nr:
150 applied = applied[-(nr+1):]
153 unapplied = unapplied[:nr]
155 hidden = hidden[:nr-n]
157 patches = applied + unapplied + hidden
160 out.stdout(len(patches))
166 if options.showbranch:
167 branch_str = '@' + stack.name
173 max_len = max([len(i + branch_str) for i in patches])
176 for p in applied[:-1]:
177 __print_patch(stack, p, branch_str, '+ ', '0 ', max_len, options)
178 __print_patch(stack, applied[-1], branch_str, '> ', '0>', max_len,
182 __print_patch(stack, p, branch_str, '- ', '0 ', max_len, options)
185 __print_patch(stack, p, branch_str, '! ', '! ', max_len, options)