/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

Avoid interpreting bzr-svn revisions in git revspecs.

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,
75
65
            repository.InterRepository.register_optimiser(optimiser)
76
66
 
77
67
    def is_shared(self):
78
 
        return True
 
68
        return False
79
69
 
80
70
    def supports_rich_root(self):
81
71
        return True
82
72
 
83
 
    def _warn_if_deprecated(self):
 
73
    def _warn_if_deprecated(self, branch=None):
84
74
        # This class isn't deprecated
85
75
        pass
86
76
 
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 
110
 
        # about this once we start writing to git
111
 
        self._parents_provider = graph.CachingParentsProvider(self)
112
99
        GitRepository.__init__(self, gitdir, lockfiles)
113
100
        self.base = gitdir.root_transport.base
114
101
        self._git = gitdir._git
115
 
        self.texts = None
116
102
        self.signatures = None
117
 
        self.revisions = GitRevisions(self._git.object_store)
 
103
        self.revisions = GitRevisions(self, self._git.object_store)
118
104
        self.inventories = None
119
105
        self.texts = GitTexts(self)
120
106
 
121
107
    def all_revision_ids(self):
122
 
        ret = set([revision.NULL_REVISION])
 
108
        ret = set([])
123
109
        heads = self._git.refs.as_dict('refs/heads')
124
110
        if heads == {}:
125
111
            return ret
130
116
            ret.add(rev)
131
117
        return ret
132
118
 
133
 
    def _make_parents_provider(self):
134
 
        """See Repository._make_parents_provider()."""
135
 
        return self._parents_provider
136
 
 
137
119
    def get_parent_map(self, revids):
138
120
        parent_map = {}
139
121
        for revision_id in revids:
141
123
            if revision_id == revision.NULL_REVISION:
142
124
                parent_map[revision_id] = ()
143
125
                continue
144
 
            hexsha, mapping = self.lookup_git_revid(revision_id)
145
 
            commit  = self._git.commit(hexsha)
146
 
            if commit is None:
 
126
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
 
127
            try:
 
128
                commit = self._git[hexsha]
 
129
            except KeyError:
147
130
                continue
148
 
            else:
149
 
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
 
131
            parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
150
132
        return parent_map
151
133
 
152
134
    def get_ancestry(self, revision_id, topo_sorted=True):
165
147
    def get_signature_text(self, revision_id):
166
148
        raise errors.NoSuchRevision(self, revision_id)
167
149
 
168
 
    def lookup_revision_id(self, revid):
 
150
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
169
151
        """Lookup a revision id.
170
 
        
171
 
        :param revid: Bazaar revision id.
172
 
        :return: Tuple with git revisionid and mapping.
 
152
 
173
153
        """
174
 
        # Yes, this doesn't really work, but good enough as a stub
175
 
        return osutils.sha(rev_id).hexdigest(), self.get_mapping()
 
154
        if mapping is None:
 
155
            mapping = self.get_mapping()
 
156
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
176
157
 
177
158
    def has_signature_for_revision_id(self, revision_id):
178
159
        return False
179
160
 
180
 
    def lookup_git_revid(self, bzr_revid):
 
161
    def lookup_bzr_revision_id(self, bzr_revid):
181
162
        try:
182
163
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
183
164
        except errors.InvalidRevisionId:
184
165
            raise errors.NoSuchRevision(self, bzr_revid)
185
166
 
186
167
    def get_revision(self, revision_id):
187
 
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
 
168
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
188
169
        try:
189
 
            commit = self._git.commit(git_commit_id)
 
170
            commit = self._git[git_commit_id]
190
171
        except KeyError:
191
172
            raise errors.NoSuchRevision(self, revision_id)
192
173
        # print "fetched revision:", git_commit_id
196
177
 
197
178
    def has_revision(self, revision_id):
198
179
        try:
199
 
            self.get_revision(revision_id)
 
180
            git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
200
181
        except errors.NoSuchRevision:
201
182
            return False
202
 
        else:
203
 
            return True
 
183
        return (git_commit_id in self._git)
 
184
 
 
185
    def has_revisions(self, revision_ids):
 
186
        ret = set()
 
187
        for revid in revision_ids:
 
188
            if self.has_revision(revid):
 
189
                ret.add(revid)
 
190
        return ret
204
191
 
205
192
    def get_revisions(self, revids):
206
193
        return [self.get_revision(r) for r in revids]
228
215
        progress=None):
229
216
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
230
217
 
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
 
218
    def _get_versioned_file_checker(self, text_key_references=None,
 
219
                        ancestors=None):
 
220
        return GitVersionedFileChecker(self,
 
221
            text_key_references=text_key_references, ancestors=ancestors)
 
222
    
 
223
 
 
224
class GitVersionedFileChecker(repository._VersionedFileChecker):
 
225
 
 
226
    file_ids = []
 
227
 
 
228
    def _check_file_version_parents(self, texts, progress_bar):
 
229
        return {}, []
258
230
 
259
231
 
260
232
class GitRepositoryFormat(repository.RepositoryFormat):
267
239
        return "Git Repository"
268
240
 
269
241
    def initialize(self, url, shared=False, _internal=False):
270
 
        raise bzr_errors.UninitializableFormat(self)
 
242
        raise errors.UninitializableFormat(self)
271
243
 
272
244
    def check_conversion_target(self, target_repo_format):
273
245
        return target_repo_format.rich_root_data
274
246
 
 
247
    def get_foreign_tests_repository_factory(self):
 
248
        from bzrlib.plugins.git.tests.test_repository import (
 
249
            ForeignTestsRepositoryFactory,
 
250
            )
 
251
        return ForeignTestsRepositoryFactory()
 
252
 
275
253
    def network_name(self):
276
254
        return "git"