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
import stack
, git
28 help = 'print the patch series'
29 usage
= """%prog [options] [<patch-range>]
31 Show all the patches in the series or just those in the given
32 range. The applied patches are prefixed with a '+', the unapplied ones
33 with a '-' and the hidden ones with a '!'. The current patch is
34 prefixed with a '>'. Empty patches are prefixed with a '0'."""
36 options
= [make_option('-b', '--branch',
37 help = 'use BRANCH instead of the default one'),
38 make_option('-a', '--all',
39 help = 'show all patches, including the hidden ones',
40 action
= 'store_true'),
41 make_option('-i', '--invisible',
42 help = 'show the hidden patches only',
43 action
= 'store_true'),
44 make_option('-m', '--missing', metavar
= 'BRANCH',
45 help = 'show patches in BRANCH missing in current'),
46 make_option('-c', '--count',
47 help = 'print the number of patches in the series',
48 action
= 'store_true'),
49 make_option('-d', '--description',
50 help = 'show a short description for each patch',
51 action
= 'store_true'),
52 make_option('--author',
53 help = 'show the author name for each patch',
54 action
= 'store_true'),
55 make_option('-e', '--empty',
56 help = 'check whether patches are empty '
58 action
= 'store_true'),
59 make_option('--showbranch',
60 help = 'append the branch name to the listed patches',
61 action
= 'store_true'),
62 make_option('--noprefix',
63 help = 'do not show the patch status prefix',
64 action
= 'store_true'),
65 make_option('-s', '--short',
66 help = 'list just the patches around the topmost patch',
67 action
= 'store_true'),
68 make_option('-g', '--graphical',
69 help = 'run gitk instead of printing',
70 action
= 'store_true')]
73 def __get_description(patch
):
74 """Extract and return a patch's short description
76 p
= crt_series
.get_patch(patch
)
77 descr
= (p
.get_description() or '').strip()
78 descr_lines
= descr
.split('\n')
79 return descr_lines
[0].rstrip()
81 def __get_author(patch
):
82 """Extract and return a patch's short description
84 p
= crt_series
.get_patch(patch
)
85 return p
.get_authname();
87 def __print_patch(patch
, branch_str
, prefix
, empty_prefix
, length
, options
):
88 """Print a patch name, description and various markers.
92 elif options
.empty
and crt_series
.empty_patch(patch
):
95 patch_str
= patch
+ branch_str
97 if options
.description
or options
.author
:
98 patch_str
= patch_str
.ljust(length
)
100 if options
.description
:
101 out
.stdout(prefix
+ patch_str
+ ' | ' + __get_description(patch
))
103 out
.stdout(prefix
+ patch_str
+ ' | ' + __get_author(patch
))
105 out
.stdout(prefix
+ patch_str
)
107 def func(parser
, options
, args
):
108 """Show the patch series
112 # current series patches
113 if options
.invisible
:
114 applied
= unapplied
= []
115 hidden
= crt_series
.get_hidden()
117 applied
= crt_series
.get_applied()
118 unapplied
= crt_series
.get_unapplied()
119 hidden
= crt_series
.get_hidden()
121 applied
= crt_series
.get_applied()
122 unapplied
= crt_series
.get_unapplied()
126 # switch the series, the one specified with --missing should
128 cmp_series
= crt_series
129 crt_series
= stack
.Series(options
.missing
)
130 stgit
.commands
.common
.crt_series
= crt_series
132 cmp_patches
= applied
+ unapplied
+ hidden
134 # new current series patches
135 if options
.invisible
:
136 applied
= unapplied
= []
137 hidden
= crt_series
.get_hidden()
139 applied
= crt_series
.get_applied()
140 unapplied
= crt_series
.get_unapplied()
141 hidden
= crt_series
.get_hidden()
143 applied
= crt_series
.get_applied()
144 unapplied
= crt_series
.get_unapplied()
149 # the filtering range covers the whole series
151 show_patches
= parse_patches(args
, applied
+ unapplied
+ hidden
,
154 show_patches
= applied
+ unapplied
+ hidden
157 show_patches
= [p
for p
in show_patches
if p
not in cmp_patches
]
160 applied
= [p
for p
in applied
if p
in show_patches
]
161 unapplied
= [p
for p
in unapplied
if p
in show_patches
]
162 hidden
= [p
for p
in hidden
if p
in show_patches
]
165 nr
= int(config
.get('stgit.shortnr'))
166 if len(applied
) > nr
:
167 applied
= applied
[-(nr
+1):]
170 unapplied
= unapplied
[:nr
]
172 hidden
= hidden
[:nr
-n
]
174 patches
= applied
+ unapplied
+ hidden
177 out
.stdout(len(patches
))
183 if options
.showbranch
:
184 branch_str
= '@' + crt_series
.get_branch()
188 if options
.graphical
:
190 raise CmdException
, '--graphical not supported with --missing'
193 gitk_args
= ' %s^..%s' %
(git_id(applied
[0]), git_id(applied
[-1]))
199 gitk_args
+= ' %s^..%s' %
(patch_id
, patch_id
)
201 if os
.system('gitk%s' % gitk_args
) != 0:
202 raise CmdException
, 'gitk execution failed'
206 max_len
= max([len(i
+ branch_str
) for i
in patches
])
209 for p
in applied
[:-1]:
210 __print_patch(p
, branch_str
, '+ ', '0 ', max_len
, options
)
211 __print_patch(applied
[-1], branch_str
, '> ', '0>', max_len
,
215 __print_patch(p
, branch_str
, '- ', '0 ', max_len
, options
)
218 __print_patch(p
, branch_str
, '! ', '! ', max_len
, options
)