[meld] Uniformize status maps the same way between all VC plugins using one:



commit 96731b836f150db4ce89b69ef96617f9490e2343
Author: Vincent Legoll <vincent legoll gmail com>
Date:   Wed Apr 22 01:21:07 2009 +0200

    Uniformize status maps the same way between all VC plugins using one:
    - Same name "state_map" (monotone has 2 of those)
    - Member of the Vc class
---
 vc/bzr.py       |   21 ++++---
 vc/darcs.py     |   17 +++---
 vc/git.py       |   17 +++---
 vc/mercurial.py |   19 +++---
 vc/monotone.py  |  164 +++++++++++++++++++++++++++---------------------------
 vc/svn.py       |   18 +++---
 vc/tla.py       |   31 +++++-----
 7 files changed, 144 insertions(+), 143 deletions(-)

diff --git a/vc/bzr.py b/vc/bzr.py
index d02ae7b..4a043cf 100644
--- a/vc/bzr.py
+++ b/vc/bzr.py
@@ -32,6 +32,15 @@ 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,
+    }
 
     def commit_command(self, message):
         return [self.CMD,"commit","-m",message]
@@ -58,20 +67,12 @@ class Vc(_vc.CachedVc):
             except OSError, e:
                 if e.errno != errno.EAGAIN:
                     raise
