Allow 'refresh' to annotate the patch log entries
[stgit] / stgit / commands / log.py
CommitLineData
64354a2d
CM
1__copyright__ = """
2Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License version 2 as
6published by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16"""
17
18import sys, os, time
19from optparse import OptionParser, make_option
20from pydoc import pager
21from stgit.commands.common import *
22from stgit import stack, git
23
24help = 'display the patch changelog'
25usage = """%prog [options] [patch]
26
27List all the current and past commit ids of the given patch. The
28--graphical option invokes gitk instead of printing. The changelog
29commit messages have the form '<action> <new-patch-id>'. The <action>
30can be one of the following:
31
32 new - new patch created
33 refresh - local changes were added to the patch
34 push - the patch was cleanly pushed onto the stack
35 push(m) - the patch was pushed onto the stack with a three-way merge
36 push(f) - the patch was fast-forwarded
37 undo - the patch boundaries were restored to the old values
38
06848fab
CM
39Note that only the diffs shown in the 'refresh', 'undo' and 'sync'
40actions are meaningful for the patch changes. The 'push' actions
41represent the changes to the entire base of the current
42patch. Conflicts reset the patch content and a subsequent 'refresh'
43will show the entire patch."""
64354a2d
CM
44
45options = [make_option('-b', '--branch',
46 help = 'use BRANCH instead of the default one'),
47 make_option('-p', '--patch',
48 help = 'show the refresh diffs',
49 action = 'store_true'),
eff17c6b
CM
50 make_option('-f', '--full',
51 help = 'show the full commit ids',
52 action = 'store_true'),
64354a2d
CM
53 make_option('-g', '--graphical',
54 help = 'run gitk instead of printing',
55 action = 'store_true')]
56
eff17c6b 57def show_log(log, options):
64354a2d
CM
58 """List the patch changelog
59 """
60 commit = git.get_commit(log)
61 diff_str = ''
62 while commit:
eff17c6b
CM
63 log = commit.get_log().split('\n')
64
65 cmd_rev = log[0].split()
66 if len(cmd_rev) >= 2:
67 cmd = cmd_rev[0]
68 rev = cmd_rev[1]
69 elif len(cmd_rev) == 1:
70 cmd = cmd_rev[0]
71 rev = ''
72 else:
73 cmd = rev = ''
64354a2d 74
eff17c6b
CM
75 if options.patch:
76 if cmd in ['refresh', 'undo', 'sync']:
64354a2d
CM
77 diff_str = '%s%s\n' % (diff_str,
78 git.pretty_commit(commit.get_id_hash()))
79 else:
eff17c6b
CM
80 if len(log) >= 3:
81 notes = log[2]
82 else:
83 notes = ''
64354a2d
CM
84 author_name, author_email, author_date = \
85 name_email_date(commit.get_author())
86 secs, tz = author_date.split()
87 date = '%s %s' % (time.ctime(int(secs)), tz)
88
eff17c6b
CM
89 if options.full:
90 out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date))
91 else:
92 out.stdout('%-8s [%-7s] %-28s %s' % \
93 (rev[:8], cmd[:7], notes[:28], date))
64354a2d
CM
94
95 parent = commit.get_parent()
96 if parent:
97 commit = git.get_commit(parent)
98 else:
99 commit = None
100
eff17c6b 101 if options.patch and diff_str:
64354a2d
CM
102 pager(diff_str.rstrip())
103
104def func(parser, options, args):
105 """Show the patch changelog
106 """
107 if len(args) == 0:
108 name = crt_series.get_current()
109 if not name:
110 raise CmdException, 'No patches applied'
111 elif len(args) == 1:
112 name = args[0]
cc9888a8
YD
113 if not name in crt_series.get_applied() + crt_series.get_unapplied() + \
114 crt_series.get_hidden():
64354a2d
CM
115 raise CmdException, 'Unknown patch "%s"' % name
116 else:
117 parser.error('incorrect number of arguments')
118
119 patch = crt_series.get_patch(name)
120
121 log = patch.get_log()
122 if not log:
123 raise CmdException, 'No changelog for patch "%s"' % name
124
125 if options.graphical:
126 if os.system('gitk %s' % log) != 0:
127 raise CmdException, 'gitk execution failed'
128 else:
eff17c6b 129 show_log(log, options)