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 optparse
import make_option
21 from stgit
.commands
import common
22 from stgit
.commands
.common
import parse_patches
23 from stgit
.out
import out
25 help = 'print the patch series'
26 usage
= """%prog [options] [<patch-range>]
28 Show all the patches in the series or just those in the given
29 range. The applied patches are prefixed with a '+', the unapplied ones
30 with a '-' and the hidden ones with a '!'. The current patch is
31 prefixed with a '>'. Empty patches are prefixed with a '0'."""
33 directory
= common
.DirectoryHasRepositoryLib()
35 options
= [make_option('-b', '--branch',
36 help = 'use BRANCH instead of the default one'),
37 make_option('-a', '--all',
38 help = 'show all patches, including the hidden ones',
39 action
= 'store_true'),
40 make_option('-A', '--applied',
41 help = 'show the applied patches only',
42 action
= 'store_true'),
43 make_option('-U', '--unapplied',
44 help = 'show the unapplied patches only',
45 action
= 'store_true'),
46 make_option('-H', '--hidden',
47 help = 'show the hidden patches only',
48 action
= 'store_true'),
49 make_option('-m', '--missing', metavar
= 'BRANCH',
50 help = 'show patches in BRANCH missing in current'),
51 make_option('-c', '--count',
52 help = 'print the number of patches in the series',
53 action
= 'store_true'),
54 make_option('-d', '--description',
55 help = 'show a short description for each patch',
56 action
= 'store_true'),
57 make_option('--author',
58 help = 'show the author name for each patch',
59 action
= 'store_true'),
60 make_option('-e', '--empty',
61 help = 'check whether patches are empty '
63 action
= 'store_true'),
64 make_option('--showbranch',
65 help = 'append the branch name to the listed patches',
66 action
= 'store_true'),
67 make_option('--noprefix',
68 help = 'do not show the patch status prefix',
69 action
= 'store_true'),
70 make_option('-s', '--short',
71 help = 'list just the patches around the topmost patch',
72 action
= 'store_true')]
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
, empty_prefix
, length
, options
):
90 """Print a patch name, description and various markers.
94 elif options
.empty
and stack
.patches
.get(patch
).is_empty():
97 patch_str
= branch_str
+ patch
99 if options
.description
or options
.author
:
100 patch_str
= patch_str
.ljust(length
)
102 if options
.description
:
103 out
.stdout(prefix
+ patch_str
+ ' # ' + __get_description(stack
, patch
))
105 out
.stdout(prefix
+ patch_str
+ ' # ' + __get_author(stack
, patch
))
107 out
.stdout(prefix
+ patch_str
)
109 def func(parser
, options
, args
):
110 """Show the patch series
112 if options
.all
and options
.short
:
113 raise common
.CmdException
, 'combining --all and --short is meaningless'
115 stack
= directory
.repository
.get_stack(options
.branch
)
118 stack
= directory
.repository
.get_stack(options
.missing
)
120 # current series patches
121 applied
= unapplied
= hidden
= ()
122 if options
.applied
or options
.unapplied
or options
.hidden
:
124 raise common
.CmdException
, \
125 '--all cannot be used with --applied/unapplied/hidden'
127 applied
= stack
.patchorder
.applied
128 if options
.unapplied
:
129 unapplied
= stack
.patchorder
.unapplied
131 hidden
= stack
.patchorder
.hidden
133 applied
= stack
.patchorder
.applied
134 unapplied
= stack
.patchorder
.unapplied
135 hidden
= stack
.patchorder
.hidden
137 applied
= stack
.patchorder
.applied
138 unapplied
= stack
.patchorder
.unapplied
141 cmp_patches
= cmp_stack
.patchorder
.all
145 # the filtering range covers the whole series
147 show_patches
= parse_patches(args
, applied
+ unapplied
+ hidden
,
150 show_patches
= applied
+ unapplied
+ hidden
153 show_patches
= [p
for p
in show_patches
if p
not in cmp_patches
]
156 applied
= [p
for p
in applied
if p
in show_patches
]
157 unapplied
= [p
for p
in unapplied
if p
in show_patches
]
158 hidden
= [p
for p
in hidden
if p
in show_patches
]
161 nr
= int(config
.get('stgit.shortnr'))
162 if len(applied
) > nr
:
163 applied
= applied
[-(nr
+1):]
166 unapplied
= unapplied
[:nr
]
168 hidden
= hidden
[:nr
-n
]
170 patches
= applied
+ unapplied
+ hidden
173 out
.stdout(len(patches
))
179 if options
.showbranch
:
180 branch_str
= stack
.name
+ ':'
186 max_len
= max([len(i
+ branch_str
) for i
in patches
])
189 for p
in applied
[:-1]:
190 __print_patch(stack
, p
, branch_str
, '+ ', '0 ', max_len
, options
)
191 __print_patch(stack
, applied
[-1], branch_str
, '> ', '0>', max_len
,
195 __print_patch(stack
, p
, branch_str
, '- ', '0 ', max_len
, options
)
198 __print_patch(stack
, p
, branch_str
, '! ', '! ', max_len
, options
)