[meld] Use bzr 'short' status for more robust parsing (closes bgo#348722)



commit 7452da2ce84775e261229b9fa03598934d36f21f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Aug 29 08:28:00 2010 +1000

    Use bzr 'short' status for more robust parsing (closes bgo#348722)
    
    bzr's 'short' version of the status command is easier to parse reliably
    than the default version, and lets us easily ignore status changes that
    we don't yet support.
    
    For a list of possible status flags, see:
    http://doc.bazaar.canonical.com/latest/en/user-reference/
    status-flags-help.html

 meld/vc/bzr.py |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/meld/vc/bzr.py b/meld/vc/bzr.py
index 3ad7720..777a74f 100644
--- a/meld/vc/bzr.py
+++ b/meld/vc/bzr.py
@@ -33,14 +33,23 @@ class Vc(_vc.CachedVc):
     NAME = "Bazaar-NG"
     VC_DIR = ".bzr"
     PATCH_INDEX_RE = "^=== modified file '(.*)'$"
-    state_map = {
-        "unknown:":   _vc.STATE_NONE,
-        "added:":     _vc.STATE_NEW,
-        "unchanged:": _vc.STATE_NORMAL,
-        "removed:":   _vc.STATE_REMOVED,
-        "ignored:":   _vc.STATE_IGNORED,
-        "modified:":  _vc.STATE_MODIFIED,
-        "conflicts:": _vc.STATE_CONFLICT,
+
+    # We use None here to indicate flags that we don't deal with or care about
+    state_1_map = {
+        "+": None,               # File versioned
+        "-": None,               # File unversioned
+        "R": None,               # File renamed
+        "?": _vc.STATE_NONE,     # File unknown
+        "X": None,               # File nonexistent (and unknown to bzr)
+        "C": _vc.STATE_CONFLICT, # File has conflicts
+        "P": None,               # Entry for a pending merge (not a file)
+    }
+
+    state_2_map = {
+        "N": _vc.STATE_NEW,      # File created
+        "D": _vc.STATE_REMOVED,  # File deleted
+        "K": None,               # File kind changed
+        "M": _vc.STATE_MODIFIED, # File modified
     }
 
     def commit_command(self, message):
@@ -69,7 +78,8 @@ class Vc(_vc.CachedVc):
         branch_root = _vc.popen([self.CMD] + self.CMDARGS + ["root", rootdir]).read().rstrip('\n')
         while 1:
             try:
-                proc = _vc.popen([self.CMD] + self.CMDARGS + ["status", branch_root])
+                proc = _vc.popen([self.CMD] + self.CMDARGS +
+                                 ["status", "-S", "--no-pending", branch_root])
                 entries = proc.read().split("\n")[:-1]
                 break
             except OSError, e:
@@ -77,13 +87,15 @@ class Vc(_vc.CachedVc):
                     raise
         tree_state = {}
         for entry in entries:
-            if entry == "pending merges:":
-                break
-            if entry in self.state_map:
-                cur_state = self.state_map[entry]
-            else:
-                if entry.startswith("  "):
-                    tree_state[os.path.join(rootdir, entry[2:])] = cur_state
+            state_string, name = entry[:3], entry[4:]
+
+            # TODO: We don't do anything with exec bit changes.
+            path = os.path.join(branch_root, name.strip())
+            state = self.state_1_map.get(state_string[0], None)
+            if state is None:
+                state = self.state_2_map.get(state_string[1], _vc.STATE_NORMAL)
+            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]