788e57bbc151152397dd5f7d0cce5d9651667f2e
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'."""
36 options
= [make_option('-b', '--branch',
37 help = 'use BRANCH instead of the default one'),
38 make_option('-m', '--missing', metavar
= 'BRANCH',
39 help = 'show patches in BRANCH missing in current'),
40 make_option('-c', '--count',
41 help = 'print the number of patches in the series',
42 action
= 'store_true'),
43 make_option('-d', '--description',
44 help = 'show a short description for each patch',
45 action
= 'store_true'),
46 make_option('-e', '--empty',
47 help = 'check whether patches are empty '
49 action
= 'store_true'),
50 make_option('--showbranch',
51 help = 'append the branch name to the listed patches',
52 action
= 'store_true'),
53 make_option('--noprefix',
54 help = 'do not show the patch status prefix',
55 action
= 'store_true'),
56 make_option('-s', '--short',
57 help = 'list just the patches around the topmost patch',
58 action
= 'store_true'),
59 make_option('-g', '--graphical',
60 help = 'run gitk instead of printing',
61 action
= 'store_true')]
64 def __get_description(patch
):
65 """Extract and return a patch's short description
67 p
= crt_series
.get_patch(patch
)
68 descr
= (p
.get_description() or '').strip()
69 descr_lines
= descr
.split('\n')
70 return descr_lines
[0].rstrip()
72 def __print_patch(patch
, branch_str
, prefix
, empty_prefix
, length
, options
):
75 elif options
.empty
and crt_series
.empty_patch(patch
):
78 patch_str
= patch
+ branch_str
80 if options
.description
:
81 print prefix
+ patch_str
.ljust(length
) + ' | ' \
82 + __get_description(patch
)
84 print prefix
+ patch_str
86 def func(parser
, options
, args
):
87 """Show the patch series
92 # switch the series, the one specified with --missing should
94 cmp_series
= crt_series
95 crt_series
= stack
.Series(options
.missing
)
96 stgit
.commands
.common
.crt_series
= crt_series
98 cmp_patches
= cmp_series
.get_applied() + cmp_series
.get_unapplied()
102 applied
= crt_series
.get_applied()
103 unapplied
= crt_series
.get_unapplied()
105 # the filtering range covers the whole series
107 show_patches
= parse_patches(args
, applied
+ unapplied
, len(applied
))
109 show_patches
= applied
+ unapplied
112 applied
= [p
for p
in applied
113 if p
in show_patches
and p
not in cmp_patches
]
114 unapplied
= [p
for p
in unapplied
115 if p
in show_patches
and p
not in cmp_patches
]
119 applied
= applied
[-6:]
120 if len(unapplied
) > 5:
121 unapplied
= unapplied
[:5]
123 patches
= applied
+ unapplied
132 if options
.showbranch
:
133 branch_str
= '@' + crt_series
.get_branch()
137 if options
.graphical
:
139 raise CmdException
, '--graphical not supported with --missing'
142 gitk_args
= ' %s^..%s' %
(git_id(applied
[0]), git_id(applied
[-1]))
148 gitk_args
+= ' %s^..%s' %
(patch_id
, patch_id
)
150 if os
.system('gitk%s' % gitk_args
) != 0:
151 raise CmdException
, 'gitk execution failed'
155 max_len
= max([len(i
+ branch_str
) for i
in patches
])
158 for p
in applied
[0:-1]:
159 __print_patch(p
, branch_str
, '+ ', '0 ', max_len
, options
)
161 __print_patch(applied
[-1], branch_str
, '> ', '0>', max_len
,
165 __print_patch(p
, branch_str
, '- ', '0 ', max_len
, options
)