[Pkg-bazaar-commits] ./bzr/unstable r892: - weave stores only direct parents, and calculates and memoizes expansion as needed

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:21:22 UTC 2009


------------------------------------------------------------
revno: 892
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-11 14:28:44 +1000
message:
  - weave stores only direct parents, and calculates and memoizes expansion as needed
modified:
  bzrlib/weave.py
  bzrlib/weavefile.py
-------------- next part --------------
=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py	2005-07-11 04:08:33 +0000
+++ b/bzrlib/weave.py	2005-07-11 04:28:44 +0000
@@ -139,16 +139,15 @@
       version.
 
     _l
-        Text of the weave. 
+        Text of the weave.
 
     _v
-        List of versions, indexed by index number.
+        List of parents, indexed by version number.
+        It is only necessary to store the minimal set of parents for
+        each version; the parent's parents are implied.
 
-        For each version we store the set (included_versions), which
-        lists the previous versions also considered active; the
-        versions included in those versions are included transitively.
-        So new versions created from nothing list []; most versions
-        have a single entry; some have more.
+    _i
+        Full set of inclusions for each revision.
 
     _sha1s
         List of hex SHA-1 of each version, or None if not recorded.
@@ -157,6 +156,7 @@
         self._l = []
         self._v = []
         self._sha1s = []
+        self._i = {}
 
 
     def __eq__(self, other):
@@ -176,9 +176,8 @@
         Returns the index number of the newly added version.
 
         parents
-            List or set of parent version numbers.  This must normally include
-            the parents and the parent's parents, or wierd things might happen.
-
+            List or set of direct parent version numbers.
+            
         text
             Sequence of lines to be added in the new version."""
         ## self._check_versions(parents)
@@ -193,7 +192,8 @@
         del s
 
         if parents:
-            delta = self._delta(self.inclusions(parents), text)
+            ancestors = self.inclusions(parents)
+            delta = self._delta(ancestors, text)
 
             # offset gives the number of lines that have been inserted
             # into the weave up to the current point; if the original edit instruction
@@ -238,14 +238,25 @@
         return idx
 
 
+    def _expand(self, version):
+        if version in self._i:
+            return self._i[version]
+        else:
+            i = set([version])
+            for pv in self._v[version]:
+                i.update(self._expand(pv))
+            self._i[version] = i
+            return i
+
+
     def inclusions(self, versions):
         """Expand out everything included by versions."""
         i = set(versions)
-        for v in versions:
-            try:
-                i.update(self._v[v])
-            except IndexError:
-                raise ValueError("version %d not present in weave" % v)
+        try:
+            for v in versions:
+                i.update(self._expand(v))
+        except IndexError:
+            raise ValueError("version %d not present in weave" % v)
         return i
 
 
@@ -274,7 +285,7 @@
 
     def _addversion(self, parents):
         if parents:
-            self._v.append(frozenset(parents))
+            self._v.append(parents)
         else:
             self._v.append(frozenset())
 
@@ -308,7 +319,7 @@
 
         The index indicates when the line originated in the weave."""
         included = self.inclusions([version])
-        for origin, lineno, text in self._extract(included):
+        for origin, lineno, text in self._extract(self.inclusions(included)):
             yield origin, text
 
 
@@ -381,7 +392,7 @@
     def mash_iter(self, included):
         """Return composed version of multiple included versions."""
         included = frozenset(included)
-        for origin, lineno, text in self._extract(included):
+        for origin, lineno, text in self._extract(self.inclusions(included)):
             yield text
 
 
@@ -469,7 +480,7 @@
         # basis a list of (origin, lineno, line)
         basis_lineno = []
         basis_lines = []
-        for origin, lineno, line in self._extract(included):
+        for origin, lineno, line in self._extract(self.inclusions(included)):
             basis_lineno.append(lineno)
             basis_lines.append(line)
 
@@ -525,7 +536,9 @@
         bytes = sum((len(a) for a in text))
         sha1 = w._sha1s[i]
         print '%6d %6d %8d %40s' % (i, lines, bytes, sha1),
-        print ', '.join(map(str, w.minimal_parents(i)))
+        for pv in w._v[i]:
+            print pv,
+        print
         total += bytes
 
     print >>out, "versions total %d bytes" % total
@@ -634,6 +647,14 @@
         w = readit()
         w.check()
 
+    elif cmd == 'inclusions':
+        w = readit()
+        print ' '.join(map(str, w.inclusions([int(argv[3])])))
+
+    elif cmd == 'parents':
+        w = readit()
+        print ' '.join(map(str, w._v[int(argv[3])]))
+
     elif cmd == 'merge':
         if len(argv) != 5:
             usage()

=== modified file 'bzrlib/weavefile.py'
--- a/bzrlib/weavefile.py	2005-07-11 04:08:33 +0000
+++ b/bzrlib/weavefile.py	2005-07-11 04:28:44 +0000
@@ -54,7 +54,8 @@
 
     for version, included in enumerate(weave._v):
         if included:
-            mininc = weave.minimal_parents(version)
+            # mininc = weave.minimal_parents(version)
+            mininc = included
             print >>f, 'i',
             for i in mininc:
                 print >>f, i,
@@ -105,11 +106,7 @@
 
             if len(l) > 2:
                 included = map(int, l[2:].split(' '))
-                full = set()
-                for pv in included:
-                    full.add(pv)
-                    full.update(w._v[pv])
-                w._addversion(full)
+                w._addversion(included)
             else:
                 w._addversion(None)
 



More information about the Pkg-bazaar-commits mailing list