1 from stgit
.argparse
import opt
, patch_range
2 from stgit
.commands
.common
import CmdException
, DirectoryHasRepository
, parse_patches
3 from stgit
.config
import config
4 from stgit
.out
import out
7 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see http://www.gnu.org/licenses/.
22 help = 'Print the patch series'
24 usage
= ['[options] [--] [<patch-range>]']
26 Show all the patches in the series, or just those in the given range,
27 ordered from top to bottom.
29 The applied patches are prefixed with a +++ (except the current patch,
30 which is prefixed with a +>+), the unapplied patches with a +-+, and
31 the hidden patches with a +!+.
33 Empty patches are prefixed with a '0'."""
35 args
= [patch_range('applied_patches', 'unapplied_patches', 'hidden_patches')]
40 args
=['stg_branches'],
41 short
='Use BRANCH instead of the default branch',
47 short
='Show all patches, including the hidden ones',
53 short
='Show the applied patches only',
59 short
='Show the unapplied patches only',
65 short
='Show the hidden patches only',
71 args
=['stg_branches'],
72 short
='Show patches in BRANCH missing in current',
78 short
='Print the number of patches in the series',
84 short
='Show a short description for each patch',
89 short
='Inverse of --description',
95 short
='Show the author name for each patch',
101 short
='Check whether patches are empty',
103 Before the +++, +>+, +-+, and +!+ prefixes, print a column
104 that contains either +0+ (for empty patches) or a space (for
105 non-empty patches).""",
110 short
='Append the branch name to the listed patches',
115 short
='Do not show the patch status prefix',
121 short
='List just the patches around the topmost patch',
125 directory
= DirectoryHasRepository()
128 def __get_description(stack
, patch
):
129 """Extract and return a patch's short description"""
130 cd
= stack
.patches
[patch
].data
131 return cd
.message_str
.strip().split('\n', 1)[0].rstrip()
134 def __get_author(stack
, patch
):
135 """Extract and return a patch's short description"""
136 return stack
.patches
[patch
].data
.author
.name
139 def __render_text(text
, effects
):
144 'black_foreground': 30,
145 'red_foreground': 31,
146 'green_foreground': 32,
147 'yellow_foreground': 33,
148 'blue_foreground': 34,
149 'magenta_foreground': 35,
150 'cyan_foreground': 36,
151 'white_foreground': 37,
152 'black_background': 40,
153 'red_background': 41,
154 'green_background': 42,
155 'yellow_background': 44,
156 'blue_background': 44,
157 'magenta_background': 45,
158 'cyan_background': 46,
159 'white_background': 47,
161 start
= [str(_effects
[e
]) for e
in effects
.split() if e
in _effects
]
162 start
= '\033[' + ';'.join(start
) + 'm'
163 stop
= '\033[' + str(_effects
['none']) + 'm'
164 return ''.join([start
, text
, stop
])
167 def __print_patch(stack
, patch
, branch_str
, prefix
, length
, options
, effects
):
168 """Print a patch name, description and various markers."""
172 if stack
.patches
[patch
].data
.is_nochange():
173 prefix
= '0' + prefix
175 prefix
= ' ' + prefix
177 patch_str
= branch_str
+ patch
179 if options
.description
or options
.author
:
180 patch_str
= patch_str
.ljust(length
)
182 if options
.description
:
183 output
= prefix
+ patch_str
+ ' # ' + __get_description(stack
, patch
)
185 output
= prefix
+ patch_str
+ ' # ' + __get_author(stack
, patch
)
187 output
= prefix
+ patch_str
188 if not effects
or not out
.isatty
:
191 out
.stdout(__render_text(output
, effects
))
194 def func(parser
, options
, args
):
195 """Show the patch series"""
196 if options
.all
and options
.short
:
197 raise CmdException('combining --all and --short is meaningless')
199 stack
= directory
.repository
.get_stack(options
.branch
)
202 stack
= directory
.repository
.get_stack(options
.missing
)
204 if options
.description
is None:
205 options
.description
= config
.getbool('stgit.series.description')
207 # current series patches
208 applied
= unapplied
= hidden
= ()
209 if options
.applied
or options
.unapplied
or options
.hidden
:
211 raise CmdException('--all cannot be used with --applied/unapplied/hidden')
213 applied
= stack
.patchorder
.applied
214 if options
.unapplied
:
215 unapplied
= stack
.patchorder
.unapplied
217 hidden
= stack
.patchorder
.hidden
219 applied
= stack
.patchorder
.applied
220 unapplied
= stack
.patchorder
.unapplied
221 hidden
= stack
.patchorder
.hidden
223 applied
= stack
.patchorder
.applied
224 unapplied
= stack
.patchorder
.unapplied
227 cmp_patches
= cmp_stack
.patchorder
.all
231 # the filtering range covers the whole series
233 show_patches
= parse_patches(args
, applied
+ unapplied
+ hidden
, len(applied
))
235 show_patches
= applied
+ unapplied
+ hidden
238 show_patches
= [p
for p
in show_patches
if p
not in cmp_patches
]
241 applied
= [p
for p
in applied
if p
in show_patches
]
242 unapplied
= [p
for p
in unapplied
if p
in show_patches
]
243 hidden
= [p
for p
in hidden
if p
in show_patches
]
246 nr
= int(config
.get('stgit.shortnr'))
247 if len(applied
) > nr
:
248 applied
= applied
[-(nr
+ 1) :]
251 unapplied
= unapplied
[:nr
]
253 hidden
= hidden
[: nr
- n
]
255 patches
= applied
+ unapplied
+ hidden
258 out
.stdout(len(patches
))
264 if options
.showbranch
:
265 branch_str
= stack
.name
+ ':'
269 max_len
= len(branch_str
) + max(len(p
) for p
in patches
)
272 for p
in applied
[:-1]:
280 config
.get("stgit.color.applied"),
289 config
.get("stgit.color.current"),
300 config
.get("stgit.color.unapplied"),
311 config
.get("stgit.color.hidden"),