/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Robert Collins
  • Date: 2008-01-14 04:46:08 UTC
  • mto: This revision was merged to the branch mainline in revision 3184.
  • Revision ID: robertc@robertcollins.net-20080114044608-bmse3mmsnp1663rf
Create new smart server verb Repository.get_parent_map.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    SmartServerRequest,
31
31
    SuccessfulSmartServerResponse,
32
32
    )
 
33
from bzrlib import revision as _mod_revision
33
34
 
34
35
 
35
36
class SmartServerRepositoryRequest(SmartServerRequest):
51
52
        return self.do_repository_request(repository, *args)
52
53
 
53
54
 
 
55
class SmartServerRepositoryGetParentMap(SmartServerRepositoryRequest):
 
56
    
 
57
    def do_repository_request(self, repository, *revision_ids):
 
58
        repository.lock_read()
 
59
        try:
 
60
            return self._do_repository_request(repository, revision_ids)
 
61
        finally:
 
62
            repository.unlock()
 
63
 
 
64
    def _do_repository_request(self, repository, revision_ids):
 
65
        """Get parent details for some revisions.
 
66
        
 
67
        All the parents for revision_ids are returned. Additionally up to 64KB
 
68
        of additional parent data found by performing a breadth first search
 
69
        from revision_ids is returned.
 
70
 
 
71
        :param repository: The repository to query in.
 
72
        :param revision_id:s The utf8 encoded revision_id to answer.
 
73
        :return: A smart server response where the body contains an utf8
 
74
            encoded flattened list of the revision graph, (the same format as
 
75
            Repository.get_revision_graph).
 
76
        """
 
77
        lines = []
 
78
        repo_graph = repository.get_graph()
 
79
        result = {}
 
80
        queried_revs = set()
 
81
        size_so_far = 0
 
82
        next_revs = revision_ids
 
83
        first_loop_done = False
 
84
        while next_revs:
 
85
            queried_revs.update(next_revs)
 
86
            parent_map = repo_graph.get_parent_map(next_revs)
 
87
            next_revs = set()
 
88
            for revision_id, parents in parent_map.iteritems():
 
89
                # adjust for the wire
 
90
                if parents == (_mod_revision.NULL_REVISION,):
 
91
                    parents = ()
 
92
                # add parents to the result
 
93
                result[revision_id] = parents
 
94
                # prepare the next query
 
95
                next_revs.update(parents)
 
96
                size_so_far += 2 + len(revision_id) + sum(map(len, parents))
 
97
                # get all the directly asked for parents, and then flesh out to
 
98
                # 64K or so.
 
99
                if first_loop_done and size_so_far > 65000:
 
100
                    next_revs = set()
 
101
                    break
 
102
            # don't query things we've already queried
 
103
            next_revs.difference_update(queried_revs)
 
104
            first_loop_done = True
 
105
 
 
106
        for revision, parents in result.items():
 
107
            lines.append(' '.join((revision, ) + tuple(parents)))
 
108
 
 
109
        return SuccessfulSmartServerResponse(('ok', ), '\n'.join(lines))
 
110
 
 
111
 
54
112
class SmartServerRepositoryGetRevisionGraph(SmartServerRepositoryRequest):
55
113
    
56
114
    def do_repository_request(self, repository, revision_id):