From: Catalin Marinas Date: Fri, 22 Jun 2007 21:21:55 +0000 (+0100) Subject: Modify the 'patches' command to use the locally modified files X-Git-Tag: v0.14.3~204 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/d436b1dac150bb6cd6def2da612aba7b5b950ee8 Modify the 'patches' command to use the locally modified files With this patch, when running 'stg patches' without any arguments, it uses the locally modified files by default. This way one can see which patches are affected by the locally modified files. Signed-off-by: Catalin Marinas --- diff --git a/stgit/commands/patches.py b/stgit/commands/patches.py index a8fb008..23b3aa7 100644 --- a/stgit/commands/patches.py +++ b/stgit/commands/patches.py @@ -25,10 +25,12 @@ from stgit import stack, git help = 'show the applied patches modifying a file' -usage = """%prog [options] [...] +usage = """%prog [options] [] -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', @@ -47,14 +49,19 @@ diff_tmpl = \ 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() @@ -72,7 +79,7 @@ def func(parser, options, args): 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()) diff --git a/stgit/git.py b/stgit/git.py index 6c96a16..02590a9 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -216,7 +216,7 @@ def __run(cmd, args=None): 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] """ @@ -268,7 +268,7 @@ def __tree_status(files = None, tree_id = 'HEAD', unknown = False, 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 @@ -567,7 +567,7 @@ def update_cache(files = None, force = False): 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: @@ -745,7 +745,7 @@ def status(files = None, modified = False, new = False, deleted = False, 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) @@ -876,7 +876,7 @@ def reset(files = None, tree_id = None, check_out = True): 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']]