[Zodb-checkins] CVS: Packages/bsddb3Storage - Full.py:1.24

barry@digicool.com barry@digicool.com
Thu, 14 Jun 2001 14:47:47 -0400 (EDT)


Update of /cvs-repository/Packages/bsddb3Storage/bsddb3Storage
In directory korak.digicool.com:/tmp/cvs-serv25475

Modified Files:
	Full.py 
Log Message:
Add a real (and tested!) implementation of the history() method.



--- Updated File Full.py in package Packages/bsddb3Storage --
--- Full.py	2001/04/28 05:50:26	1.23
+++ Full.py	2001/06/14 18:47:46	1.24
@@ -832,12 +832,58 @@
                 c.close()
             self._lock_release()
 
-    def history(self, oid, version=None, length=1, filter=None):
-        # FIXME
+    def history(self, oid, version=None, size=1, filter=None):
         self._lock_acquire()
         try:
-            tid=self._current[oid]
-        finally: self._lock_release()
+            # Find the vid for the version
+            if version is None:
+                tvid = None
+                version = ''
+            elif version == '':
+                tvid = 0
+            else:
+                # BAW: for now, let KeyErrors percolate up
+                tvid = self._vids[version]
+            # Start with the most recent revision of the object, then search
+            # the transaction records backwards finding revisions in the
+            # selected version.
+            history = []
+            revid = self._serials[oid]
+            # BAW: Again, let KeyErrors percolate up
+            while len(history) < size:
+                vid, nvrevid, lrevid, previd = struct.unpack(
+                    '>8s8s8s8s', self._metadata[oid+revid])
+                if tvid is None or vid == ZERO or tvid == vid:
+                    # Get transaction metadata, which we need to fill in the
+                    # appropriate HistoryEntry slots.
+                    txnmeta = self._txnMetadata[revid]
+                    userlen, desclen = struct.unpack('>II', txnmeta[1:9])
+                    user = txnmeta[9:9+userlen]
+                    desc = txnmeta[9+userlen:9+userlen+desclen]
+                    # Now get the pickle size
+                    data = self._pickles[oid+lrevid]
+                    # Create a HistoryEntry structure, which turns out to be a
+                    # dictionary with some specifically named entries (BAW:
+                    # although this poorly documented).
+                    if vid == ZERO:
+                        retvers = ''
+                    else:
+                        retvers = version
+                    d = {'time'       : TimeStamp(revid).timeTime(),
+                         'user_name'  : user,
+                         'description': desc,
+                         'serial'     : revid,
+                         'version'    : retvers,
+                         'size'       : len(data),
+                         }
+                    if filter is None or filter(d):
+                        history.append(d)
+                if previd == ZERO:
+                    break
+                revid = previd
+            return history
+        finally:
+            self._lock_release()
 
     def _zaprevision(self, key, referencesf):
         # Delete the metadata record pointed to by the key, decrefing the



--- Updated File Full.py in package Packages/bsddb3Storage --
--- Full.py	2001/04/28 05:50:26	1.23
+++ Full.py	2001/06/14 18:47:46	1.24
@@ -832,12 +832,58 @@
                 c.close()
             self._lock_release()
 
-    def history(self, oid, version=None, length=1, filter=None):
-        # FIXME
+    def history(self, oid, version=None, size=1, filter=None):
         self._lock_acquire()
         try:
-            tid=self._current[oid]
-        finally: self._lock_release()
+            # Find the vid for the version
+            if version is None:
+                tvid = None
+                version = ''
+            elif version == '':
+                tvid = 0
+            else:
+                # BAW: for now, let KeyErrors percolate up
+                tvid = self._vids[version]
+            # Start with the most recent revision of the object, then search
+            # the transaction records backwards finding revisions in the
+            # selected version.
+            history = []
+            revid = self._serials[oid]
+            # BAW: Again, let KeyErrors percolate up
+            while len(history) < size:
+                vid, nvrevid, lrevid, previd = struct.unpack(
+                    '>8s8s8s8s', self._metadata[oid+revid])
+                if tvid is None or vid == ZERO or tvid == vid:
+                    # Get transaction metadata, which we need to fill in the
+                    # appropriate HistoryEntry slots.
+                    txnmeta = self._txnMetadata[revid]
+                    userlen, desclen = struct.unpack('>II', txnmeta[1:9])
+                    user = txnmeta[9:9+userlen]
+                    desc = txnmeta[9+userlen:9+userlen+desclen]
+                    # Now get the pickle size
+                    data = self._pickles[oid+lrevid]
+                    # Create a HistoryEntry structure, which turns out to be a
+                    # dictionary with some specifically named entries (BAW:
+                    # although this poorly documented).
+                    if vid == ZERO:
+                        retvers = ''
+                    else:
+                        retvers = version
+                    d = {'time'       : TimeStamp(revid).timeTime(),
+                         'user_name'  : user,
+                         'description': desc,
+                         'serial'     : revid,
+                         'version'    : retvers,
+                         'size'       : len(data),
+                         }
+                    if filter is None or filter(d):
+                        history.append(d)
+                if previd == ZERO:
+                    break
+                revid = previd
+            return history
+        finally:
+            self._lock_release()
 
     def _zaprevision(self, key, referencesf):
         # Delete the metadata record pointed to by the key, decrefing the