/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

Cope with imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    errors,
23
23
    graph,
24
24
    inventory,
25
 
    osutils,
26
25
    repository,
27
26
    revision,
28
27
    revisiontree,
29
 
    ui,
30
 
    urlutils,
31
28
    )
32
29
from bzrlib.foreign import (
33
30
    ForeignRepository,
34
31
    )
35
 
from bzrlib.trace import (
36
 
    mutter,
37
 
    )
38
 
from bzrlib.transport import (
39
 
    get_transport,
40
 
    )
41
32
 
42
33
from bzrlib.plugins.git.commit import (
43
34
    GitCommitBuilder,
44
35
    )
45
 
from bzrlib.plugins.git.inventory import (
46
 
    GitInventory,
47
 
    )
48
36
from bzrlib.plugins.git.mapping import (
49
37
    default_mapping,
50
38
    foreign_git,
51
39
    mapping_registry,
52
40
    )
 
41
from bzrlib.plugins.git.tree import (
 
42
    GitRevisionTree,
 
43
    )
53
44
from bzrlib.plugins.git.versionedfiles import (
54
45
    GitRevisions,
55
46
    GitTexts,
64
55
    vcs = foreign_git
65
56
 
66
57
    def __init__(self, gitdir, lockfiles):
67
 
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
 
58
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
68
59
            lockfiles)
69
60
        from bzrlib.plugins.git import fetch, push
70
 
        for optimiser in [fetch.InterRemoteGitNonGitRepository, 
 
61
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
71
62
                          fetch.InterLocalGitNonGitRepository,
72
63
                          fetch.InterGitGitRepository,
73
64
                          push.InterToLocalGitRepository,
106
97
    """Git repository on the file system."""
107
98
 
108
99
    def __init__(self, gitdir, lockfiles):
109
 
        # FIXME: This also caches negatives. Need to be more careful 
 
100
        # FIXME: This also caches negatives. Need to be more careful
110
101
        # about this once we start writing to git
111
102
        self._parents_provider = graph.CachingParentsProvider(self)
112
103
        GitRepository.__init__(self, gitdir, lockfiles)
113
104
        self.base = gitdir.root_transport.base
114
105
        self._git = gitdir._git
115
 
        self.texts = None
116
106
        self.signatures = None
117
 
        self.revisions = GitRevisions(self._git.object_store)
 
107
        self.revisions = GitRevisions(self, self._git.object_store)
118
108
        self.inventories = None
119
109
        self.texts = GitTexts(self)
120
110
 
121
111
    def all_revision_ids(self):
122
 
        ret = set([revision.NULL_REVISION])
 
112
        ret = set([])
123
113
        heads = self._git.refs.as_dict('refs/heads')
124
114
        if heads == {}:
125
115
            return ret
141
131
            if revision_id == revision.NULL_REVISION:
142
132
                parent_map[revision_id] = ()
143
133
                continue
144
 
            hexsha, mapping = self.lookup_git_revid(revision_id)
145
 
            commit  = self._git.commit(hexsha)
 
134
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
 
135
            try:
 
136
                commit = self._git.commit(hexsha)
 
137
            except KeyError:
 
138
                continue
146
139
            if commit is None:
 
140
                # Older versions of Dulwich used to return None rather than
 
141
                # raise KeyError.
147
142
                continue
148
143
            else:
149
144
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
165
160
    def get_signature_text(self, revision_id):
166
161
        raise errors.NoSuchRevision(self, revision_id)
167
162
 
168
 
    def lookup_revision_id(self, revid):
 
163
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
169
164
        """Lookup a revision id.
170
 
        
 
165
 
171
166
        :param revid: Bazaar revision id.
172
167
        :return: Tuple with git revisionid and mapping.
173
168
        """
174
 
        # Yes, this doesn't really work, but good enough as a stub
175
 
        return osutils.sha(rev_id).hexdigest(), self.get_mapping()
 
169
        if mapping is None:
 
170
            mapping = self.get_mapping()
 
171
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
176
172
 
177
173
    def has_signature_for_revision_id(self, revision_id):
178
174
        return False
179
175
 
180
 
    def lookup_git_revid(self, bzr_revid):
 
176
    def lookup_bzr_revision_id(self, bzr_revid):
181
177
        try:
182
178
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
183
179
        except errors.InvalidRevisionId:
184
180
            raise errors.NoSuchRevision(self, bzr_revid)
185
181
 
186
182
    def get_revision(self, revision_id):
187
 
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
 
183
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
188
184
        try:
189
185
            commit = self._git.commit(git_commit_id)
190
186
        except KeyError:
228
224
        progress=None):
229
225
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
230
226
 
231
 
 
232
 
class GitRevisionTree(revisiontree.RevisionTree):
233
 
 
234
 
    def __init__(self, repository, revision_id):
235
 
        self._revision_id = revision_id
236
 
        self._repository = repository
237
 
        store = repository._git.object_store
238
 
        assert isinstance(revision_id, str)
239
 
        git_id, self.mapping = repository.lookup_git_revid(revision_id)
240
 
        try:
241
 
            commit = store[git_id]
242
 
        except KeyError, r:
243
 
            raise errors.NoSuchRevision(repository, revision_id)
244
 
        self.tree = commit.tree
245
 
        self._inventory = GitInventory(self.tree, self.mapping, store, 
246
 
                                       revision_id)
247
 
 
248
 
    def get_revision_id(self):
249
 
        return self._revision_id
250
 
 
251
 
    def get_file_text(self, file_id, path=None):
252
 
        if path is not None:
253
 
            entry = self._inventory._get_ie(path)
254
 
        else:
255
 
            entry = self._inventory[file_id]
256
 
        if entry.kind == 'directory': return ""
257
 
        return entry.object.data
 
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 {}, []
258
239
 
259
240
 
260
241
class GitRepositoryFormat(repository.RepositoryFormat):
267
248
        return "Git Repository"
268
249
 
269
250
    def initialize(self, url, shared=False, _internal=False):
270
 
        raise bzr_errors.UninitializableFormat(self)
 
251
        raise errors.UninitializableFormat(self)
271
252
 
272
253
    def check_conversion_target(self, target_repo_format):
273
254
        return target_repo_format.rich_root_data
274
255
 
 
256
    def get_foreign_tests_repository_factory(self):
 
257
        from bzrlib.plugins.git.tests.test_repository import ForeignTestsRepositoryFactory
 
258
        return ForeignTestsRepositoryFactory()
 
259
 
275
260
    def network_name(self):
276
261
        return "git"