033c79759309bc17679af7551be0122234ab8a6f
[stgit] / stgit / commands / log.py
1 __copyright__ = """
2 Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
3
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.
7
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.
12
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
16 """
17
18 import sys, os, time
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
24 help = 'display the patch changelog'
25 usage = """%prog [options] [patch]
26
27 List all the current and past commit ids of the given patch. The
28 --graphical option invokes gitk instead of printing. The changelog
29 commit messages have the form '<action> <new-patch-id>'. The <action>
30 can 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
39 Note that only the diffs shown in the 'refresh' and 'undo' actions are
40 meaningful for the patch changes. The 'push' actions represent the
41 changes to the entire base of the current patch. Conflicts reset the
42 patch content and a subsequent 'refresh' will show the entire patch."""
43
44 options = [make_option('-b', '--branch',
45 help = 'use BRANCH instead of the default one'),
46 make_option('-p', '--patch',
47 help = 'show the refresh diffs',
48 action = 'store_true'),
49 make_option('-g', '--graphical',
50 help = 'run gitk instead of printing',
51 action = 'store_true')]
52
53 def show_log(log, show_patch):
54 """List the patch changelog
55 """
56 commit = git.get_commit(log)
57 diff_str = ''
58 while commit:
59 descr = commit.get_log().rstrip()
60
61 if show_patch:
62 if descr.startswith('refresh') or descr.startswith('undo'):
63 diff_str = '%s%s\n' % (diff_str,
64 git.pretty_commit(commit.get_id_hash()))
65 else:
66 author_name, author_email, author_date = \
67 name_email_date(commit.get_author())
68 secs, tz = author_date.split()
69 date = '%s %s' % (time.ctime(int(secs)), tz)
70
71 print descr, date
72
73 parent = commit.get_parent()
74 if parent:
75 commit = git.get_commit(parent)
76 else:
77 commit = None
78
79 if show_patch and diff_str:
80 pager(diff_str.rstrip())
81
82 def func(parser, options, args):
83 """Show the patch changelog
84 """
85 if len(args) == 0:
86 name = crt_series.get_current()
87 if not name:
88 raise CmdException, 'No patches applied'
89 elif len(args) == 1:
90 name = args[0]
91 if not name in crt_series.get_applied() + crt_series.get_unapplied():
92 raise CmdException, 'Unknown patch "%s"' % name
93 else:
94 parser.error('incorrect number of arguments')
95
96 patch = crt_series.get_patch(name)
97
98 log = patch.get_log()
99 if not log:
100 raise CmdException, 'No changelog for patch "%s"' % name
101
102 if options.graphical:
103 if os.system('gitk %s' % log) != 0:
104 raise CmdException, 'gitk execution failed'
105 else:
106 show_log(log, options.patch)