1 from stgit
.argparse
import diff_opts_option
, opt
, patch_range
2 from stgit
.commands
.common
import (
3 DirectoryHasRepository
,
7 from stgit
.lib
.git
import RepositoryException
8 from stgit
.pager
import pager
9 from stgit
.run
import Run
12 Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 2 as
16 published by the Free Software Foundation.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see http://www.gnu.org/licenses/.
27 help = 'Show the commit corresponding to a patch'
30 '[-b] [-s] [-O] [--] [<patch1>] [<patch2>] [<patch3>..<patch4>]',
31 '(--applied | --unapplied) [-b] [-s] [-O]',
35 Show the commit log and the diff corresponding to the given patches.
36 The output is similar to that generated by 'git show'."""
38 args
= [patch_range('applied_patches', 'unapplied_patches', 'hidden_patches')]
43 args
=['stg_branches'],
44 short
='Use BRANCH instead of the default branch',
50 short
='Show the applied patches',
56 short
='Show the unapplied patches',
62 short
='Show a diffstat summary of the specified patches',
64 ] + diff_opts_option()
66 directory
= DirectoryHasRepository()
69 def func(parser
, options
, args
):
70 """Show commit log and diff"""
71 if args
and (options
.applied
or options
.unapplied
):
72 parser
.error('patches may not be given with --applied or --unapplied')
73 elif options
.applied
and options
.unapplied
:
74 parser
.error('cannot use both --applied and --unapplied')
76 repository
= directory
.repository
77 stack
= repository
.get_stack(options
.branch
)
78 patchorder
= stack
.patchorder
81 commits
= [stack
.patches
[pn
] for pn
in patchorder
.applied
]
82 elif options
.unapplied
:
83 commits
= [stack
.patches
[pn
] for pn
in patchorder
.unapplied
]
86 elif '..' in ' '.join(args
):
88 patch_names
= parse_patches(
91 len(patchorder
.applied
),
93 commits
= [stack
.patches
[pn
] for pn
in patch_names
]
97 if name
in stack
.patches
:
98 commits
.append(stack
.patches
[name
])
102 repository
.rev_parse(
103 name
, object_type
='commit', discard_stderr
=True
106 except RepositoryException
:
107 raise RepositoryException(
108 '%s: Unknown patch or revision name' % name
111 cmd
= ['git', 'show']
113 cmd
.extend(['--stat', '--summary'])
115 cmd
.append('--patch')
116 cmd
.extend(options
.diff_flags
)
117 cmd
.extend(color_diff_flags())
118 cmd
.extend(commit
.sha1
for commit
in commits
)
119 pager(Run(*cmd
).decoding(None).raw_output())