[meld] Update git to use "git diff-index" instead of "git status"



commit 84524f7f2be4722f206e77e3d8fc8acb25de7fea
Author: Peter Tyser <ptyser gmail com>
Date:   Sun Feb 28 14:42:02 2010 -0600

    Update git to use "git diff-index" instead of "git status"
    
    "git status" is a "porcelain" command whose output is shown in a format
    that is easy for a user to digest.  The output formatting can change as
    it is not considered a "plumbing" git command.
    
    By using "git diff-index" instead of "git status" we reduce the chance
    that meld will mis-parse a git tree's current status if/when the output
    of "git status" changes.  Additionally, "git diff-index"'s output is
    much easier to parse which simplifies meld's code a bit.
    
    Lastly, unlike "git status", "git diff-index" can be used to only
    show the changed files in a specific repository location.  "git status"
    is only able to show all changed files in a repository.  This feature
    of "diff-index" will be useful when updating meld to properly parse
    git repositories' sub-directories. (see bug 609025)
    
    Signed-off-by: Peter Tyser <ptyser gmail com>

 meld/vc/git.py |   42 ++++++++++++------------------------------
 1 files changed, 12 insertions(+), 30 deletions(-)
---
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 833b9b2..4067692 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -39,12 +39,12 @@ class Vc(_vc.CachedVc):
     PATCH_STRIP_NUM = 1
     PATCH_INDEX_RE = "^diff --git a/(.*) b/.*$"
     state_map = {
-        "unknown":    _vc.STATE_NONE,
-        "new file":   _vc.STATE_NEW,
-        "deleted":    _vc.STATE_REMOVED,
-        "modified":   _vc.STATE_MODIFIED,
-        "typechange": _vc.STATE_MODIFIED,
-        "unmerged":   _vc.STATE_CONFLICT,
+        "X": _vc.STATE_NONE,     # Unknown
+        "A": _vc.STATE_NEW,      # New
+        "D": _vc.STATE_REMOVED,  # Deleted
+        "M": _vc.STATE_MODIFIED, # Modified
+        "T": _vc.STATE_MODIFIED, # Type-changed
+        "U": _vc.STATE_CONFLICT, # Unmerged
     }
 
     def check_repo_root(self, location):
@@ -74,7 +74,7 @@ class Vc(_vc.CachedVc):
     def _lookup_tree_cache(self, rootdir):
         while 1:
             try:
-                proc = _vc.popen([self.CMD, "status", "--untracked-files"], cwd=self.root)
+                proc = _vc.popen([self.CMD, "diff-index", "--name-status", "HEAD", "./"], cwd=self.root)
                 entries = proc.read().split("\n")[:-1]
                 break
             except OSError, e:
@@ -82,29 +82,11 @@ class Vc(_vc.CachedVc):
                     raise
         tree_state = {}
         for entry in entries:
-            if not entry.startswith("#\t"):
-                continue
-            try:
-                statekey, name = entry[2:].split(":", 2)
-            except ValueError:
-                # untracked
-                name = entry[2:]
-                path = os.path.join(self.root, name.strip())
-                tree_state[path] = _vc.STATE_NONE
-            else:
-                statekey = statekey.strip()
-                name = name.strip()
-                try:
-                    src, dst = name.split(" -> ", 2)
-                except ValueError:
-                    path = os.path.join(self.root, name.strip())
-                    state = self.state_map.get(statekey, _vc.STATE_NONE)
-                    tree_state[path] = state
-                else:
-                    # copied, renamed
-                    if statekey == "renamed":
-                        tree_state[os.path.join(self.root, src)] = _vc.STATE_REMOVED
-                    tree_state[os.path.join(self.root, dst)] = _vc.STATE_NEW
+            statekey, name = entry.split("\t", 2)
+            path = os.path.join(self.root, name.strip())
+            state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
+            tree_state[path] = state
+
         return tree_state
 
     def _get_dirsandfiles(self, directory, dirs, files):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]