Cleanup tree_status and use -z
authorDavid Kågedal <david@virtutech.com>
Fri, 17 Aug 2007 15:06:33 +0000 (17:06 +0200)
committerKarl Hasselström <kha@treskal.com>
Fri, 31 Aug 2007 06:36:20 +0000 (08:36 +0200)
Improved the python code, eliminating temporary variables and using
destructuring binds. And use NUL-separation instead of newlines.

Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/patches.py
stgit/commands/refresh.py
stgit/git.py

index b3defb6..fb65b62 100644 (file)
@@ -51,7 +51,7 @@ def func(parser, options, args):
     """Show the patches modifying a file
     """
     if not args:
-        files = [stat[1] for stat in git.tree_status(verbose = True)]
+        files = [path for (stat,path) in git.tree_status(verbose = True)]
     else:
         files = args
 
index 218075b..f44c58c 100644 (file)
@@ -121,7 +121,7 @@ def func(parser, options, args):
     else:
         sign_str = None
 
-    files = [x[1] for x in git.tree_status(verbose = True)]
+    files = [path for (stat,path) in git.tree_status(verbose = True)]
     if args:
         files = [f for f in files if f in args]
 
index 7962cdb..f315b05 100644 (file)
@@ -168,7 +168,7 @@ def exclude_files():
 
 def tree_status(files = None, tree_id = 'HEAD', unknown = False,
                   noexclude = True, verbose = False, diff_flags = []):
-    """Returns a list of pairs - [status, filename]
+    """Returns a list of pairs - (status, filename)
     """
     if verbose:
         out.start('Checking for changes in the working directory')
@@ -181,16 +181,16 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
 
     # unknown files
     if unknown:
-        if noexclude:
-            exclude = []
-        else:
-            exclude = (['--exclude=%s' % s for s in
-                        ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
-                       + ['--exclude-per-directory=.gitignore']
-                       + ['--exclude-from=%s' % fn for fn in exclude_files()
-                          if os.path.exists(fn)])
-        lines = GRun('git-ls-files', '--others', '--directory', *exclude
-                     ).output_lines()
+        cmd = ['git-ls-files', '-z', '--others', '--directory']
+        if not noexclude:
+            cmd += ['--exclude=%s' % s for s in
+                    ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
+            cmd += ['--exclude-per-directory=.gitignore']
+            cmd += ['--exclude-from=%s' % fn
+                    for fn in exclude_files()
+                    if os.path.exists(fn)]
+
+        lines = GRun(*cmd).raw_output().split('\0')
         cache_files += [('?', line) for line in lines]
 
     # conflicted files