git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 2/2] Cleanup tree_status and use -z

From
David Kågedal <davidk@lysator.liu.se>
Date
Aug 30, 2007, 11:11 UTC
Message-ID
<11884722703840-git-send-email-davidk@lysator.liu.se>
In-Reply-To
<11884722703161-git-send-email-davidk@lysator.liu.se>
From: David KÃ¥gedal <david@virtutech.com>

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>
---
There are still no good test cases for this code, though.
 stgit/commands/patches.py |    2 +-
 stgit/commands/refresh.py |    2 +-
 stgit/git.py              |   22 +++++++++++-----------
 3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/stgit/commands/patches.py b/stgit/commands/patches.py
index b3defb6..fb65b62 100644
--- a/stgit/commands/patches.py
+++ b/stgit/commands/patches.py
@@ -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
 
diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py
index 218075b..f44c58c 100644
--- a/stgit/commands/refresh.py
+++ b/stgit/commands/refresh.py
@@ -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]
 
diff --git a/stgit/git.py b/stgit/git.py
index 7962cdb..f315b05 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -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
-- 
1.5.3.rc6.31.g3c3b
Previous: David KågedalNext: Karl Hasselström
Message 2 of 7 in “Add basic test for stg status”
  1. 1/1 Add basic test for stg statusDavid Kågedal, Aug 30, 2007
  2. 2/2 Cleanup tree_status and use -zDavid Kågedal, Aug 30, 2007
  3. Karl HasselströmAug 30, 2007
  4. David KågedalAug 30, 2007
  5. David KågedalAug 30, 2007
  6. Karl HasselströmAug 30, 2007
  7. David KågedalAug 30, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.