Commit 042f0abc authored by Barry Warsaw's avatar Barry Warsaw

Code cleanup.

parent 41409b00
...@@ -18,7 +18,7 @@ See Minimal.py for an implementation of Berkeley storage that does not support ...@@ -18,7 +18,7 @@ See Minimal.py for an implementation of Berkeley storage that does not support
undo or versioning. undo or versioning.
""" """
__version__ = '$Revision: 1.42 $'.split()[-2:][0] __version__ = '$Revision: 1.43 $'.split()[-2:][0]
import sys import sys
import struct import struct
...@@ -463,8 +463,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -463,8 +463,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# We've already dealt with this oid... # We've already dealt with this oid...
continue continue
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid meta = self._metadata[oid+tid]
meta = self._metadata[oid+revid]
curvid, nvrevid = struct.unpack('>8s8s', meta[:16]) curvid, nvrevid = struct.unpack('>8s8s', meta[:16])
# Make sure that the vid in the metadata record is the same as # Make sure that the vid in the metadata record is the same as
# the vid we sucked out of the vids table. # the vid we sucked out of the vids table.
...@@ -484,7 +483,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -484,7 +483,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# Write the object id, live revision id, the current revision # Write the object id, live revision id, the current revision
# id (which serves as the previous revid to this transaction) # id (which serves as the previous revid to this transaction)
# to the commit log. # to the commit log.
self._commitlog.write_nonversion_object(oid, lrevid, revid) self._commitlog.write_nonversion_object(oid, lrevid, tid)
# Remember to return the oid... # Remember to return the oid...
oids[oid] = 1 oids[oid] = 1
# We've now processed all the objects on the discarded version, so # We've now processed all the objects on the discarded version, so
...@@ -534,8 +533,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -534,8 +533,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
if oids.has_key(oid): if oids.has_key(oid):
continue continue
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid meta = self._metadata[oid+tid]
meta = self._metadata[oid+revid]
curvid, nvrevid, lrevid = struct.unpack('>8s8s8s', meta[:24]) curvid, nvrevid, lrevid = struct.unpack('>8s8s8s', meta[:24])
# Our database better be consistent. # Our database better be consistent.
if curvid <> svid: if curvid <> svid:
...@@ -548,7 +546,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -548,7 +546,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
if not dest: if not dest:
nvrevid = ZERO nvrevid = ZERO
self._commitlog.write_moved_object( self._commitlog.write_moved_object(
oid, dvid, nvrevid, lrevid, revid) oid, dvid, nvrevid, lrevid, tid)
# Remember to return the oid... # Remember to return the oid...
oids[oid] = 1 oids[oid] = 1
# Now that we're done, we can discard this version # Now that we're done, we can discard this version
...@@ -567,8 +565,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -567,8 +565,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
try: try:
# Let KeyErrors percolate up # Let KeyErrors percolate up
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid vid = self._metadata[oid+tid][:8]
vid = self._metadata[oid+revid][:8]
if vid == ZERO: if vid == ZERO:
# Not in a version # Not in a version
return '' return ''
...@@ -596,11 +593,10 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -596,11 +593,10 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# Get the current revid for the object. As per the protocol, let # Get the current revid for the object. As per the protocol, let
# any KeyErrors percolate up. # any KeyErrors percolate up.
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid
# Get the metadata associated with this revision of the object. # Get the metadata associated with this revision of the object.
# All we really need is the vid, the non-version revid and the # All we really need is the vid, the non-version revid and the
# pickle pointer revid. # pickle pointer revid.
rec = self._metadata[oid+revid] rec = self._metadata[oid+tid]
vid, nvrevid, lrevid = struct.unpack('>8s8s8s', rec[:24]) vid, nvrevid, lrevid = struct.unpack('>8s8s8s', rec[:24])
if lrevid == DNE: if lrevid == DNE:
raise KeyError, 'Object does not exist' raise KeyError, 'Object does not exist'
...@@ -1060,15 +1056,14 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1060,15 +1056,14 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# the transaction records backwards until we find enough records. # the transaction records backwards until we find enough records.
history = [] history = []
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid
# BAW: Again, let KeyErrors percolate up # BAW: Again, let KeyErrors percolate up
while len(history) < size: while len(history) < size:
# Some information comes out of the revision metadata... # Some information comes out of the revision metadata...
vid, nvrevid, lrevid, previd = struct.unpack( vid, nvrevid, lrevid, previd = struct.unpack(
'>8s8s8s8s', self._metadata[oid+revid]) '>8s8s8s8s', self._metadata[oid+tid])
# ...while other information comes out of the transaction # ...while other information comes out of the transaction
# metadata. # metadata.
txnmeta = self._txnMetadata[revid] txnmeta = self._txnMetadata[tid]
userlen, desclen = struct.unpack('>II', txnmeta[1:9]) userlen, desclen = struct.unpack('>II', txnmeta[1:9])
user = txnmeta[9:9+userlen] user = txnmeta[9:9+userlen]
desc = txnmeta[9+userlen:9+userlen+desclen] desc = txnmeta[9+userlen:9+userlen+desclen]
...@@ -1082,7 +1077,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1082,7 +1077,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
else: else:
retvers = self._versions[vid] retvers = self._versions[vid]
# The HistoryEntry object # The HistoryEntry object
d = {'time' : TimeStamp(revid).timeTime(), d = {'time' : TimeStamp(tid).timeTime(),
'user_name' : user, 'user_name' : user,
'description': desc, 'description': desc,
'serial' : serial, 'serial' : serial,
...@@ -1095,7 +1090,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1095,7 +1090,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# revision, stopping when we've reached the end. # revision, stopping when we've reached the end.
if previd == ZERO: if previd == ZERO:
break break
serial = revid = previd serial = tid = previd
return history return history
finally: finally:
self._lock_release() self._lock_release()
...@@ -1119,12 +1114,11 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1119,12 +1114,11 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
reachables[oid] = 1 reachables[oid] = 1
# Get the pickle data for the object's current version # Get the pickle data for the object's current version
serial, tid = self._getSerialAndTidMissingOk(oid) serial, tid = self._getSerialAndTidMissingOk(oid)
revid = tid if tid is None:
if revid is None:
# BAW: how can this happen?! This means that an object is # BAW: how can this happen?! This means that an object is
# holding references to an object that we know nothing about. # holding references to an object that we know nothing about.
continue continue
lrevid = self._metadata[oid+revid][16:24] lrevid = self._metadata[oid+tid][16:24]
pickle = self._pickles[oid+lrevid] pickle = self._pickles[oid+lrevid]
refdoids = [] refdoids = []
referencesf(pickle, refdoids) referencesf(pickle, refdoids)
......
...@@ -18,7 +18,7 @@ See Minimal.py for an implementation of Berkeley storage that does not support ...@@ -18,7 +18,7 @@ See Minimal.py for an implementation of Berkeley storage that does not support
undo or versioning. undo or versioning.
""" """
__version__ = '$Revision: 1.42 $'.split()[-2:][0] __version__ = '$Revision: 1.43 $'.split()[-2:][0]
import sys import sys
import struct import struct
...@@ -463,8 +463,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -463,8 +463,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# We've already dealt with this oid... # We've already dealt with this oid...
continue continue
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid meta = self._metadata[oid+tid]
meta = self._metadata[oid+revid]
curvid, nvrevid = struct.unpack('>8s8s', meta[:16]) curvid, nvrevid = struct.unpack('>8s8s', meta[:16])
# Make sure that the vid in the metadata record is the same as # Make sure that the vid in the metadata record is the same as
# the vid we sucked out of the vids table. # the vid we sucked out of the vids table.
...@@ -484,7 +483,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -484,7 +483,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# Write the object id, live revision id, the current revision # Write the object id, live revision id, the current revision
# id (which serves as the previous revid to this transaction) # id (which serves as the previous revid to this transaction)
# to the commit log. # to the commit log.
self._commitlog.write_nonversion_object(oid, lrevid, revid) self._commitlog.write_nonversion_object(oid, lrevid, tid)
# Remember to return the oid... # Remember to return the oid...
oids[oid] = 1 oids[oid] = 1
# We've now processed all the objects on the discarded version, so # We've now processed all the objects on the discarded version, so
...@@ -534,8 +533,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -534,8 +533,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
if oids.has_key(oid): if oids.has_key(oid):
continue continue
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid meta = self._metadata[oid+tid]
meta = self._metadata[oid+revid]
curvid, nvrevid, lrevid = struct.unpack('>8s8s8s', meta[:24]) curvid, nvrevid, lrevid = struct.unpack('>8s8s8s', meta[:24])
# Our database better be consistent. # Our database better be consistent.
if curvid <> svid: if curvid <> svid:
...@@ -548,7 +546,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -548,7 +546,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
if not dest: if not dest:
nvrevid = ZERO nvrevid = ZERO
self._commitlog.write_moved_object( self._commitlog.write_moved_object(
oid, dvid, nvrevid, lrevid, revid) oid, dvid, nvrevid, lrevid, tid)
# Remember to return the oid... # Remember to return the oid...
oids[oid] = 1 oids[oid] = 1
# Now that we're done, we can discard this version # Now that we're done, we can discard this version
...@@ -567,8 +565,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -567,8 +565,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
try: try:
# Let KeyErrors percolate up # Let KeyErrors percolate up
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid vid = self._metadata[oid+tid][:8]
vid = self._metadata[oid+revid][:8]
if vid == ZERO: if vid == ZERO:
# Not in a version # Not in a version
return '' return ''
...@@ -596,11 +593,10 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -596,11 +593,10 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# Get the current revid for the object. As per the protocol, let # Get the current revid for the object. As per the protocol, let
# any KeyErrors percolate up. # any KeyErrors percolate up.
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid
# Get the metadata associated with this revision of the object. # Get the metadata associated with this revision of the object.
# All we really need is the vid, the non-version revid and the # All we really need is the vid, the non-version revid and the
# pickle pointer revid. # pickle pointer revid.
rec = self._metadata[oid+revid] rec = self._metadata[oid+tid]
vid, nvrevid, lrevid = struct.unpack('>8s8s8s', rec[:24]) vid, nvrevid, lrevid = struct.unpack('>8s8s8s', rec[:24])
if lrevid == DNE: if lrevid == DNE:
raise KeyError, 'Object does not exist' raise KeyError, 'Object does not exist'
...@@ -1060,15 +1056,14 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1060,15 +1056,14 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# the transaction records backwards until we find enough records. # the transaction records backwards until we find enough records.
history = [] history = []
serial, tid = self._getSerialAndTid(oid) serial, tid = self._getSerialAndTid(oid)
revid = tid
# BAW: Again, let KeyErrors percolate up # BAW: Again, let KeyErrors percolate up
while len(history) < size: while len(history) < size:
# Some information comes out of the revision metadata... # Some information comes out of the revision metadata...
vid, nvrevid, lrevid, previd = struct.unpack( vid, nvrevid, lrevid, previd = struct.unpack(
'>8s8s8s8s', self._metadata[oid+revid]) '>8s8s8s8s', self._metadata[oid+tid])
# ...while other information comes out of the transaction # ...while other information comes out of the transaction
# metadata. # metadata.
txnmeta = self._txnMetadata[revid] txnmeta = self._txnMetadata[tid]
userlen, desclen = struct.unpack('>II', txnmeta[1:9]) userlen, desclen = struct.unpack('>II', txnmeta[1:9])
user = txnmeta[9:9+userlen] user = txnmeta[9:9+userlen]
desc = txnmeta[9+userlen:9+userlen+desclen] desc = txnmeta[9+userlen:9+userlen+desclen]
...@@ -1082,7 +1077,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1082,7 +1077,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
else: else:
retvers = self._versions[vid] retvers = self._versions[vid]
# The HistoryEntry object # The HistoryEntry object
d = {'time' : TimeStamp(revid).timeTime(), d = {'time' : TimeStamp(tid).timeTime(),
'user_name' : user, 'user_name' : user,
'description': desc, 'description': desc,
'serial' : serial, 'serial' : serial,
...@@ -1095,7 +1090,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1095,7 +1090,7 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
# revision, stopping when we've reached the end. # revision, stopping when we've reached the end.
if previd == ZERO: if previd == ZERO:
break break
serial = revid = previd serial = tid = previd
return history return history
finally: finally:
self._lock_release() self._lock_release()
...@@ -1119,12 +1114,11 @@ class Full(BerkeleyBase, ConflictResolvingStorage): ...@@ -1119,12 +1114,11 @@ class Full(BerkeleyBase, ConflictResolvingStorage):
reachables[oid] = 1 reachables[oid] = 1
# Get the pickle data for the object's current version # Get the pickle data for the object's current version
serial, tid = self._getSerialAndTidMissingOk(oid) serial, tid = self._getSerialAndTidMissingOk(oid)
revid = tid if tid is None:
if revid is None:
# BAW: how can this happen?! This means that an object is # BAW: how can this happen?! This means that an object is
# holding references to an object that we know nothing about. # holding references to an object that we know nothing about.
continue continue
lrevid = self._metadata[oid+revid][16:24] lrevid = self._metadata[oid+tid][16:24]
pickle = self._pickles[oid+lrevid] pickle = self._pickles[oid+lrevid]
refdoids = [] refdoids = []
referencesf(pickle, refdoids) referencesf(pickle, refdoids)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment