/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 repository.py

More tests for sha maps, fix cache misses in tdb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    errors,
23
23
    graph,
24
24
    inventory,
 
25
    osutils,
25
26
    repository,
26
27
    revision,
27
28
    revisiontree,
 
29
    ui,
 
30
    urlutils,
28
31
    )
29
32
from bzrlib.foreign import (
30
33
    ForeignRepository,
31
34
    )
 
35
from bzrlib.trace import (
 
36
    mutter,
 
37
    )
 
38
from bzrlib.transport import (
 
39
    get_transport,
 
40
    )
32
41
 
33
42
from bzrlib.plugins.git.commit import (
34
43
    GitCommitBuilder,
35
44
    )
 
45
from bzrlib.plugins.git.foreign import (
 
46
    versionedfiles,
 
47
    )
 
48
from bzrlib.plugins.git.inventory import (
 
49
    GitInventory,
 
50
    )
36
51
from bzrlib.plugins.git.mapping import (
37
52
    default_mapping,
38
53
    foreign_git,
39
54
    mapping_registry,
40
55
    )
41
 
from bzrlib.plugins.git.tree import (
42
 
    GitRevisionTree,
43
 
    )
44
56
from bzrlib.plugins.git.versionedfiles import (
45
 
    GitRevisions,
46
57
    GitTexts,
47
58
    )
48
59
 
49
60
 
 
61
class GitTags(object):
 
62
 
 
63
    def __init__(self, tags):
 
64
        self._tags = tags
 
65
 
 
66
    def __iter__(self):
 
67
        return iter(self._tags)
 
68
 
 
69
 
50
70
class GitRepository(ForeignRepository):
51
71
    """An adapter to git repositories for bzr."""
52
72
 
55
75
    vcs = foreign_git
56
76
 
57
77
    def __init__(self, gitdir, lockfiles):
58
 
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
 
78
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
59
79
            lockfiles)
60
80
        from bzrlib.plugins.git import fetch, push
61
 
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
 
81
        for optimiser in [fetch.InterRemoteGitNonGitRepository, 
62
82
                          fetch.InterLocalGitNonGitRepository,
63
83
                          fetch.InterGitGitRepository,
64
84
                          push.InterToLocalGitRepository,
81
101
    def make_working_trees(self):
82
102
        return True
83
103
 
84
 
    def revision_graph_can_have_wrong_parents(self):
85
 
        return False
86
 
 
87
104
    def dfetch(self, source, stop_revision):
88
105
        interrepo = repository.InterRepository.get(source, self)
89
106
        return interrepo.dfetch(stop_revision)
97
114
    """Git repository on the file system."""
98
115
 
99
116
    def __init__(self, gitdir, lockfiles):
100
 
        # FIXME: This also caches negatives. Need to be more careful
 
117
        # FIXME: This also caches negatives. Need to be more careful 
101
118
        # about this once we start writing to git
102
119
        self._parents_provider = graph.CachingParentsProvider(self)
103
120
        GitRepository.__init__(self, gitdir, lockfiles)
104
121
        self.base = gitdir.root_transport.base
105
122
        self._git = gitdir._git
106
 
        self.signatures = None
107
 
        self.revisions = GitRevisions(self, self._git.object_store)
108
 
        self.inventories = None
 
123
        self.texts = None
 
124
        self.signatures = versionedfiles.VirtualSignatureTexts(self)
 
125
        self.revisions = versionedfiles.VirtualRevisionTexts(self)
 
126
        self.inventories = versionedfiles.VirtualInventoryTexts(self)
109
127
        self.texts = GitTexts(self)
 
128
        self.tags = GitTags(self._git.get_tags())
110
129
 
111
130
    def all_revision_ids(self):
112
 
        ret = set([])
113
 
        heads = self._git.refs.as_dict('refs/heads')
 
131
        ret = set([revision.NULL_REVISION])
 
132
        heads = self._git.heads()
114
133
        if heads == {}:
115
134
            return ret
116
135
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
131
150
            if revision_id == revision.NULL_REVISION:
132
151
                parent_map[revision_id] = ()
133
152
                continue
134
 
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
135
 
            try:
136
 
                commit = self._git.commit(hexsha)
137
 
            except KeyError:
138
 
                continue
 
153
            hexsha, mapping = self.lookup_git_revid(revision_id)
 
154
            commit  = self._git.commit(hexsha)
139
155
            if commit is None:
140
 
                # Older versions of Dulwich used to return None rather than
141
 
                # raise KeyError.
142
156
                continue
143
157
            else:
144
158
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
160
174
    def get_signature_text(self, revision_id):
161
175
        raise errors.NoSuchRevision(self, revision_id)
162
176
 
163
 
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
 
177
    def lookup_revision_id(self, revid):
164
178
        """Lookup a revision id.
165
 
 
 
179
        
166
180
        :param revid: Bazaar revision id.
167
181
        :return: Tuple with git revisionid and mapping.
168
182
        """
169
 
        if mapping is None:
170
 
            mapping = self.get_mapping()
171
 
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
 
183
        # Yes, this doesn't really work, but good enough as a stub
 
184
        return osutils.sha(rev_id).hexdigest(), self.get_mapping()
172
185
 
173
186
    def has_signature_for_revision_id(self, revision_id):
174
187
        return False
175
188
 
176
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
189
    def lookup_git_revid(self, bzr_revid):
177
190
        try:
178
191
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
179
192
        except errors.InvalidRevisionId:
180
193
            raise errors.NoSuchRevision(self, bzr_revid)
181
194
 
182
195
    def get_revision(self, revision_id):
183
 
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
196
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
184
197
        try:
185
198
            commit = self._git.commit(git_commit_id)
186
199
        except KeyError:
224
237
        progress=None):