-        statemap = {
-            "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 }
         tree_state = {}
         for entry in entries:
             if entry == "pending merges:":
                 break
-            if entry in statemap:
-                cur_state = statemap[entry]
+            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
diff --git a/vc/darcs.py b/vc/darcs.py
index cd48ed3..807ccf3 100644
--- a/vc/darcs.py
+++ b/vc/darcs.py
@@ -25,14 +25,6 @@ import os
 import errno
 import _vc
 
-STATES = {
-    "a": _vc.STATE_NONE,
-    "A": _vc.STATE_NEW,
-    "M": _vc.STATE_MODIFIED,
-    "C": _vc.STATE_CONFLICT,
-    "R": _vc.STATE_REMOVED
-}
-
 class Vc(_vc.CachedVc):
 
     CMD = "darcs"
@@ -40,6 +32,13 @@ class Vc(_vc.CachedVc):
     VC_DIR = "_darcs"
     PATCH_STRIP_NUM = 1
     PATCH_INDEX_RE = "--- old.+?/(.+?)\\t+.*[0-9]{4}$"
+    state_map = {
+        "a": _vc.STATE_NONE,
+        "A": _vc.STATE_NEW,
+        "M": _vc.STATE_MODIFIED,
+        "C": _vc.STATE_CONFLICT,
+        "R": _vc.STATE_REMOVED,
+    }
 
     def commit_command(self, message):
         return [self.CMD, "record",
@@ -104,7 +103,7 @@ class Vc(_vc.CachedVc):
                     status = _vc.STATE_NEW
                     filename = elements.pop()
                 else:
-                    status = STATES[elements.pop(0)]
+                    status = self.state_map[elements.pop(0)]
                     filename = elements.pop(0)
                 filepath = os.path.join(self.root,
                                         os.path.normpath(filename))
diff --git a/vc/git.py b/vc/git.py
index f5c42f3..17c1682 100644
--- a/vc/git.py
+++ b/vc/git.py
@@ -38,6 +38,14 @@ class Vc(_vc.CachedVc):
     VC_DIR = ".git"
     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_NORMAL,
+        "unmerged":   _vc.STATE_CONFLICT,
+    }
 
     def commit_command(self, message):
         return [self.CMD,"commit","-m",message]
@@ -66,13 +74,6 @@ class Vc(_vc.CachedVc):
             except OSError, e:
                 if e.errno != errno.EAGAIN:
                     raise
-        statemap = {
-            "unknown": _vc.STATE_NONE,
-            "new file": _vc.STATE_NEW,
-            "deleted": _vc.STATE_REMOVED,
-            "modified": _vc.STATE_MODIFIED,
-            "typechange": _vc.STATE_NORMAL,
-            "unmerged": _vc.STATE_CONFLICT }
         tree_state = {}
         for entry in entries:
             if not entry.startswith("#\t"):
@@ -91,7 +92,7 @@ class Vc(_vc.CachedVc):
                     src, dst = name.split(" -> ", 2)
                 except ValueError:
                     path = os.path.join(self.root, name.strip())
-                    state = statemap.get(statekey, _vc.STATE_NONE)
+                    state = self.state_map.get(statekey, _vc.STATE_NONE)
                     tree_state[path] = state
                 else:
                     # copied, renamed
diff --git a/vc/mercurial.py b/vc/mercurial.py
index 403af80..157afe0 100644
--- a/vc/mercurial.py
+++ b/vc/mercurial.py
@@ -34,6 +34,15 @@ class Vc(_vc.Vc):
     # Mercurial diffs can be run in "git" mode
     PATCH_INDEX_RE = "^diff (?:-r \w+ |--git a/.* b/)(.*)$"
     DIFF_GIT_MODE = False
+    state_map = {
+        "?": _vc.STATE_NONE,
+        "A": _vc.STATE_NEW,
+        "C": _vc.STATE_NORMAL,
+        "!": _vc.STATE_MISSING,
+        "I": _vc.STATE_IGNORED,
+        "M": _vc.STATE_MODIFIED,
+        "R": _vc.STATE_REMOVED,
+    }
 
     def commit_command(self, message):
         return [self.CMD,"commit","-m",message]
@@ -65,19 +74,11 @@ class Vc(_vc.Vc):
 
         retfiles = []
         retdirs = []
-        statemap = {
-            "?": _vc.STATE_NONE,
-            "A": _vc.STATE_NEW,
-            "C": _vc.STATE_NORMAL,
-            "!": _vc.STATE_MISSING,
-            "I": _vc.STATE_IGNORED,
-            "M": _vc.STATE_MODIFIED,
-            "R": _vc.STATE_REMOVED }
         hgfiles = {}
         for statekey, name in [ (entry[0], entry[2:]) for entry in entries if entry.find("/")==-1 ]:
             path = os.path.join(directory, name)
             rev, options, tag = "","",""
-            state = statemap.get(statekey, _vc.STATE_NONE)
+            state = self.state_map.get(statekey, _vc.STATE_NONE)
             retfiles.append( _vc.File(path, name, state, rev, tag, options) )
             hgfiles[name] = 1
         for f,path in files:
diff --git a/vc/monotone.py b/vc/monotone.py
index 9e1e5f2..0825917 100644
--- a/vc/monotone.py
+++ b/vc/monotone.py
@@ -31,6 +31,84 @@ class Vc(_vc.CachedVc):
     VC_METADATA = ['MT', '_MTN']
     PATCH_INDEX_RE = "^[+]{3,3} ([^  ]*)\t[0-9a-f]{40,40}$"
 
+    state_map_6 = {
+        'added known rename_source'         : _vc.STATE_NEW,
+        'added known'                       : _vc.STATE_NEW,
+        'added missing'                     : _vc.STATE_EMPTY,
+        'dropped'                           : _vc.STATE_REMOVED,
+        'dropped unknown'                   : _vc.STATE_REMOVED,
+        'known'                             : _vc.STATE_NORMAL,
+        'known rename_target'               : _vc.STATE_MODIFIED,
+        'missing'                           : _vc.STATE_MISSING,
+        'missing rename_target'             : _vc.STATE_MISSING,
+        'ignored'                           : _vc.STATE_IGNORED,
+        'unknown'                           : _vc.STATE_NONE,
+        'rename_source'                     : _vc.STATE_NONE, # the rename target is what we now care about
+        'rename_source unknown'             : _vc.STATE_NONE,
+        'known rename_target'               : _vc.STATE_MODIFIED,
+        'known rename_source rename_target' : _vc.STATE_MODIFIED,
+    }
+
+    state_map_old = {
+        '   ' : _vc.STATE_NORMAL,   # unchanged
+        '  P' : _vc.STATE_MODIFIED, # patched (contents changed)
+        '  U' : _vc.STATE_NONE,     # unknown (exists on the filesystem but not tracked)
+        '  I' : _vc.STATE_IGNORED,  # ignored (exists on the filesystem but excluded by lua hook)
+        '  M' : _vc.STATE_MISSING,  # missing (exists in the manifest but not on the filesystem)
+
+        # Added files are not consistantly handled by all releases:
+        #   0.28: although documented as invalid added files are tagged ' A '.
+        #   0.26, 0.27: ???
+        #   0.25: added files are tagged ' AP'.
+        ' A ' : _vc.STATE_NEW,      # added (invalid, add should have associated patch)
+        ' AP' : _vc.STATE_NEW,      # added and patched
+        ' AU' : _vc.STATE_ERROR,    # added but unknown (invalid)
+        ' AI' : _vc.STATE_ERROR,    # added but ignored (seems invalid, but may be possible)
+        ' AM' : _vc.STATE_EMPTY,    # added but missing from the filesystem
+
+        ' R ' : _vc.STATE_NORMAL,   # rename target
+        ' RP' : _vc.STATE_MODIFIED, # rename target and patched
+        ' RU' : _vc.STATE_ERROR,    # rename target but unknown (invalid)
+        ' RI' : _vc.STATE_ERROR,    # rename target but ignored (seems invalid, but may be possible?)
+        ' RM' : _vc.STATE_MISSING,  # rename target but missing from the filesystem
+
+        'D  ' : _vc.STATE_REMOVED,  # dropped
+        'D P' : _vc.STATE_ERROR,    # dropped and patched (invalid)
+        'D U' : _vc.STATE_REMOVED,  # dropped and unknown (still exists on the filesystem)
+        'D I' : _vc.STATE_ERROR,    # dropped and ignored (seems invalid, but may be possible?)
+        'D M' : _vc.STATE_ERROR,    # dropped and missing (invalid)
+
+        'DA ' : _vc.STATE_ERROR,    # dropped and added (invalid, add should have associated patch)
+        'DAP' : _vc.STATE_NEW,      # dropped and added and patched
+        'DAU' : _vc.STATE_ERROR,    # dropped and added but unknown (invalid)
+        'DAI' : _vc.STATE_ERROR,    # dropped and added but ignored (seems invalid, but may be possible?)
+        'DAM' : _vc.STATE_MISSING,  # dropped and added but missing from the filesystem
+
+        'DR ' : _vc.STATE_NORMAL,   # dropped and rename target
+        'DRP' : _vc.STATE_MODIFIED, # dropped and rename target and patched
+        'DRU' : _vc.STATE_ERROR,    # dropped and rename target but unknown (invalid)
+        'DRI' : _vc.STATE_ERROR,    # dropped and rename target but ignored (invalid)
+        'DRM' : _vc.STATE_MISSING,  # dropped and rename target but missing from the filesystem
+
+        'R  ' : _vc.STATE_REMOVED,  # rename source
+        'R P' : _vc.STATE_ERROR,    # rename source and patched (invalid)
+        'R U' : _vc.STATE_REMOVED,  # rename source and unknown (still exists on the filesystem)
+        'R I' : _vc.STATE_ERROR,    # rename source and ignored (seems invalid, but may be possible?)
+        'R M' : _vc.STATE_ERROR,    # rename source and missing (invalid)
+
+        'RA ' : _vc.STATE_ERROR,    # rename source and added (invalid, add should have associated patch)
+        'RAP' : _vc.STATE_NEW,      # rename source and added and patched
+        'RAU' : _vc.STATE_ERROR,    # rename source and added but unknown (invalid)
+        'RAI' : _vc.STATE_ERROR,    # rename source and added but ignored (seems invalid, but may be possible?)
+        'RAM' : _vc.STATE_MISSING,  # rename source and added but missing from the filesystem
+
+        'RR ' : _vc.STATE_NEW,      # rename source and target
+        'RRP' : _vc.STATE_MODIFIED, # rename source and target and target patched
+        'RRU' : _vc.STATE_ERROR,    # rename source and target and target unknown (invalid)
+        'RRI' : _vc.STATE_ERROR,    # rename source and target and target ignored (seems invalid, but may be possible?)
+        'RRM' : _vc.STATE_MISSING,  # rename source and target and target missing
+    }
+
     def __init__(self, location):
         self.interface_version = 0.0
         self.choose_monotone_version()
@@ -80,24 +158,6 @@ class Vc(_vc.CachedVc):
         if self.interface_version >= 6.0:
             # this version of monotone uses the new inventory format
 
-            statemap = {
-                'added known rename_source' : _vc.STATE_NEW,
-                'added known' : _vc.STATE_NEW,
-                'added missing' : _vc.STATE_EMPTY,
-                'dropped' : _vc.STATE_REMOVED,
-                'dropped unknown' : _vc.STATE_REMOVED,
-                'known' : _vc.STATE_NORMAL,
-                'known rename_target' : _vc.STATE_MODIFIED,
-                'missing' : _vc.STATE_MISSING,
-                'missing rename_target' : _vc.STATE_MISSING,
-                'ignored' : _vc.STATE_IGNORED,
-                'unknown' : _vc.STATE_NONE,
-                'rename_source' : _vc.STATE_NONE, # the rename target is what we now care about
-                'rename_source unknown' : _vc.STATE_NONE,
-                'known rename_target' : _vc.STATE_MODIFIED,
-                'known rename_source rename_target' : _vc.STATE_MODIFIED,
-            }
-
             # terminate the final stanza. basic io stanzas are blank line seperated with no
             # blank line at the beginning or end (and we need to loop below to act upon the
             # final stanza
@@ -124,11 +184,11 @@ class Vc(_vc.CachedVc):
                     mstate.sort()
                     mstate = ' '.join(mstate)
 
-                    if mstate in statemap:
+                    if mstate in self.state_map_6:
                         if 'changes' in stanza:
                             state = _vc.STATE_MODIFIED
                         else:
-                            state = statemap[mstate]
+                            state = self.state_map_6[mstate]
                             if state == _vc.STATE_ERROR:
                                 print "WARNING: invalid state ('%s') reported by 'automate inventory' for %s" % (mstate, fname)
                     else:
@@ -143,73 +203,13 @@ class Vc(_vc.CachedVc):
 
             return tree_state
 
-        statemap = {
-            '   ' : _vc.STATE_NORMAL,   # unchanged
-            '  P' : _vc.STATE_MODIFIED, # patched (contents changed)
-            '  U' : _vc.STATE_NONE,     # unknown (exists on the filesystem but not tracked)
-            '  I' : _vc.STATE_IGNORED,  # ignored (exists on the filesystem but excluded by lua hook)
-            '  M' : _vc.STATE_MISSING,  # missing (exists in the manifest but not on the filesystem)
-
-            # Added files are not consistantly handled by all releases:
-            #   0.28: although documented as invalid added files are tagged ' A '.
-            #   0.26, 0.27: ???
-            #   0.25: added files are tagged ' AP'.
-            ' A ' : _vc.STATE_NEW,      # added (invalid, add should have associated patch)
-            ' AP' : _vc.STATE_NEW,      # added and patched
-            ' AU' : _vc.STATE_ERROR,    # added but unknown (invalid)
-            ' AI' : _vc.STATE_ERROR,    # added but ignored (seems invalid, but may be possible)
-            ' AM' : _vc.STATE_EMPTY,    # added but missing from the filesystem
-
-            ' R ' : _vc.STATE_NORMAL,   # rename target
-            ' RP' : _vc.STATE_MODIFIED, # rename target and patched
-            ' RU' : _vc.STATE_ERROR,    # rename target but unknown (invalid)
-            ' RI' : _vc.STATE_ERROR,    # rename target but ignored (seems invalid, but may be possible?)
-            ' RM' : _vc.STATE_MISSING,  # rename target but missing from the filesystem
-
-            'D  ' : _vc.STATE_REMOVED,  # dropped
-            'D P' : _vc.STATE_ERROR,    # dropped and patched (invalid)
-            'D U' : _vc.STATE_REMOVED,  # dropped and unknown (still exists on the filesystem)
-            'D I' : _vc.STATE_ERROR,    # dropped and ignored (seems invalid, but may be possible?)
-            'D M' : _vc.STATE_ERROR,    # dropped and missing (invalid)
-
-            'DA ' : _vc.STATE_ERROR,    # dropped and added (invalid, add should have associated patch)
-            'DAP' : _vc.STATE_NEW,      # dropped and added and patched
-            'DAU' : _vc.STATE_ERROR,    # dropped and added but unknown (invalid)
-            'DAI' : _vc.STATE_ERROR,    # dropped and added but ignored (seems invalid, but may be possible?)
-            'DAM' : _vc.STATE_MISSING,  # dropped and added but missing from the filesystem
-
-            'DR ' : _vc.STATE_NORMAL,   # dropped and rename target
-            'DRP' : _vc.STATE_MODIFIED, # dropped and rename target and patched
-            'DRU' : _vc.STATE_ERROR,    # dropped and rename target but unknown (invalid)
-            'DRI' : _vc.STATE_ERROR,    # dropped and rename target but ignored (invalid)
-            'DRM' : _vc.STATE_MISSING,  # dropped and rename target but missing from the filesystem
-
-            'R  ' : _vc.STATE_REMOVED,  # rename source
-            'R P' : _vc.STATE_ERROR,    # rename source and patched (invalid)
-            'R U' : _vc.STATE_REMOVED,  # rename source and unknown (still exists on the filesystem)
-            'R I' : _vc.STATE_ERROR,    # rename source and ignored (seems invalid, but may be possible?)
-            'R M' : _vc.STATE_ERROR,    # rename source and missing (invalid)
-
-            'RA ' : _vc.STATE_ERROR,    # rename source and added (invalid, add should have associated patch)
-            'RAP' : _vc.STATE_NEW,      # rename source and added and patched
-            'RAU' : _vc.STATE_ERROR,    # rename source and added but unknown (invalid)
-            'RAI' : _vc.STATE_ERROR,    # rename source and added but ignored (seems invalid, but may be possible?)
-            'RAM' : _vc.STATE_MISSING,  # rename source and added but missing from the filesystem
-
-            'RR ' : _vc.STATE_NEW,      # rename source and target
-            'RRP' : _vc.STATE_MODIFIED, # rename source and target and target patched
-            'RRU' : _vc.STATE_ERROR,    # rename source and target and target unknown (invalid)
-            'RRI' : _vc.STATE_ERROR,    # rename source and target and target ignored (seems invalid, but may be possible?)
-            'RRM' : _vc.STATE_MISSING   # rename source and target and target missing
-        }
-
         tree_state = {}
         for entry in entries:
             mstate = entry[0:3]
             fname = entry[8:]
 
-            if mstate in statemap:
-                state = statemap[mstate]
+            if mstate in self.state_map_old:
+                state = self.state_map_old[mstate]
                 if state == _vc.STATE_ERROR:
                     print "WARNING: invalid state ('%s') reported by 'automate inventory'" % mstate
             else:
diff --git a/vc/svn.py b/vc/svn.py
index 6d41847..0e9b6dc 100644
--- a/vc/svn.py
+++ b/vc/svn.py
@@ -34,15 +34,15 @@ class Vc(_vc.Vc):
     VC_ROOT_WALK = False
     PATCH_INDEX_RE = "^Index:(.*)$"
     state_map = {
-                 "?": _vc.STATE_NONE,
-                 "A": _vc.STATE_NEW,
-                 " ": _vc.STATE_NORMAL,
-                 "!": _vc.STATE_MISSING,
-                 "I": _vc.STATE_IGNORED,
-                 "M": _vc.STATE_MODIFIED,
-                 "D": _vc.STATE_REMOVED,
-                 "C": _vc.STATE_CONFLICT,
-                 }
+        "?": _vc.STATE_NONE,
+        "A": _vc.STATE_NEW,
+        " ": _vc.STATE_NORMAL,
+        "!": _vc.STATE_MISSING,
+        "I": _vc.STATE_IGNORED,
+        "M": _vc.STATE_MODIFIED,
+        "D": _vc.STATE_REMOVED,
+        "C": _vc.STATE_CONFLICT,
+    }
 
     def commit_command(self, message):
         return [self.CMD,"commit","-m",message]
