git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "David Kågedal" <davidk@lysator.liu.se>
To: git@vger.kernel.org, catalin.marinas@gmail.com
Subject: [StGit PATCH 02/13] Clear up semantics of tree_status
Date: Sat, 15 Sep 2007 00:31:19 +0200	[thread overview]
Message-ID: <20070914223119.7001.23842.stgit@morpheus.local> (raw)
In-Reply-To: <20070914222819.7001.55921.stgit@morpheus.local>

The tree_status() function does a few slightly different things
depending on the arguments.  This patch adds checks that the arguments
are consistent and that the returned value looks good.

It also changes the semantics slightly.  If the 'files' parameter is
None, it will run status on all files.  If 'files' is a list, it will
run status on only those files.  This changes two things:

 1) If 'files' is the empty list, it will run status on no files.
 2) It 'files' is a list, it will never return the status for other files

Clearing this up will make it easier to understand code that is using
this function.

Signed-off-by: David Kågedal <davidk@lysator.liu.se>
---

 stgit/commands/status.py |    3 +++
 stgit/git.py             |   44 +++++++++++++++++++++++---------------------
 2 files changed, 26 insertions(+), 21 deletions(-)


diff --git a/stgit/commands/status.py b/stgit/commands/status.py
index 156552b..de88ba0 100644
--- a/stgit/commands/status.py
+++ b/stgit/commands/status.py
@@ -82,6 +82,9 @@ def func(parser, options, args):
         else:
             diff_flags = []
 
+        # No args means all files
+        if not args:
+            args = None
         git.status(args, options.modified, options.new, options.deleted,
                    options.conflict, options.unknown, options.noexclude,
                    diff_flags = diff_flags)
diff --git a/stgit/git.py b/stgit/git.py
index 539d699..8dda1ed 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -167,15 +167,20 @@ 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)
+    """Get the status of all changed files, or of a selected set of
+    files. Returns a list of pairs - (status, filename).
+
+    If 'files' is None, it will check all files, and optionally all
+    unknown files.  If 'files' is a list, it will only check the files
+    in the list.
     """
+    assert files == None or not unknown
+
     if verbose:
         out.start('Checking for changes in the working directory')
 
     refresh_index()
 
-    if not files:
-        files = []
     cache_files = []
 
     # unknown files
@@ -197,11 +202,14 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
     conflicts = get_conflicts()
     if not conflicts:
         conflicts = []
-    cache_files += [('C', filename) for filename in conflicts]
+    cache_files += [('C', filename) for filename in conflicts
+                    if files == None or filename in files]
 
     # the rest
-    for line in GRun('git-diff-index', *(diff_flags + [tree_id, '--'] + files)
-                     ).output_lines():
+    args = diff_flags + [tree_id]
+    if files != None:
+        args += ['--'] + files
+    for line in GRun('git-diff-index', *args).output_lines():
         fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
         if fs[1] not in conflicts:
             cache_files.append(fs)
@@ -209,6 +217,7 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
     if verbose:
         out.done()
 
+    assert files == None or set(f for s,f in cache_files) <= set(files)
     return cache_files
 
 def local_changes(verbose = True):
@@ -538,9 +547,6 @@ def committer():
 def update_cache(files = None, force = False):
     """Update the cache information for the given files
     """
-    if not files:
-        files = []
-
     cache_files = tree_status(files, verbose = False)
 
     # everything is up-to-date
@@ -569,8 +575,6 @@ def commit(message, files = None, parents = None, allowempty = False,
            committer_name = None, committer_email = None):
     """Commit the current tree to repository
     """
-    if not files:
-        files = []
     if not parents:
         parents = []
 
@@ -712,14 +716,13 @@ def status(files = None, modified = False, new = False, deleted = False,
            diff_flags = []):
     """Show the tree status
     """
-    if not files:
-        files = []
-
-    cache_files = tree_status(files, unknown = True, noexclude = noexclude,
-                                diff_flags = diff_flags)
-    all = not (modified or new or deleted or conflict or unknown)
+    cache_files = tree_status(files,
+                              unknown = (files == None),
+                              noexclude = noexclude,
+                              diff_flags = diff_flags)
+    filtered = (modified or new or deleted or conflict or unknown)
 
-    if not all:
+    if filtered:
         filestat = []
         if modified:
             filestat.append('M')
@@ -735,9 +738,8 @@ def status(files = None, modified = False, new = False, deleted = False,
         cache_files = [x for x in cache_files if x[0] in filestat]
 
     for fs in cache_files:
-        if files and not fs[1] in files:
-            continue
-        if all:
+        assert files == None or fs[1] in files
+        if not filtered:
             out.stdout('%s %s' % (fs[0], fs[1]))
         else:
             out.stdout('%s' % fs[1])

  parent reply	other threads:[~2007-09-14 22:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-14 22:31 [StGit PATCH 00/13] Eliminate 'top' and 'bottom' files David Kågedal
2007-09-14 22:31 ` [StGit PATCH 01/13] Add some more tests of "stg status" output David Kågedal
2007-09-14 22:31 ` David Kågedal [this message]
2007-09-14 22:31 ` [StGit PATCH 03/13] Moved that status function to the status command file David Kågedal
2007-09-14 22:36   ` David Kågedal
2007-09-14 22:31 ` [StGit PATCH 04/13] Split Series.push_patch in two David Kågedal
2007-09-14 22:31 ` [StGit PATCH 05/13] Remove dead code from push_empty_patch David Kågedal
2007-09-14 22:31 ` [StGit PATCH 06/13] Refactor Series.push_patch David Kågedal
2007-09-14 22:31 ` [StGit PATCH 07/13] Clean up Series.refresh_patch David Kågedal
2007-09-14 22:31 ` [StGit PATCH 08/13] Add a 'bottom' parameter to Series.refresh_patch and use it David Kågedal
2007-09-14 22:31 ` [StGit PATCH 09/13] Clear up the semantics of Series.new_patch David Kågedal
2007-10-08 13:16   ` Catalin Marinas
2007-10-08 13:25     ` Karl Hasselström
2007-10-09 21:01       ` Catalin Marinas
2007-10-10  7:43         ` David Kågedal
2007-10-11 20:42           ` Catalin Marinas
2007-10-10  7:45         ` Karl Hasselström
2007-10-10  8:15           ` Karl Hasselström
2007-09-14 22:32 ` [StGit PATCH 10/13] Refactor Series.new_patch David Kågedal
2007-09-14 22:32 ` [StGit PATCH 11/13] Check bottom and invariants David Kågedal
2007-09-14 22:32 ` [StGit PATCH 12/13] Remove the 'bottom' field David Kågedal
2007-09-14 22:32 ` [StGit PATCH 13/13] Remove the 'top' field David Kågedal
2007-09-15 23:36   ` Karl Hasselström
2007-09-16 10:22     ` David Kågedal
2007-09-17  7:30       ` Karl Hasselström
2007-09-15 23:42 ` [StGit PATCH 00/13] Eliminate 'top' and 'bottom' files Karl Hasselström
2007-09-16  7:28   ` Catalin Marinas
2007-09-16 10:28     ` David Kågedal
2007-09-17  8:17     ` Karl Hasselström
2007-09-16 10:25   ` David Kågedal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070914223119.7001.23842.stgit@morpheus.local \
    --to=davidk@lysator.liu.se \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).