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 range,
31 ordered from top to bottom.
33 The applied patches are prefixed with a +++ (except the current patch,
34 which is prefixed with a +>+), the unapplied patches with a +-+, and
35 the hidden patches with a +!+.
37 Empty patches are prefixed with a '0'."""
39 args
= [argparse
.patch_range(argparse
.applied_patches
,
40 argparse
.unapplied_patches
,
41 argparse
.hidden_patches
)]
43 opt('-b', '--branch', args
= [argparse
.stg_branches
],
44 short
= 'Use BRANCH instead of the default branch'),
45 opt('-a', '--all', action
= 'store_true',
46 short
= 'Show all patches, including the hidden ones'),
47 opt('-A', '--applied', action
= 'store_true',
48 short
= 'Show the applied patches only'),
49 opt('-U', '--unapplied', action
= 'store_true',
50 short
= 'Show the unapplied patches only'),
51 opt('-H', '--hidden', action
= 'store_true',
52 short
= 'Show the hidden patches only'),
53 opt('-m', '--missing', metavar
= 'BRANCH', args
= [argparse
.stg_branches
],
54 short
= 'Show patches in BRANCH missing in current'),
55 opt('-c', '--count', action
= 'store_true',
56 short
= 'Print the number of patches in the series'),
57 opt('-d', '--description', action
= 'store_true',
58 short
= 'Show a short description for each patch'),
59 opt('--author', action
= 'store_true',
60 short
= 'Show the author name for each patch'),
61 opt('-e', '--empty', action
= 'store_true',
62 short
= 'Check whether patches are empty', long = """
63 Before the +++, +>+, +-+, and +!+ prefixes, print a column
64 that contains either +0+ (for empty patches) or a space (for
65 non-empty patches)."""),
66 opt('--showbranch', action
= 'store_true',
67 short
= 'Append the branch name to the listed patches'),
68 opt('--noprefix', action
= 'store_true',
69 short
= 'Do not show the patch status prefix'),
70 opt('-s', '--short', action
= 'store_true',
71 short
= 'List just the patches around the topmost patch')]
73 directory
= common
.DirectoryHasRepositoryLib()
75 def __get_description(stack
, patch
):
76 """Extract and return a patch's short description
78 cd
= stack
.patches
.get(patch
).commit
.data
79 descr
= cd
.message
.strip()
80 descr_lines
= descr
.split('\n')
81 return descr_lines
[0].rstrip()
83 def __get_author(stack
, patch
):
84 """Extract and return a patch's short description
86 cd
= stack
.patches
.get(patch
).commit
.data
89 def __print_patch(stack
, patch
, branch_str
, prefix
, length
, options
):
90 """Print a patch name, description and various markers.
95 if stack
.patches
.get(patch
).is_empty():
100 patch_str
= branch_str
+ patch
102 if options
.description
or options
.author
:
103 patch_str
= patch_str
.ljust(length
)
105 if options
.description
:
106 out
.stdout(prefix
+ patch_str
+ ' # ' + __get_description(stack
, patch
))
108 out
.stdout(prefix
+ patch_str
+ ' # ' + __get_author(stack
, patch
))
110 out
.stdout(prefix
+ patch_str
)
112 def func(parser
, options
, args
):
113 """Show the patch series
115 if options
.all
and options
.short
:
116 raise common
.CmdException
, 'combining --all and --short is meaningless'
118 stack
= directory
.repository
.get_stack(options
.branch
)
121 stack
= directory
.repository
.get_stack(options
.missing
)
123 # current series patches
124 applied
= unapplied
= hidden
= ()
125 if options
.applied
or options
.unapplied
or options
.hidden
:
127 raise common
.CmdException
, \
128 '--all cannot be used with --applied/unapplied/hidden'
130 applied
= stack
.patchorder
.applied
131 if options
.unapplied
:
132 unapplied
= stack
.patchorder
.unapplied
134 hidden
= stack
.patchorder
.hidden
136 applied
= stack
.patchorder
.applied
137 unapplied
= stack
.patchorder
.unapplied
138 hidden
= stack
.patchorder
.hidden
140 applied
= stack
.patchorder
.applied
141 unapplied
= stack
.patchorder
.unapplied
144 cmp_patches
= cmp_stack
.patchorder
.all
148 # the filtering range covers the whole series
150 show_patches
= parse_patches(args
, applied
+ unapplied
+ hidden
,
153 show_patches
= applied
+ unapplied
+ hidden
156 show_patches
= [p
for p
in show_patches
if p
not in cmp_patches
]
159 applied
= [p
for p
in applied
if p
in show_patches
]
160 unapplied
= [p
for p
in unapplied
if p
in show_patches
]
161 hidden
= [p
for p
in hidden
if p
in show_patches
]
164 nr
= int(config
.get('stgit.shortnr'))
165 if len(applied
) > nr
:
166 applied
= applied
[-(nr
+1):]
169 unapplied
= unapplied
[:nr
]
171 hidden
= hidden
[:nr
-n
]
173 patches
= applied
+ unapplied
+ hidden
176 out
.stdout(len(patches
))
182 if options
.showbranch
:
183 branch_str
= stack
.name
+ ':'
189 max_len
= max([len(i
+ branch_str
) for i
in patches
])
192 for p
in applied
[:-1]:
193 __print_patch(stack
, p
, branch_str
, '+ ', max_len
, options
)
194 __print_patch(stack
, applied
[-1], branch_str
, '> ', max_len
,
198 __print_patch(stack
, p
, branch_str
, '- ', max_len
, options
)
201 __print_patch(stack
, p
, branch_str
, '! ', max_len
, options
)