chiark / gitweb /
Modify the 'patches' command to use the locally modified files
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 22 Jun 2007 21:21:55 +0000 (22:21 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 22 Jun 2007 21:21:55 +0000 (22:21 +0100)
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 <catalin.marinas@gmail.com>
stgit/commands/patches.py
stgit/git.py

index a8fb00882a3d596d97abadb9420270f017bc9f89..23b3aa75131448c1847c774fbd0c76939f666fc4 100644 (file)
@@ -25,10 +25,12 @@ from stgit import stack, git
 
 
 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',
@@ -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())
index 6c96a1682a5a975583f8aaa8edea776894f6e908..02590a9512b1fd8f7a79cbfbe97413fc762fc364 100644 (file)
@@ -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']]