Commit | Line | Data |
---|---|---|
64354a2d CM |
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 | ||
06848fab CM |
39 | Note that only the diffs shown in the 'refresh', 'undo' and 'sync' |
40 | actions are meaningful for the patch changes. The 'push' actions | |
41 | represent the changes to the entire base of the current | |
42 | patch. Conflicts reset the patch content and a subsequent 'refresh' | |
43 | will show the entire patch.""" | |
64354a2d CM |
44 | |
45 | options = [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 | ||
54 | def 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 | ||
84 | def 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) |