Print conflict details with the new infrastructure (bug #11181)
[stgit] / stgit / commands / log.py
... / ...
CommitLineData
1# -*- coding: utf-8 -*-
2
3__copyright__ = """
4Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
5Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
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
21import os.path
22from optparse import make_option
23from stgit import argparse, run
24from stgit.argparse import opt
25from stgit.commands import common
26from stgit.lib import log
27from stgit.out import out
28
29help = 'Display the patch changelog'
30kind = 'stack'
31usage = ['[options] [<patches>]']
32description = """
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.
36
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."""
39
40args = [argparse.patch_range(argparse.applied_patches,
41 argparse.unapplied_patches,
42 argparse.hidden_patches)]
43options = [
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
55directory = common.DirectoryHasRepositoryLib()
56
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()
66
67def 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)