Merge branch 'stable'
[stgit] / stgit / commands / log.py
CommitLineData
de19d17b
KH
1# -*- coding: utf-8 -*-
2
64354a2d
CM
3__copyright__ = """
4Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
de19d17b 5Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
64354a2d
CM
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License version 2 as
9published by the Free Software Foundation.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19"""
20
de19d17b
KH
21import os.path
22from optparse import make_option
6c8a90e1 23from stgit import argparse, run
575bbdae 24from stgit.argparse import opt
de19d17b
KH
25from stgit.commands import common
26from stgit.lib import log
27from stgit.out import out
64354a2d 28
575bbdae 29help = 'Display the patch changelog'
de19d17b
KH
30kind = 'stack'
31usage = ['[options] [<patches>]']
575bbdae 32description = """
de19d17b
KH
33List the history of the patch stack: the stack log. If one or more
34patch names are given, limit the list to the log entries that touch
35the named patches.
64354a2d 36
de19d17b
KH
37"stg undo" and "stg redo" let you step back and forth in the patch
38stack. "stg reset" lets you go directly to any state."""
64354a2d 39
6c8a90e1
KH
40args = [argparse.patch_range(argparse.applied_patches,
41 argparse.unapplied_patches,
42 argparse.hidden_patches)]
575bbdae 43options = [
6c8a90e1 44 opt('-b', '--branch', args = [argparse.stg_branches],
575bbdae 45 short = 'Use BRANCH instead of the default one'),
3730c524 46 opt('-d', '--diff', action = 'store_true',
575bbdae
KH
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
de19d17b 55directory = common.DirectoryHasRepositoryLib()
380fde12 56
de19d17b
KH
57def 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()
64354a2d
CM
66
67def func(parser, options, args):
de19d17b
KH
68 if options.branch:
69 stack = directory.repository.get_stack(options.branch)
64354a2d 70 else:
de19d17b
KH
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]
64354a2d
CM
81
82 if options.graphical:
de19d17b
KH
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()
64354a2d 89 else:
de19d17b
KH
90 show_log(stacklog.simplified, pathlim,
91 options.number, options.full, options.diff)