Commit | Line | Data |
---|---|---|
fcee87cf CM |
1 | |
2 | __copyright__ = """ | |
3 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> | |
4 | ||
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. | |
8 | ||
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. | |
13 | ||
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 | |
17 | """ | |
18 | ||
575bbdae | 19 | from stgit.argparse import opt |
448e5d9d CM |
20 | from stgit.commands import common |
21 | from stgit.commands.common import parse_patches | |
22 | from stgit.out import out | |
607326fd | 23 | from stgit.config import config |
6c8a90e1 | 24 | from stgit import argparse |
fcee87cf | 25 | |
575bbdae | 26 | help = 'Print the patch series' |
33ff9cdd | 27 | kind = 'stack' |
575bbdae KH |
28 | usage = ['[options] [<patch-range>]'] |
29 | description = """ | |
0aebdb85 | 30 | Show all the patches in the series or just those in the given |
ca8b854c CM |
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'.""" | |
fcee87cf | 34 | |
6c8a90e1 KH |
35 | args = [argparse.patch_range(argparse.applied_patches, |
36 | argparse.unapplied_patches, | |
37 | argparse.hidden_patches)] | |
575bbdae | 38 | options = [ |
6c8a90e1 | 39 | opt('-b', '--branch', args = [argparse.stg_branches], |
575bbdae KH |
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'), | |
6c8a90e1 | 49 | opt('-m', '--missing', metavar = 'BRANCH', args = [argparse.stg_branches], |
575bbdae KH |
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')] | |
fcee87cf | 65 | |
575bbdae | 66 | directory = common.DirectoryHasRepositoryLib() |
fcee87cf | 67 | |
448e5d9d | 68 | def __get_description(stack, patch): |
f82e85bc CL |
69 | """Extract and return a patch's short description |
70 | """ | |
448e5d9d CM |
71 | cd = stack.patches.get(patch).commit.data |
72 | descr = cd.message.strip() | |
f82e85bc CL |
73 | descr_lines = descr.split('\n') |
74 | return descr_lines[0].rstrip() | |
75 | ||
448e5d9d | 76 | def __get_author(stack, patch): |
54fac8e6 CM |
77 | """Extract and return a patch's short description |
78 | """ | |
448e5d9d CM |
79 | cd = stack.patches.get(patch).commit.data |
80 | return cd.author.name | |
54fac8e6 | 81 | |
448e5d9d | 82 | def __print_patch(stack, patch, branch_str, prefix, empty_prefix, length, options): |
841c7b2a CM |
83 | """Print a patch name, description and various markers. |
84 | """ | |
f483998b CM |
85 | if options.noprefix: |
86 | prefix = '' | |
448e5d9d | 87 | elif options.empty and stack.patches.get(patch).is_empty(): |
f82e85bc | 88 | prefix = empty_prefix |
f483998b | 89 | |
e4560d7e | 90 | patch_str = branch_str + patch |
f483998b | 91 | |
54fac8e6 CM |
92 | if options.description or options.author: |
93 | patch_str = patch_str.ljust(length) | |
94 | ||
f82e85bc | 95 | if options.description: |
448e5d9d | 96 | out.stdout(prefix + patch_str + ' # ' + __get_description(stack, patch)) |
54fac8e6 | 97 | elif options.author: |
448e5d9d | 98 | out.stdout(prefix + patch_str + ' # ' + __get_author(stack, patch)) |
f82e85bc | 99 | else: |
27ac2b7e | 100 | out.stdout(prefix + patch_str) |
f82e85bc | 101 | |
fcee87cf CM |
102 | def func(parser, options, args): |
103 | """Show the patch series | |
104 | """ | |
1f396835 | 105 | if options.all and options.short: |
448e5d9d CM |
106 | raise common.CmdException, 'combining --all and --short is meaningless' |
107 | ||
13b26f1a | 108 | stack = directory.repository.get_stack(options.branch) |
448e5d9d CM |
109 | if options.missing: |
110 | cmp_stack = stack | |
111 | stack = directory.repository.get_stack(options.missing) | |
112 | ||
ca8b854c | 113 | # current series patches |
f9d9a062 CM |
114 | applied = unapplied = hidden = () |
115 | if options.applied or options.unapplied or options.hidden: | |
116 | if options.all: | |
117 | raise common.CmdException, \ | |
118 | '--all cannot be used with --applied/unapplied/hidden' | |
119 | if options.applied: | |
120 | applied = stack.patchorder.applied | |
121 | if options.unapplied: | |
122 | unapplied = stack.patchorder.unapplied | |
123 | if options.hidden: | |
124 | hidden = stack.patchorder.hidden | |
125 | elif options.all: | |
448e5d9d CM |
126 | applied = stack.patchorder.applied |
127 | unapplied = stack.patchorder.unapplied | |
128 | hidden = stack.patchorder.hidden | |
ca8b854c | 129 | else: |
448e5d9d CM |
130 | applied = stack.patchorder.applied |
131 | unapplied = stack.patchorder.unapplied | |
ca8b854c | 132 | |
19ac8fe4 | 133 | if options.missing: |
448e5d9d | 134 | cmp_patches = cmp_stack.patchorder.all |
19ac8fe4 | 135 | else: |
448e5d9d | 136 | cmp_patches = () |
19ac8fe4 | 137 | |
0aebdb85 CM |
138 | # the filtering range covers the whole series |
139 | if args: | |
ca8b854c CM |
140 | show_patches = parse_patches(args, applied + unapplied + hidden, |
141 | len(applied)) | |
0aebdb85 | 142 | else: |
ca8b854c | 143 | show_patches = applied + unapplied + hidden |
0aebdb85 | 144 | |
841c7b2a CM |
145 | # missing filtering |
146 | show_patches = [p for p in show_patches if p not in cmp_patches] | |
147 | ||
0aebdb85 | 148 | # filter the patches |
841c7b2a CM |
149 | applied = [p for p in applied if p in show_patches] |
150 | unapplied = [p for p in unapplied if p in show_patches] | |
ca8b854c | 151 | hidden = [p for p in hidden if p in show_patches] |
948dae34 | 152 | |
47d6ad47 | 153 | if options.short: |
c73e63b7 | 154 | nr = int(config.get('stgit.shortnr')) |
c6f366f6 CM |
155 | if len(applied) > nr: |
156 | applied = applied[-(nr+1):] | |
ca8b854c CM |
157 | n = len(unapplied) |
158 | if n > nr: | |
c6f366f6 | 159 | unapplied = unapplied[:nr] |
ca8b854c CM |
160 | elif n < nr: |
161 | hidden = hidden[:nr-n] | |
47d6ad47 | 162 | |
ca8b854c | 163 | patches = applied + unapplied + hidden |
0aebdb85 CM |
164 | |
165 | if options.count: | |
27ac2b7e | 166 | out.stdout(len(patches)) |
0aebdb85 CM |
167 | return |
168 | ||
43e97a20 CM |
169 | if not patches: |
170 | return | |
171 | ||
f483998b | 172 | if options.showbranch: |
e4560d7e | 173 | branch_str = stack.name + ':' |
f483998b CM |
174 | else: |
175 | branch_str = '' | |
176 | ||
448e5d9d CM |
177 | max_len = 0 |
178 | if len(patches) > 0: | |
179 | max_len = max([len(i + branch_str) for i in patches]) | |
841c7b2a | 180 | |
448e5d9d CM |
181 | if applied: |
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, | |
185 | options) | |
f82e85bc | 186 | |
448e5d9d CM |
187 | for p in unapplied: |
188 | __print_patch(stack, p, branch_str, '- ', '0 ', max_len, options) | |
ca8b854c | 189 | |
448e5d9d CM |
190 | for p in hidden: |
191 | __print_patch(stack, p, branch_str, '! ', '! ', max_len, options) |