1
=== modified file 'bzrlib/weave.py'
6
# TODO: Perhaps the API should work only in names to hide the integer
7
# indexes from the user?
9
+# TODO: Is there any potential performance win by having an add()
10
+# variant that is passed a pre-cooked version of the single basis
19
- __slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
21
+ ##__slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
22
+ ## '_weave_name', '_inclusion_cache']
24
def __init__(self, weave_name=None):
29
self._weave_name = weave_name
31
+ self._inclusion_cache = {}
33
def __eq__(self, other):
34
if not isinstance(other, Weave):
36
self._weave.append(('{', new_version))
37
self._weave.extend(text)
38
self._weave.append(('}', None))
44
if sha1 == self._sha1s[pv]:
45
# special case: same as the single parent
49
ancestors = self.inclusions(parents)
51
+ self._inclusion_cache[(new_version,)] = ancestors | set([new_version])
54
# basis a list of (origin, lineno, line)
57
def inclusions(self, versions):
58
"""Return set of all ancestors of given version(s)."""
59
+ tv = tuple(sorted(versions))
60
+ cached_val = self._inclusion_cache.get(tv)
61
+ if cached_val is not None:
68
- # include all its parents
69
- i.update(self._parents[v])
73
- raise ValueError("version %d not present in weave" % v)
74
+ for v in xrange(max(versions), 0, -1):
76
+ # include all its parents
77
+ i.update(self._parents[v])
78
+ self._inclusion_cache[tv] = i
80
+ ## except IndexError:
81
+ ## raise ValueError("version %d not present in weave" % v)
84
def parents(self, version):