| 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', '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.""" |
| 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('-f', '--full', |
| 51 | help = 'show the full commit ids', |
| 52 | action = 'store_true'), |
| 53 | make_option('-g', '--graphical', |
| 54 | help = 'run gitk instead of printing', |
| 55 | action = 'store_true')] |
| 56 | |
| 57 | def show_log(log, options): |
| 58 | """List the patch changelog |
| 59 | """ |
| 60 | commit = git.get_commit(log) |
| 61 | diff_str = '' |
| 62 | while commit: |
| 63 | log = commit.get_log().split('\n') |
| 64 | |
| 65 | cmd_rev = log[0].split() |
| 66 | if len(cmd_rev) >= 2: |
| 67 | cmd = cmd_rev[0] |
| 68 | rev = cmd_rev[1] |
| 69 | elif len(cmd_rev) == 1: |
| 70 | cmd = cmd_rev[0] |
| 71 | rev = '' |
| 72 | else: |
| 73 | cmd = rev = '' |
| 74 | |
| 75 | if options.patch: |
| 76 | if cmd in ['refresh', 'undo', 'sync']: |
| 77 | diff_str = '%s%s\n' % (diff_str, |
| 78 | git.pretty_commit(commit.get_id_hash())) |
| 79 | else: |
| 80 | if len(log) >= 3: |
| 81 | notes = log[2] |
| 82 | else: |
| 83 | notes = '' |
| 84 | author_name, author_email, author_date = \ |
| 85 | name_email_date(commit.get_author()) |
| 86 | secs, tz = author_date.split() |
| 87 | date = '%s %s' % (time.ctime(int(secs)), tz) |
| 88 | |
| 89 | if options.full: |
| 90 | out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date)) |
| 91 | else: |
| 92 | out.stdout('%-8s [%-7s] %-28s %s' % \ |
| 93 | (rev[:8], cmd[:7], notes[:28], date)) |
| 94 | |
| 95 | parent = commit.get_parent() |
| 96 | if parent: |
| 97 | commit = git.get_commit(parent) |
| 98 | else: |
| 99 | commit = None |
| 100 | |
| 101 | if options.patch and diff_str: |
| 102 | pager(diff_str.rstrip()) |
| 103 | |
| 104 | def func(parser, options, args): |
| 105 | """Show the patch changelog |
| 106 | """ |
| 107 | if len(args) == 0: |
| 108 | name = crt_series.get_current() |
| 109 | if not name: |
| 110 | raise CmdException, 'No patches applied' |
| 111 | elif len(args) == 1: |
| 112 | name = args[0] |
| 113 | if not name in crt_series.get_applied() + crt_series.get_unapplied() + \ |
| 114 | crt_series.get_hidden(): |
| 115 | raise CmdException, 'Unknown patch "%s"' % name |
| 116 | else: |
| 117 | parser.error('incorrect number of arguments') |
| 118 | |
| 119 | patch = crt_series.get_patch(name) |
| 120 | |
| 121 | log = patch.get_log() |
| 122 | if not log: |
| 123 | raise CmdException, 'No changelog for patch "%s"' % name |
| 124 | |
| 125 | if options.graphical: |
| 126 | if os.system('gitk %s' % log) != 0: |
| 127 | raise CmdException, 'gitk execution failed' |
| 128 | else: |
| 129 | show_log(log, options) |