1 # -*- coding: utf-8 -*-
4 Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
5 Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from optparse import make_option
24 from stgit.argparse import opt
25 from stgit.commands import common
26 from stgit.lib import log
27 from stgit.out import out
29 help = 'Display the patch changelog'
31 usage = ['[options] [<patches>]']
33 List the history of the patch stack: the stack log. If one or more
34 patch names are given, limit the list to the log entries that touch
37 "stg undo" and "stg redo" let you step back and forth in the patch
38 stack. "stg reset" lets you go directly to any state."""
42 short = 'Use BRANCH instead of the default one'),
43 opt('-p', '--patch', action = 'store_true',
44 short = 'Show the refresh diffs'),
45 opt('-n', '--number', type = 'int',
46 short = 'Limit the output to NUMBER commits'),
47 opt('-f', '--full', action = 'store_true',
48 short = 'Show the full commit ids'),
49 opt('-g', '--graphical', action = 'store_true',
50 short = 'Run gitk instead of printing')]
52 directory = common.DirectoryHasRepositoryLib()
54 def show_log(stacklog, pathlim, num, full, show_diff):
56 if num != None and num > 0:
57 cmd.append('-%d' % num)
61 cmd.append('--pretty=format:%h %aD %s')
62 run.Run(*(cmd + [stacklog.sha1, '--'] + pathlim)).run()
64 def func(parser, options, args):
66 stack = directory.repository.get_stack(options.branch)
68 stack = directory.repository.current_stack
69 patches = common.parse_patches(args, list(stack.patchorder.all))
70 logref = log.log_ref(stack.name)
72 logcommit = stack.repository.refs.get(logref)
74 out.info('Log is empty')
76 stacklog = log.get_log_entry(stack.repository, logref, logcommit)
77 pathlim = [os.path.join('patches', pn) for pn in patches]
80 for o in ['diff', 'number', 'full']:
81 if getattr(options, o):
82 parser.error('cannot combine --graphical and --%s' % o)
83 # Discard the exit codes generated by SIGINT, SIGKILL, and SIGTERM.
84 run.Run(*(['gitk', stacklog.simplified.sha1, '--'] + pathlim)
85 ).returns([0, -2, -9, -15]).run()
87 show_log(stacklog.simplified, pathlim,
88 options.number, options.full, options.diff)