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