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 stgit
.argparse
import opt
20 from stgit
.commands
import common
21 from stgit
.commands
.common
import parse_patches
22 from stgit
.out
import out
23 from stgit
.config
import config
24 from stgit
import argparse
26 help = 'Print the patch series'
28 usage
= ['[options] [<patch-range>]']
30 Show all the patches in the series or just those in the given
31 range. The applied patches are prefixed with a '+', the unapplied ones
32 with a '-' and the hidden ones with a '!'. The current patch is
33 prefixed with a '>'. Empty patches are prefixed with a '0'."""
35 args
= [argparse
.patch_range(argparse
.applied_patches
,
36 argparse
.unapplied_patches
,
37 argparse
.hidden_patches
)]
39 opt('-b', '--branch', args
= [argparse
.stg_branches
],
40 short
= 'Use BRANCH instead of the default branch'),
41 opt('-a', '--all', action
= 'store_true',
42 short
= 'Show all patches, including the hidden ones'),
43 opt('-A', '--applied', action
= 'store_true',
44 short
= 'Show the applied patches only'),
45 opt('-U', '--unapplied', action
= 'store_true',
46 short
= 'Show the unapplied patches only'),
47 opt('-H', '--hidden', action
= 'store_true',
48 short
= 'Show the hidden patches only'),
49 opt('-m', '--missing', metavar
= 'BRANCH', args
= [argparse
.stg_branches
],
50 short
= 'Show patches in BRANCH missing in current'),
51 opt('-c', '--count', action
= 'store_true',
52 short
= 'Print the number of patches in the series'),
53 opt('-d', '--description', action
= 'store_true',
54 short
= 'Show a short description for each patch'),
55 opt('--author', action
= 'store_true',
56 short
= 'Show the author name for each patch'),
57 opt('-e', '--empty', action
= 'store_true',
58 short
= 'Check whether patches are empty'),
59 opt('--showbranch', action
= 'store_true',
60 short
= 'Append the branch name to the listed patches'),
61 opt('--noprefix', action
= 'store_true',
62 short
= 'Do not show the patch status prefix'),
63 opt('-s', '--short', action
= 'store_true',
64 short
= 'List just the patches around the topmost patch')]
66 directory
= common
.DirectoryHasRepositoryLib()
68 def __get_description(stack
, patch
):
69 """Extract and return a patch's short description
71 cd
= stack
.patches
.get(patch
).commit
.data
72 descr
= cd
.message
.strip()
73 descr_lines
= descr
.split('\n')
74 return descr_lines
[0].rstrip()
76 def __get_author(stack
, patch
):
77 """Extract and return a patch's short description
79 cd
= stack
.patches
.get(patch
).commit
.data
82 def __print_patch(stack
, patch
, branch_str
, prefix
, empty_prefix
, length
, options
):
83 """Print a patch name, description and various markers.
87 elif options
.empty
and stack
.patches
.get(patch
).is_empty():
90 patch_str
= branch_str
+ patch
92 if options
.description
or options
.author
:
93 patch_str
= patch_str
.ljust(length
)
95 if options
.description
:
96 out
.stdout(prefix
+ patch_str
+ ' # ' + __get_description(stack
, patch
))
98 out
.stdout(prefix
+ patch_str
+ ' # ' + __get_author(stack
, patch
))
100 out
.stdout(prefix
+ patch_str
)
102 def func(parser
, options
, args
):
103 """Show the patch series
105 if options
.all
and options
.short
:
106 raise common
.CmdException
, 'combining --all and --short is meaningless'
108 stack
= directory
.repository
.get_stack(options
.branch
)
111 stack
= directory
.repository
.get_stack(options
.missing
)
113 # current series patches
114 applied
= unapplied
= hidden
= ()
115 if options
.applied
or options
.unapplied
or options
.hidden
:
117 raise common
.CmdException
, \
118 '--all cannot be used with --applied/unapplied/hidden'
120 applied
= stack
.patchorder
.applied
121 if options
.unapplied
:
122 unapplied
= stack
.patchorder
.unapplied
124 hidden
= stack
.patchorder
.hidden
126 applied
= stack
.patchorder
.applied
127 unapplied
= stack
.patchorder
.unapplied
128 hidden
= stack
.patchorder
.hidden
130 applied
= stack
.patchorder
.applied
131 unapplied
= stack
.patchorder
.unapplied
134 cmp_patches
= cmp_stack
.patchorder
.all
138 # the filtering range covers the whole series
140 show_patches
= parse_patches(args
, applied
+ unapplied
+ hidden
,
143 show_patches
= applied
+ unapplied
+ hidden
146 show_patches
= [p
for p
in show_patches
if p
not in cmp_patches
]
149 applied
= [p
for p
in applied
if p
in show_patches
]
150 unapplied
= [p
for p
in unapplied
if p
in show_patches
]
151 hidden
= [p
for p
in hidden
if p
in show_patches
]
154 nr
= int(config
.get('stgit.shortnr'))
155 if len(applied
) > nr
:
156 applied
= applied
[-(nr
+1):]
159 unapplied
= unapplied
[:nr
]
161 hidden
= hidden
[:nr
-n
]
163 patches
= applied
+ unapplied
+ hidden
166 out
.stdout(len(patches
))
172 if options
.showbranch
:
173 branch_str
= stack
.name
+ ':'
179 max_len
= max([len(i
+ branch_str
) for i
in patches
])
182 for p
in applied
[:-1]:
183 __print_patch(stack
, p
, branch_str
, '+ ', '0 ', max_len
, options
)
184 __print_patch(stack
, applied
[-1], branch_str
, '> ', '0>', max_len
,
188 __print_patch(stack
, p
, branch_str
, '- ', '0 ', max_len
, options
)
191 __print_patch(stack
, p
, branch_str
, '! ', '! ', max_len
, options
)