diff --git a/vc/tla.py b/vc/tla.py
index 911c9c8..0a0b09d 100644
--- a/vc/tla.py
+++ b/vc/tla.py
@@ -42,21 +42,6 @@ import _vc
 # lf   link replaced by file
 # ->   link target changed
 
-STATES = {
-    "a": _vc.STATE_NONE,
-    "A": _vc.STATE_NEW,
-    "M": _vc.STATE_MODIFIED,
-    "C": _vc.STATE_CONFLICT,
-    "D": _vc.STATE_REMOVED,
-    "--": _vc.STATE_MODIFIED,
-    "=>": _vc.STATE_REMOVED,
-    "->": _vc.STATE_MODIFIED,
-    "A/": _vc.STATE_NEW,
-    "D/": _vc.STATE_REMOVED,
-    "/>": _vc.STATE_REMOVED,
-    "-/": _vc.STATE_MODIFIED,
-}
-
 class Vc(_vc.CachedVc):
 
     CMD = "tla"
@@ -65,6 +50,20 @@ class Vc(_vc.CachedVc):
     VC_METADATA = ['.arch-ids', '.arch-inventory']
     PATCH_STRIP_NUM = 1
     PATCH_INDEX_RE = "--- orig/(.*)"
+    state_map = {
+        "a":  _vc.STATE_NONE,
+        "A":  _vc.STATE_NEW,
+        "M":  _vc.STATE_MODIFIED,
+        "C":  _vc.STATE_CONFLICT,
+        "D":  _vc.STATE_REMOVED,
+        "--": _vc.STATE_MODIFIED,
+        "=>": _vc.STATE_REMOVED,
+        "->": _vc.STATE_MODIFIED,
+        "A/": _vc.STATE_NEW,
+        "D/": _vc.STATE_REMOVED,
+        "/>": _vc.STATE_REMOVED,
+        "-/": _vc.STATE_MODIFIED,
+    }
 
     def commit_command(self, message):
         return [self.CMD, "commit",
@@ -110,7 +109,7 @@ class Vc(_vc.CachedVc):
                 continue
             elements = line.split()
             if len(elements) > 1:
-                status = STATES[elements.pop(0)]
+                status = self.state_map[elements.pop(0)]
                 filename = elements.pop(0)
                 filepath = os.path.join(self.root,
                                     os.path.normpath(filename))



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