Merge branch 'stable'
[stgit] / stgit / commands / log.py
1 # -*- coding: utf-8 -*-
2
3 __copyright__ = """
4 Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
5 Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 """
20
21 import os.path
22 from optparse import make_option
23 from stgit import argparse, run
24 from stgit.argparse import opt
25 from stgit.commands import common
26 from stgit.lib import log
27 from stgit.out import out
28
29 help = 'Display the patch changelog'
30 kind = 'stack'
31 usage = ['[options] [<patches>]']
32 description = """
33 List the history of the patch stack: the stack log. If one or more
34 patch names are given, limit the list to the log entries that touch
35 the named patches.
36
37 "stg undo" and "stg redo" let you step back and forth in the patch
38 stack. "stg reset" lets you go directly to any state."""
39
40 args = [argparse.patch_range(argparse.applied_patches,
41 argparse.unapplied_patches,
42 argparse.hidden_patches)]
43 options = [
44 opt('-b', '--branch', args = [argparse.stg_branches],
45 short = 'Use BRANCH instead of the default one'),
46 opt('-d', '--diff', action = 'store_true',
47 short = 'Show the refresh diffs'),
48 opt('-n', '--number', type = 'int',
49 short = 'Limit the output to NUMBER commits'),
50 opt('-f', '--full', action = 'store_true',
51 short = 'Show the full commit ids'),
52 opt('-g', '--graphical', action = 'store_true',
53 short = 'Run gitk instead of printing')]
54
55 directory = common.DirectoryHasRepositoryLib()
56
57 def show_log(stacklog, pathlim, num, full, show_diff):
58 cmd = ['git', 'log']
59 if num != None and num > 0:
60 cmd.append('-%d' % num)
61 if show_diff:
62 cmd.append('-p')
63 elif not full:
64 cmd.append('--pretty=format:%h %aD %s')
65 run.Run(*(cmd + [stacklog.sha1, '--'] + pathlim)).run()
66
67 def func(parser, options, args):
68 if options.branch:
69 stack = directory.repository.get_stack(options.branch)
70 else:
71 stack = directory.repository.current_stack
72 patches = common.parse_patches(args, list(stack.patchorder.all))
73 logref = log.log_ref(stack.name)
74 try:
75 logcommit = stack.repository.refs.get(logref)
76 except KeyError:
77 out.info('Log is empty')
78 return
79 stacklog = log.get_log_entry(stack.repository, logref, logcommit)
80 pathlim = [os.path.join('patches', pn) for pn in patches]
81
82 if options.graphical:
83 for o in ['diff', 'number', 'full']:
84 if getattr(options, o):
85 parser.error('cannot combine --graphical and --%s' % o)
86 # Discard the exit codes generated by SIGINT, SIGKILL, and SIGTERM.
87 run.Run(*(['gitk', stacklog.simplified.sha1, '--'] + pathlim)
88 ).returns([0, -2, -9, -15]).run()
89 else:
90 show_log(stacklog.simplified, pathlim,
91 options.number, options.full, options.diff)