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'
28 usage = ['[options] [patch]']
30 List all the current and past commit ids of the given patch. The
31 --graphical option invokes gitk instead of printing. The changelog
32 commit messages have the form '<action> <new-patch-id>'. The <action>
33 can be one of the following:
35 new - new patch created
36 refresh - local changes were added to the patch
37 push - the patch was cleanly pushed onto the stack
38 push(m) - the patch was pushed onto the stack with a three-way merge
39 push(f) - the patch was fast-forwarded
40 undo - the patch boundaries were restored to the old values
42 Note that only the diffs shown in the 'refresh', 'undo' and 'sync'
43 actions are meaningful for the patch changes. The 'push' actions
44 represent the changes to the entire base of the current
45 patch. Conflicts reset the patch content and a subsequent 'refresh'
46 will show the entire patch."""
50 short = 'Use BRANCH instead of the default one'),
51 opt('-p', '--patch', action = 'store_true',
52 short = 'Show the refresh diffs'),
53 opt('-n', '--number', type = 'int',
54 short = 'Limit the output to NUMBER commits'),
55 opt('-f', '--full', action = 'store_true',
56 short = 'Show the full commit ids'),
57 opt('-g', '--graphical', action = 'store_true',
58 short = 'Run gitk instead of printing')]
60 directory = DirectoryHasRepository()
62 def show_log(log, options):
63 """List the patch changelog
65 commit = git.get_commit(log)
66 if options.number != None:
76 log = commit.get_log().split('\n')
78 cmd_rev = log[0].split()
82 elif len(cmd_rev) == 1:
89 if cmd in ['refresh', 'undo', 'sync', 'edit']:
90 diff_list.append(git.pretty_commit(commit.get_id_hash()))
99 author_name, author_email, author_date = \
100 name_email_date(commit.get_author())
101 secs, tz = author_date.split()
102 date = '%s %s' % (time.ctime(int(secs)), tz)
105 out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date))
107 out.stdout('%-8s [%-7s] %-28s %s' % \
108 (rev[:8], cmd[:7], notes[:28], date))
113 parent = commit.get_parent()
115 commit = git.get_commit(parent)
119 if options.patch and diff_list:
120 pager('\n'.join(diff_list).rstrip())
122 def func(parser, options, args):
123 """Show the patch changelog
126 name = crt_series.get_current()
128 raise CmdException, 'No patches applied'
131 if not name in crt_series.get_applied() + crt_series.get_unapplied() + \
132 crt_series.get_hidden():
133 raise CmdException, 'Unknown patch "%s"' % name
135 parser.error('incorrect number of arguments')
137 patch = crt_series.get_patch(name)
139 log = patch.get_log()
141 raise CmdException, 'No changelog for patch "%s"' % name
143 if options.graphical:
144 # discard the exit codes generated by SIGINT, SIGKILL, SIGTERM
145 Run('gitk', log).returns([0, -2, -9, -15]).run()
147 show_log(log, options)