~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to weave.py

  • Committer: Martin Pool
  • Date: 2005-06-30 08:40:59 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050630084059-d6eb6cb46972365b
Rename Weave.get_included to inclusions and getiter to get_iter

Refactor annotate() code 

Show diffs side-by-side

added added

removed removed

Lines of Context:
180
180
        idx = len(self._v)
181
181
 
182
182
        if parents:
183
 
            parents = frozenset(parents)
184
 
            delta = self._delta(parents, text)
 
183
            delta = self._delta(self.inclusions(parents), text)
185
184
 
186
185
            # offset gives the number of lines that have been inserted
187
186
            # into the weave up to the current point; if the original edit instruction
211
210
                                   + [('}', idx)]
212
211
                    offset += 2 + len(newlines)
213
212
 
 
213
            # TODO: Could eliminate any parents that are implied by
 
214
            # the others
 
215
                    
214
216
            self._addversion(parents)
215
217
        else:
216
218
            # special case; adding with no parents revision; can do this
224
226
        return idx
225
227
 
226
228
 
227
 
    def get_included(self, version):
228
 
        """Return a set with all included versions for version."""
229
 
        i = set()
230
 
        x = [version]
231
 
        while x:
232
 
            v = x.pop()
233
 
            if v in i:
234
 
                continue
235
 
            i.add(v)
236
 
            for u in self._v[v]:
237
 
                x.append(u)
 
229
    def inclusions(self, versions):
 
230
        """Expand out everything included by versions."""
 
231
        i = set(versions)
 
232
        for v in versions:
 
233
            i.update(self._v[v])
238
234
        return i
239
235
 
240
236
 
268
264
        return list(self.annotate_iter(index))
269
265
 
270
266
 
271
 
    def annotate_iter(self, index):
 
267
    def annotate_iter(self, version):
272
268
        """Yield list of (index-id, line) pairs for the specified version.
273
269
 
274
270
        The index indicates when the line originated in the weave."""
275
 
        try:
276
 
            vi = self._v[index]
277
 
        except IndexError:
278
 
            raise IndexError('version index %d out of range' % index)
279
 
        included = set(vi)
280
 
        included.add(index)
 
271
        included = self.inclusions([version])
281
272
        for origin, lineno, text in self._extract(included):
282
273
            yield origin, text
283
274
 
363
354
                                   dset)
364
355
 
365
356
 
366
 
    def getiter(self, index):
 
357
    def get_iter(self, version):
367
358
        """Yield lines for the specified version."""
368
 
        for origin, line in self.annotate_iter(index):
 
359
        for origin, lineno, line in self._extract(self.inclusions([version])):
369
360
            yield line
370
361
 
371
362
 
372
363
    def get(self, index):
373
 
        return list(self.getiter(index))
 
364
        return list(self.get_iter(index))
374
365
 
375
366
 
376
367
    def merge_iter(self, included):