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 optparse
import OptionParser
, make_option
20 from pydoc
import pager
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
= """%prog [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."""
47 directory
= DirectoryHasRepository()
48 options
= [make_option('-b', '--branch',
49 help = 'use BRANCH instead of the default one'),
50 make_option('-p', '--patch',
51 help = 'show the refresh diffs',
52 action
= 'store_true'),
53 make_option('-n', '--number', type = 'int',
54 help = 'limit the output to NUMBER commits'),
55 make_option('-f', '--full',
56 help = 'show the full commit ids',
57 action
= 'store_true'),
58 make_option('-g', '--graphical',
59 help = 'run gitk instead of printing',
60 action
= 'store_true')]
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
)