help = 'show the applied patches modifying a file'
-usage = """%prog [options] <file> [<file>...]
+usage = """%prog [options] [<files...>]
-Show the applied patches modifying the given files. The '--diff'
-option also lists the patch log and the diff for the given files."""
+Show the applied patches modifying the given files. Without arguments,
+it shows the patches affected by the local tree modifications. The
+'--diff' option also lists the patch log and the diff for the given
+files."""
options = [make_option('-d', '--diff',
help = 'show the diff for the given files',
def func(parser, options, args):
"""Show the patches modifying a file
"""
- if len(args) < 1:
- parser.error('incorrect number of arguments')
+ if not args:
+ files = [stat[1] for stat in git.tree_status(verbose = True)]
+ else:
+ files = args
+
+ if not files:
+ raise CmdException, 'No files specified or no local changes'
applied = crt_series.get_applied()
if not applied:
raise CmdException, 'No patches applied'
- revs = git.modifying_revs(args, crt_series.get_base(),
+ revs = git.modifying_revs(files, crt_series.get_base(),
crt_series.get_head())
revs.reverse()
if options.diff:
diff_output += diff_tmpl \
% (patch.get_name(), patch.get_description(),
- git.diff(args, patch.get_bottom(),
+ git.diff(files, patch.get_bottom(),
patch.get_top()))
else:
out.stdout(patch.get_name())
return r
return 0
-def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
+def tree_status(files = None, tree_id = 'HEAD', unknown = False,
noexclude = True, verbose = False, diff_flags = []):
"""Returns a list of pairs - [status, filename]
"""
def local_changes(verbose = True):
"""Return true if there are local changes in the tree
"""
- return len(__tree_status(verbose = verbose)) != 0
+ return len(tree_status(verbose = verbose)) != 0
# HEAD value cached
__head = None
if not files:
files = []
- cache_files = __tree_status(files, verbose = False)
+ cache_files = tree_status(files, verbose = False)
# everything is up-to-date
if len(cache_files) == 0:
if not files:
files = []
- cache_files = __tree_status(files, unknown = True, noexclude = noexclude,
+ cache_files = tree_status(files, unknown = True, noexclude = noexclude,
diff_flags = diff_flags)
all = not (modified or new or deleted or conflict or unknown)
tree_id = get_head()
if check_out:
- cache_files = __tree_status(files, tree_id)
+ cache_files = tree_status(files, tree_id)
# files which were added but need to be removed
rm_files = [x[1] for x in cache_files if x[0] in ['A']]