~vmiklos/bzr-fastimport/darcs

« back to all changes in this revision

Viewing changes to revision_store.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-05 07:24:14 UTC
  • mfrom: (260.2.2 fastimport-kg)
  • Revision ID: john@arbash-meinel.com-20100105072414-gy7y1iw47jajujna
Include the known_graph code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import cStringIO
20
20
 
21
 
from bzrlib import errors, inventory, knit, lru_cache, osutils, trace
22
 
from bzrlib import revision as _mod_revision
 
21
from bzrlib import (
 
22
    errors,
 
23
    graph as _mod_graph,
 
24
    inventory,
 
25
    knit,
 
26
    lru_cache,
 
27
    osutils,
 
28
    revision as _mod_revision,
 
29
    trace,
 
30
    )
23
31
 
24
32
 
25
33
class _TreeShim(object):
159
167
        :param repository: the target repository
160
168
        """
161
169
        self.repo = repo
 
170
        self._graph = None
 
171
        self._use_known_graph = True
162
172
        self._supports_chks = getattr(repo._format, 'supports_chks', False)
163
173
 
164
174
    def expects_rich_root(self):
355
365
            parents=rev.parent_ids, config=None, timestamp=rev.timestamp,
356
366
            timezone=rev.timezone, committer=rev.committer,
357
367
            revprops=rev.properties, revision_id=rev.revision_id)
 
368
        if self._graph is None and self._use_known_graph:
 
369
            if (getattr(_mod_graph, 'GraphThunkIdsToKeys', None) is None
 
370
                or getattr(_mod_graph.KnownGraph, 'add_node', None) is None):
 
371
                self._use_known_graph = False
 
372
            else:
 
373
                self._graph = self.repo.revisions.get_known_graph_ancestry(
 
374
                    [(r,) for r in rev.parent_ids])
 
375
        if self._graph is not None:
 
376
            orig_heads = builder._heads
 
377
            def thunked_heads(file_id, revision_ids):
 
378
                # self._graph thinks in terms of keys, not ids, so translate
 
379
                # them
 
380
                # old_res = orig_heads(file_id, revision_ids)
 
381
                if len(revision_ids) < 2:
 
382
                    res = set(revision_ids)
 
383
                else:
 
384
                    res = set([h[0] for h in
 
385
                              self._graph.heads([(r,) for r in revision_ids])])
 
386
                # if old_res != res:
 
387
                #     import pdb; pdb.set_trace()
 
388
                return res
 
389
            builder._heads = thunked_heads
358
390
 
359
391
        if rev.parent_ids:
360
392
            basis_rev_id = rev.parent_ids[0]
379
411
        rev.inv_sha1 = builder.inv_sha1
380
412
        builder.repository.add_revision(builder._new_revision_id, rev,
381
413
            builder.new_inventory, builder._config)
 
414
        if self._graph is not None:
 
415
            # TODO: Use StaticTuple and .intern() for these things
 
416
            self._graph.add_node((builder._new_revision_id,),
 
417
                                 [(p,) for p in rev.parent_ids])
382
418
 
383
419
        if signature is not None:
384
420
            raise AssertionError('signatures not guaranteed yet')