[Pkg-bazaar-commits] ./bzr/unstable r881: - faster weave extraction

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:13:38 UTC 2009


------------------------------------------------------------
revno: 881
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-11 13:16:29 +1000
message:
  - faster weave extraction
modified:
  bzrlib/weave.py
-------------- next part --------------
=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py	2005-07-11 02:31:10 +0000
+++ b/bzrlib/weave.py	2005-07-11 03:16:29 +0000
@@ -298,74 +298,39 @@
 
         The set typically but not necessarily corresponds to a version.
         """
-        istack = []          # versions for which an insertion block is current
-
-        dset = set()         # versions for which a deletion block is current
-
-        isactive = None
+
+        istack = []
+        dset = set()
 
         lineno = 0         # line of weave, 0-based
-
-        # TODO: Probably only need to put included revisions in the istack
-
-        # TODO: Could split this into two functions, one that updates
-        # the stack and the other that processes the results -- but
-        # I'm not sure it's really needed.
-
-        # TODO: In fact, I think we only need to store the *count* of
-        # active insertions and deletions, and we can maintain that by
-        # just by just counting as we go along.
+        isactive = False
 
         WFE = WeaveFormatError
 
         for l in self._l:
             if isinstance(l, tuple):
-                isactive = None         # recalculate
                 c, v = l
-                if c == '{':
-                    if istack and (istack[-1] >= v):
-                        raise WFE("improperly nested insertions %d>=%d on line %d" 
-                                  % (istack[-1], v, lineno))
-                    istack.append(v)
-                elif c == '}':
-                    try:
+                if v in included:       # only active blocks are interesting
+                    if c == '{':
+                        assert v not in istack
+                        istack.append(v)
+                        isactive = not dset
+                    elif c == '}':
                         oldv = istack.pop()
-                    except IndexError:
-                        raise WFE("unmatched close of insertion %d on line %d"
-                                  % (v, lineno))
-                    if oldv != v:
-                        raise WFE("mismatched close of insertion %d!=%d on line %d"
-                                  % (oldv, v, lineno))
-                elif c == '[':
-                    # block deleted in v
-                    if v in dset:
-                        raise WFE("repeated deletion marker for version %d on line %d"
-                                  % (v, lineno))
-                    if istack:
-                        if istack[-1] == v:
-                            raise WFE("version %d deletes own text on line %d"
-                                      % (v, lineno))
-                        # XXX
+                        assert oldv == v
+                        isactive = istack and not dset
+                    elif c == '[':
+                        assert v not in dset
                         dset.add(v)
-                elif c == ']':
-                    if v in dset:
+                        isactive = False
+                    else:
+                        assert c == ']'
+                        assert v in dset
                         dset.remove(v)
-                    else:
-                        raise WFE("unmatched close of deletion %d on line %d"
-                                  % (v, lineno))
-                else:
-                    raise WFE("invalid processing instruction %r on line %d"
-                              % (l, lineno))
+                        isactive = istack and not dset
             else:
                 assert isinstance(l, basestring)
-                if not istack:
-                    raise WFE("literal at top level on line %d"
-                              % lineno)
-                if isactive == None:
-                    isactive = (istack[-1] in included) \
-                               and not included.intersection(dset)
                 if isactive:
-                    origin = istack[-1]
                     yield origin, lineno, l
             lineno += 1
 
@@ -433,6 +398,10 @@
                                  "got %s, expected %s"
                                  % (version, hd, expected))
 
+        # TODO: check insertions are properly nested, that there are
+        # no lines outside of insertion blocks, that deletions are
+        # properly paired, etc.
+
 
 
     def merge(self, merge_versions):



More information about the Pkg-bazaar-commits mailing list