225
238
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
226
239
 
227
 
    def _get_versioned_file_checker(self, text_key_references=None,
228
 
                        ancestors=None):
229
 
        return GitVersionedFileChecker(self,
230
 
            text_key_references=text_key_references, ancestors=ancestors)
231
 
    
232
 
 
233
 
class GitVersionedFileChecker(repository._VersionedFileChecker):
234
 
 
235
 
    file_ids = []
236
 
 
237
 
    def _check_file_version_parents(self, texts, progress_bar):
238
 
        return {}, []
 
240
 
 
241
class GitRevisionTree(revisiontree.RevisionTree):
 
242
 
 
243
    def __init__(self, repository, revision_id):
 
244
        self._repository = repository
 
245
        self._revision_id = revision_id
 
246
        assert isinstance(revision_id, str)
 
247
        git_id, self.mapping = repository.lookup_git_revid(revision_id)
 
248
        try:
 
249
            commit = repository._git.commit(git_id)
 
250
        except KeyError, r:
 
251
            raise errors.NoSuchRevision(repository, revision_id)
 
252
        self.tree = commit.tree
 
253
        self._inventory = GitInventory(self.tree, self.mapping, repository._git.object_store, revision_id)
 
254
 
 
255
    def get_revision_id(self):
 
256
        return self._revision_id
 
257
 
 
258
    def get_file_text(self, file_id):
 
259
        entry = self._inventory[file_id]
 
260
        if entry.kind == 'directory': return ""
 
261
        return entry.object.data
239
262
 
240
263
 
241
264
class GitRepositoryFormat(repository.RepositoryFormat):
248
271
        return "Git Repository"
249
272
 
250
273
    def initialize(self, url, shared=False, _internal=False):
251
 
        raise errors.UninitializableFormat(self)
 
274
        raise bzr_errors.UninitializableFormat(self)
252
275
 
253
276
    def check_conversion_target(self, target_repo_format):
254
277
        return target_repo_format.rich_root_data
255
 
 
256
 
    def get_foreign_tests_repository_factory(self):
257
 
        from bzrlib.plugins.git.tests.test_repository import ForeignTestsRepositoryFactory
258
 
        return ForeignTestsRepositoryFactory()
259
 
 
260
 
    def network_name(self):
261
 
        return "git"