2 Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2 as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 from pydoc import pager
20 from stgit.argparse import opt
21 from stgit.commands.common import *
22 from stgit import stack, git
23 from stgit.out import *
24 from stgit.run import Run
26 help = 'Display the patch changelog'
27 usage = ['[options] [patch]']
29 List all the current and past commit ids of the given patch. The
30 --graphical option invokes gitk instead of printing. The changelog
31 commit messages have the form '<action> <new-patch-id>'. The <action>
32 can be one of the following:
34 new - new patch created
35 refresh - local changes were added to the patch
36 push - the patch was cleanly pushed onto the stack
37 push(m) - the patch was pushed onto the stack with a three-way merge
38 push(f) - the patch was fast-forwarded
39 undo - the patch boundaries were restored to the old values
41 Note that only the diffs shown in the 'refresh', 'undo' and 'sync'
42 actions are meaningful for the patch changes. The 'push' actions
43 represent the changes to the entire base of the current
44 patch. Conflicts reset the patch content and a subsequent 'refresh'
45 will show the entire patch."""
49 short = 'Use BRANCH instead of the default one'),
50 opt('-p', '--patch', action = 'store_true',
51 short = 'Show the refresh diffs'),
52 opt('-n', '--number', type = 'int',
53 short = 'Limit the output to NUMBER commits'),
54 opt('-f', '--full', action = 'store_true',
55 short = 'Show the full commit ids'),
56 opt('-g', '--graphical', action = 'store_true',
57 short = 'Run gitk instead of printing')]
59 directory = DirectoryHasRepository()
61 def show_log(log, options):
62 """List the patch changelog
64 commit = git.get_commit(log)
65 if options.number != None:
75 log = commit.get_log().split('\n')
77 cmd_rev = log[0].split()
81 elif len(cmd_rev) == 1:
88 if cmd in ['refresh', 'undo', 'sync', 'edit']:
89 diff_list.append(git.pretty_commit(commit.get_id_hash()))
98 author_name, author_email, author_date = \
99 name_email_date(commit.get_author())
100 secs, tz = author_date.split()
101 date = '%s %s' % (time.ctime(int(secs)), tz)
104 out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date))
106 out.stdout('%-8s [%-7s] %-28s %s' % \
107 (rev[:8], cmd[:7], notes[:28], date))
112 parent = commit.get_parent()
114 commit = git.get_commit(parent)
118 if options.patch and diff_list:
119 pager('\n'.join(diff_list).rstrip())
121 def func(parser, options, args):
122 """Show the patch changelog
125 name = crt_series.get_current()
127 raise CmdException, 'No patches applied'
130 if not name in crt_series.get_applied() + crt_series.get_unapplied() + \
131 crt_series.get_hidden():
132 raise CmdException, 'Unknown patch "%s"' % name
134 parser.error('incorrect number of arguments')
136 patch = crt_series.get_patch(name)
138 log = patch.get_log()
140 raise CmdException, 'No changelog for patch "%s"' % name
142 if options.graphical:
143 # discard the exit codes generated by SIGINT, SIGKILL, SIGTERM
144 Run('gitk', log).returns([0, -2, -9, -15]).run()
146 show_log(log, options)