[meld] Add support for Fossil SCM (closes bgo#644811)



commit 4daca9a619a47f9d02177538361febdcdfdd0f8e
Author: Jan Danielsson <jan m danielsson gmail com>
Date:   Sat Mar 19 13:01:20 2011 +1000

    Add support for Fossil SCM (closes bgo#644811)

 meld/vc/fossil.py |  163 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 163 insertions(+), 0 deletions(-)
---
diff --git a/meld/vc/fossil.py b/meld/vc/fossil.py
new file mode 100644
index 0000000..92950f7
--- /dev/null
+++ b/meld/vc/fossil.py
@@ -0,0 +1,163 @@
+### Copyright (C) 2002-2005 Stephen Kennedy <stevek gnome org>
+### Copyright (C) 2005 Daniel Thompson <daniel redfelineninja org uk>
+### Copyright (C) 2011 Jan Danielsson <jan m danielsson gmail com>
+
+### Redistribution and use in source and binary forms, with or without
+### modification, are permitted provided that the following conditions
+### are met:
+###
+### 1. Redistributions of source code must retain the above copyright
+###    notice, this list of conditions and the following disclaimer.
+### 2. Redistributions in binary form must reproduce the above copyright
+###    notice, this list of conditions and the following disclaimer in the
+###    documentation and/or other materials provided with the distribution.
+
+### THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+### IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import _vc
+import errno
+
+
+class Vc(_vc.CachedVc):
+
+    CMD = "fossil"
+    NAME = "Fossil"
+    VC_METADATA = "_FOSSIL_"
+    PATCH_INDEX_RE = "^--- (.*)$"
+
+    state_map = {
+        'ADDED'       : _vc.STATE_NEW,
+        'DELETED'     : _vc.STATE_REMOVED,
+        'UNCHANGED'   : _vc.STATE_NORMAL,
+        'EDITED'      : _vc.STATE_MODIFIED,
+        'MISSING'     : _vc.STATE_MISSING,
+    }
+
+    def commit_command(self, message):
+        return [self.CMD, "commit", "-m", message]
+
+    def diff_command(self):
+        return [self.CMD, "diff"]
+
+    def update_command(self):
+        return [self.CMD, "update"]
+
+    def add_command(self, binary=0):
+        return [self.CMD, "add"]
+
+    def remove_command(self, force=0):
+        return [self.CMD, "rm"]
+
+    def revert_command(self):
+        return [self.CMD, "revert"]
+
+    def valid_repo(self):
+        if _vc.call([self.CMD, "info"]):
+            return False
+        else:
+            return True
+
+    def check_repo_root(self, location):
+        # Fossil uses a file -- not a directory
+        if not os.path.isfile(os.path.join(location, self.VC_METADATA)):
+            raise ValueError
+        return location
+
+    def get_working_directory(self, workdir):
+        return self.root
+
+    def _lookup_tree_cache(self, rootdir):
+        while 1:
+            try:
+                entries = _vc.popen([self.CMD, "ls", "-l"],
+                                    cwd=self.root).read().split("\n")[:-1]
+                break
+            except OSError, e:
+                if e.errno != errno.EAGAIN:
+                    raise
+
+        tree_state = {}
+        for entry in entries:
+            mstate = entry.split(' ', 1)[0]
+            fname = entry.split(' ', 1)[1].strip()
+
+            if mstate in self.state_map:
+                state = self.state_map[mstate]
+                if state == _vc.STATE_ERROR:
+                    print "WARNING: unknown state ('%s') reported by " \
+                            "'ls -l'" % mstate
+            else:
+                state = _vc.STATE_ERROR
+                print "WARNING: unknown state ('%s') reported by 'ls -l' " \
+                        "(version skew?)" % mstate
+
+            tree_state[os.path.join(self.root, fname)] = state
+
+        return tree_state
+
+    def _get_dirsandfiles(self, directory, dirs, files):
+
+        tree = self._get_tree_cache(directory)
+
+        retfiles = []
+        retdirs = []
+        vcfiles = {}
+
+        for path, state in tree.iteritems():
+            mydir, name = os.path.split(path)
+            if path.endswith('/'):
+                mydir, name = os.path.split(mydir)
+            if mydir != directory:
+                continue
+
+            rev = ""
+            while True:
+                try:
+                    entries = _vc.popen([self.CMD, "finfo", "-s", path],
+                                        cwd=self.root).read().split(" ", 1)
+                    # ToDo: Add more relevant entry types
+                    if entries[0] in ['edited', 'deleted']:
+                        rev = entries[1].strip()
+                    break
+                except OSError, e:
+                    if e.errno != errno.EAGAIN:
+                        raise
+
+            options, tag = "", ""
+            if path.endswith('/'):
+                retdirs.append(_vc.Dir(path[:-1], name, state))
+            else:
+                retfiles.append(_vc.File(path, name, state, rev, tag,
+                        options))
+            vcfiles[name] = 1
+
+        for f, path in files:
+            if f not in vcfiles:
+                ignorelist = ['_FOSSIL_', 'manifest', 'manifest.uuid']
+
+                if f not in ignorelist:
+                    print "WARNING: '%s' was not listed by 'ls -l'" % f
+
+                # If it ain't listed by the inventory it's not under version
+                # control
+                state = _vc.STATE_NONE
+                retfiles.append(_vc.File(path, f, state, ""))
+
+        for d, path in dirs:
+            if d not in vcfiles:
+                # Fossil does not version (or inventory) directories so these
+                # are always normal
+                state = _vc.STATE_NORMAL
+                retdirs.append(_vc.Dir(path, d, state))
+
+        return retdirs, retfiles



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