chiark / gitweb /
Infrastructure for current directory handling
[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
5e888f30 23from stgit.out import *
64354a2d
CM
24
25help = 'display the patch changelog'
26usage = """%prog [options] [patch]
27
28List all the current and past commit ids of the given patch. The
29--graphical option invokes gitk instead of printing. The changelog
30commit messages have the form '<action> <new-patch-id>'. The <action>
31can be one of the following:
32
33 new - new patch created
34 refresh - local changes were added to the patch
35 push - the patch was cleanly pushed onto the stack
36 push(m) - the patch was pushed onto the stack with a three-way merge
37 push(f) - the patch was fast-forwarded
38 undo - the patch boundaries were restored to the old values
39
06848fab
CM
40Note that only the diffs shown in the 'refresh', 'undo' and 'sync'
41actions are meaningful for the patch changes. The 'push' actions
42represent the changes to the entire base of the current
43patch. Conflicts reset the patch content and a subsequent 'refresh'
44will show the entire patch."""
64354a2d 45
6dd8fafa 46directory = DirectoryHasRepository()
64354a2d
CM
47options = [make_option('-b', '--branch',
48 help = 'use BRANCH instead of the default one'),
49 make_option('-p', '--patch',
50 help = 'show the refresh diffs',
51 action = 'store_true'),
eff17c6b
CM
52 make_option('-f', '--full',
53 help = 'show the full commit ids',
54 action = 'store_true'),
64354a2d
CM
55 make_option('-g', '--graphical',
56 help = 'run gitk instead of printing',
57 action = 'store_true')]
58
eff17c6b 59def show_log(log, options):
64354a2d
CM
60 """List the patch changelog
61 """
62 commit = git.get_commit(log)
63 diff_str = ''
64 while commit:
eff17c6b
CM
65 log = commit.get_log().split('\n')
66
67 cmd_rev = log[0].split()
68 if len(cmd_rev) >= 2:
69 cmd = cmd_rev[0]
70 rev = cmd_rev[1]
71 elif len(cmd_rev) == 1:
72 cmd = cmd_rev[0]
73 rev = ''
74 else:
75 cmd = rev = ''
64354a2d 76
eff17c6b
CM
77 if options.patch:
78 if cmd in ['refresh', 'undo', 'sync']:
64354a2d
CM
79 diff_str = '%s%s\n' % (diff_str,
80 git.pretty_commit(commit.get_id_hash()))
81 else:
eff17c6b
CM
82 if len(log) >= 3:
83 notes = log[2]
84 else:
85 notes = ''
64354a2d
CM
86 author_name, author_email, author_date = \
87 name_email_date(commit.get_author())
88 secs, tz = author_date.split()
89 date = '%s %s' % (time.ctime(int(secs)), tz)
90
eff17c6b
CM
91 if options.full:
92 out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date))
93 else:
94 out.stdout('%-8s [%-7s] %-28s %s' % \
95 (rev[:8], cmd[:7], notes[:28], date))
64354a2d
CM
96
97 parent = commit.get_parent()
98 if parent:
99 commit = git.get_commit(parent)
100 else:
101 commit = None
102
eff17c6b 103 if options.patch and diff_str:
64354a2d
CM
104 pager(diff_str.rstrip())
105
106def func(parser, options, args):
107 """Show the patch changelog
108 """
109 if len(args) == 0:
110 name = crt_series.get_current()
111 if not name:
112 raise CmdException, 'No patches applied'
113 elif len(args) == 1:
114 name = args[0]
cc9888a8
YD
115 if not name in crt_series.get_applied() + crt_series.get_unapplied() + \
116 crt_series.get_hidden():
64354a2d
CM
117 raise CmdException, 'Unknown patch "%s"' % name
118 else:
119 parser.error('incorrect number of arguments')
120
121 patch = crt_series.get_patch(name)
122
123 log = patch.get_log()
124 if not log:
125 raise CmdException, 'No changelog for patch "%s"' % name
126
127 if options.graphical:
128 if os.system('gitk %s' % log) != 0:
129 raise CmdException, 'gitk execution failed'
130 else:
eff17c6b 131 show_log(log, options)