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 '+' and the unapplied
33 ones with a '-'. The current patch is prefixed with a '>'. Empty
34 patches are prefixed with a '0'. The '*' postfix is appended to hidden
37 options
= [make_option('-b', '--branch',
38 help = 'use BRANCH instead of the default one'),
39 make_option('-a', '--all',
40 help = 'show all patches, including the hidden ones',
41 action
= 'store_true'),
42 make_option('-i', '--invisible',
43 help = 'show the hidden patches only',
44 action
= 'store_true'),
45 make_option('-m', '--missing', metavar
= 'BRANCH',
46 help = 'show patches in BRANCH missing in current'),
47 make_option('-c', '--count',
48 help = 'print the number of patches in the series',
49 action
= 'store_true'),
50 make_option('-d', '--description',
51 help = 'show a short description for each patch',
52 action
= 'store_true'),
53 make_option('-e', '--empty',
54 help = 'check whether patches are empty '
56 action
= 'store_true'),
57 make_option('--showbranch',
58 help = 'append the branch name to the listed patches',
59 action
= 'store_true'),
60 make_option('--noprefix',
61 help = 'do not show the patch status prefix',
62 action
= 'store_true'),
63 make_option('-s', '--short',
64 help = 'list just the patches around the topmost patch',
65 action
= 'store_true'),
66 make_option('-g', '--graphical',
67 help = 'run gitk instead of printing',
68 action
= 'store_true')]
71 def __get_description(patch
):
72 """Extract and return a patch's short description
74 p
= crt_series
.get_patch(patch
)
75 descr
= (p
.get_description() or '').strip()
76 descr_lines
= descr
.split('\n')
77 return descr_lines
[0].rstrip()
79 def __print_patch(patch
, hidden
, branch_str
, prefix
, empty_prefix
, length
,
81 """Print a patch name, description and various markers.
85 elif options
.empty
and crt_series
.empty_patch(patch
):
88 patch_str
= patch
+ branch_str
89 if not options
.noprefix
and patch
in hidden
:
92 if options
.description
:
93 print prefix
+ patch_str
.ljust(length
) + ' | ' \
94 + __get_description(patch
)
96 print prefix
+ patch_str
98 def func(parser
, options
, args
):
99 """Show the patch series
104 # switch the series, the one specified with --missing should
106 cmp_series
= crt_series
107 crt_series
= stack
.Series(options
.missing
)
108 stgit
.commands
.common
.crt_series
= crt_series
110 cmp_patches
= cmp_series
.get_applied() + cmp_series
.get_unapplied()
114 applied
= crt_series
.get_applied()
115 unapplied
= crt_series
.get_unapplied()
117 # the filtering range covers the whole series
119 show_patches
= parse_patches(args
, applied
+ unapplied
, len(applied
))
121 show_patches
= applied
+ unapplied
124 show_patches
= [p
for p
in show_patches
if p
not in cmp_patches
]
126 # hidden patches filtering
127 hidden
= crt_series
.get_hidden()
128 if options
.invisible
:
129 show_patches
= [p
for p
in show_patches
if p
in hidden
]
130 elif not options
.all
:
131 show_patches
= [p
for p
in show_patches
if p
not in hidden
]
134 applied
= [p
for p
in applied
if p
in show_patches
]
135 unapplied
= [p
for p
in unapplied
if p
in show_patches
]
139 applied
= applied
[-6:]
140 if len(unapplied
) > 5:
141 unapplied
= unapplied
[:5]
143 patches
= applied
+ unapplied
152 if options
.showbranch
:
153 branch_str
= '@' + crt_series
.get_branch()
157 if options
.graphical
:
159 raise CmdException
, '--graphical not supported with --missing'
162 gitk_args
= ' %s^..%s' %
(git_id(applied
[0]), git_id(applied
[-1]))
168 gitk_args
+= ' %s^..%s' %
(patch_id
, patch_id
)
170 if os
.system('gitk%s' % gitk_args
) != 0:
171 raise CmdException
, 'gitk execution failed'
175 max_len
= max([len(i
+ branch_str
) for i
in patches
])
179 current
= crt_series
.get_current()
180 if applied
[-1] == current
:
186 __print_patch(p
, hidden
, branch_str
, '+ ', '0 ', max_len
,
190 __print_patch(current
, hidden
, branch_str
, '> ', '0>', max_len
,
194 __print_patch(p
, hidden
, branch_str
, '- ', '0 ', max_len
, options
)