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