Add the 'sync' command
[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'),
50 make_option('-g', '--graphical',
51 help = 'run gitk instead of printing',
52 action = 'store_true')]
53
54def show_log(log, show_patch):
55 """List the patch changelog
56 """
57 commit = git.get_commit(log)
58 diff_str = ''
59 while commit:
60 descr = commit.get_log().rstrip()
61
62 if show_patch:
06848fab
CM
63 if descr.startswith('refresh') or descr.startswith('undo') \
64 or descr.startswith('sync'):
64354a2d
CM
65 diff_str = '%s%s\n' % (diff_str,
66 git.pretty_commit(commit.get_id_hash()))
67 else:
68 author_name, author_email, author_date = \
69 name_email_date(commit.get_author())
70 secs, tz = author_date.split()
71 date = '%s %s' % (time.ctime(int(secs)), tz)
72
73 print descr, date
74
75 parent = commit.get_parent()
76 if parent:
77 commit = git.get_commit(parent)
78 else:
79 commit = None
80
81 if show_patch and diff_str:
82 pager(diff_str.rstrip())
83
84def func(parser, options, args):
85 """Show the patch changelog
86 """
87 if len(args) == 0:
88 name = crt_series.get_current()
89 if not name:
90 raise CmdException, 'No patches applied'
91 elif len(args) == 1:
92 name = args[0]
93 if not name in crt_series.get_applied() + crt_series.get_unapplied():
94 raise CmdException, 'Unknown patch "%s"' % name
95 else:
96 parser.error('incorrect number of arguments')
97
98 patch = crt_series.get_patch(name)
99
100 log = patch.get_log()
101 if not log:
102 raise CmdException, 'No changelog for patch "%s"' % name
103
104 if options.graphical:
105 if os.system('gitk %s' % log) != 0:
106 raise CmdException, 'gitk execution failed'
107 else:
108 show_log(log, options.patch)