Stack "state" naming
[stgit.git] / stgit / commands / log.py
blob1aedcc40bd747248711d2e14e08947373f6678a8
1 from stgit.argparse import opt, patch_range
2 from stgit.commands.common import DirectoryHasRepository, parse_patches
3 from stgit.lib import log
4 from stgit.run import Run
6 __copyright__ = """
7 Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
8 Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License version 2 as
12 published by the Free Software Foundation.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, see http://www.gnu.org/licenses/.
21 """
23 help = 'Display or optionally clear the patch changelog'
24 kind = 'stack'
25 usage = ['[options] [--] [<patches>]']
26 description = """
27 List the history of the patch stack: the stack log. If one or more
28 patch names are given, limit the list to the log entries that touch
29 the named patches.
31 "stg undo" and "stg redo" let you step back and forth in the patch
32 stack. "stg reset" lets you go directly to any state.
34 Given the --clear option, the log history will be deleted.
35 This may be useful if the tree view has become too cluttered
36 to be useful."""
38 args = [patch_range('applied_patches', 'unapplied_patches', 'hidden_patches')]
39 options = [
40 opt(
41 '-b',
42 '--branch',
43 args=['stg_branches'],
44 short='Use BRANCH instead of the default one',
46 opt(
47 '-d',
48 '--diff',
49 action='store_true',
50 short='Show the refresh diffs',
52 opt(
53 '-n',
54 '--number',
55 type='int',
56 short='Limit the output to NUMBER commits',
58 opt(
59 '-f',
60 '--full',
61 action='store_true',
62 short='Show the full commit ids',
64 opt(
65 '-g',
66 '--graphical',
67 action='store_true',
68 short='Run gitk instead of printing',
70 opt(
71 '--clear',
72 action='store_true',
73 short='Clear the log history',
77 directory = DirectoryHasRepository()
80 def show_log(state, pathlim, num, full, show_diff):
81 cmd = ['git', 'log']
82 if num is not None and num > 0:
83 cmd.append('-%d' % num)
84 if show_diff:
85 cmd.append('-p')
86 elif not full:
87 cmd.append('--pretty=tformat:%h %aD %s')
88 cmd.extend([state.sha1, '--'])
89 cmd.extend(pathlim)
90 Run(*cmd).run()
93 def func(parser, options, args):
94 if options.clear:
95 if options.diff or options.number or options.full or options.graphical:
96 parser.error('cannot combine --clear with other options')
97 elif args:
98 parser.error('cannot combine --clear with patch arguments')
100 if options.graphical:
101 for o in ['diff', 'number', 'full']:
102 if getattr(options, o):
103 parser.error('cannot combine --graphical and --%s' % o)
105 stack = directory.repository.get_stack(options.branch)
107 if options.clear:
108 stack.clear_log()
109 return
111 patches = parse_patches(args, list(stack.patchorder.all))
112 state = log.get_stack_state(stack.repository, stack.state_ref)
113 pathlim = ['patches/%s' % pn for pn in patches]
115 if options.graphical:
116 cmd = ['gitk', state.simplified.sha1, '--'] + pathlim
117 # Discard the exit codes generated by SIGINT, SIGKILL, and SIGTERM.
118 Run(*cmd).returns([0, -2, -9, -15]).run()
119 else:
120 show_log(state.simplified, pathlim, options.number, options.full, options.diff)