/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

  • Committer: Jelmer Vernooij
  • Date: 2010-02-12 13:29:05 UTC
  • mto: (0.200.718 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20100212132905-1x9kyvsrztcz95gd
Use local repo if possible.

Show diffs side-by-side

added added

removed removed

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