/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 work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
        return default_mapping
83
83
 
84
84
    def make_working_trees(self):
85
 
        return True
 
85
        return not self._git.bare
86
86
 
87
87
    def revision_graph_can_have_wrong_parents(self):
88
88
        return False
91
91
        interrepo = repository.InterRepository.get(source, self)
92
92
        return interrepo.dfetch(stop_revision)
93
93
 
94
 
    def dfetch_refs(self, source, stop_revision):
95
 
        interrepo = repository.InterRepository.get(source, self)
96
 
        return interrepo.dfetch_refs(stop_revision)
97
 
 
98
 
    def fetch_refs(self, source, stop_revision):
99
 
        interrepo = repository.InterRepository.get(source, self)
100
 
        return interrepo.fetch_refs(stop_revision)
101
 
 
102
94
 
103
95
class LocalGitRepository(GitRepository):
104
96
    """Git repository on the file system."""
112
104
        self.inventories = None
113
105
        self.texts = GitTexts(self)
114
106
 
115
 
    def all_revision_ids(self):
116
 
        ret = set([])
 
107
    def _iter_revision_ids(self):
 
108
        mapping = self.get_mapping()
117
109
        for sha in self._git.object_store:
118
110
            o = self._git.object_store[sha]
119
111
            if not isinstance(o, Commit):
120
112
                continue
121
 
            rev = self.get_mapping().import_commit(o)
122
 
            ret.add(rev.revision_id)
 
113
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
 
114
                self.lookup_foreign_revision_id)
 
115
            yield o.id, rev.revision_id, roundtrip_revid
 
116
 
 
117
    def all_revision_ids(self):
 
118
        ret = set([])
 
119
        for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
 
120
            ret.add(revid)
 
121
            if roundtrip_revid:
 
122
                ret.add(roundtrip_revid)
123
123
        return ret
124
124
 
125
125
    def get_parent_map(self, revids):
134
134
                commit = self._git[hexsha]
135
135
            except KeyError:
136
136
                continue
137
 
            parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
 
137
            parent_map[revision_id] = [
 
138
                self.lookup_foreign_revision_id(p, mapping)
 
139
                for p in commit.parents]
138
140
        return parent_map
139
141
 
140
142
    def get_ancestry(self, revision_id, topo_sorted=True):
153
155
    def get_signature_text(self, revision_id):
154
156
        raise errors.NoSuchRevision(self, revision_id)
155
157
 
 
158
    def pack(self, hint=None, clean_obsolete_packs=False):
 
159
        self._git.object_store.pack_loose_objects()
 
160
 
156
161
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
157
162
        """Lookup a revision id.
158
163
 
159
164
        """
 
165
        assert type(foreign_revid) is str
160
166
        if mapping is None:
161
167
            mapping = self.get_mapping()
162
 
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
 
168
        from dulwich.protocol import (
 
169
            ZERO_SHA,
 
170
            )
 
171
        if foreign_revid == ZERO_SHA:
 
172
            return revision.NULL_REVISION
 
173
        commit = self._git[foreign_revid]
 
174
        rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
 
175
            lambda x: None)
 
176
        # FIXME: check testament before doing this?
 
177
        if roundtrip_revid:
 
178
            return roundtrip_revid
 
179
        else:
 
180
            return rev.revision_id
163
181
 
164
182
    def has_signature_for_revision_id(self, revision_id):
165
183
        return False
166
184
 
167
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
185
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
168
186
        try:
169
187
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
170
188
        except errors.InvalidRevisionId:
171
 
            mapping = self.get_mapping()
 
189
            if mapping is None:
 
190
                mapping = self.get_mapping()
172
191
            try:
173
 
                return self._git.refs[mapping.revid_as_refname(bzr_revid)], mapping
 
192
                return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
 
193
                        mapping)
174
194
            except KeyError:
 
195
                # Update refs from Git commit objects
 
196
                # FIXME: Hitting this a lot will be very inefficient...
 
197
                for git_sha, revid, roundtrip_revid in self._iter_revision_ids():
 
198
                    if not roundtrip_revid:
 
199
                        continue
 
200
                    refname = mapping.revid_as_refname(roundtrip_revid)
 
201
                    self._git.refs[refname] = git_sha
 
202
                    if roundtrip_revid == bzr_revid:
 
203
                        return git_sha, mapping
175
204
                raise errors.NoSuchRevision(self, bzr_revid)
176
205
 
177
206
    def get_revision(self, revision_id):
180
209
            commit = self._git[git_commit_id]
181
210
        except KeyError:
182
211
            raise errors.NoSuchRevision(self, revision_id)
183
 
        # print "fetched revision:", git_commit_id
184
 
        revision = mapping.import_commit(commit)
 
212
        revision, roundtrip_revid, verifiers = mapping.import_commit(
 
213
            commit, self.lookup_foreign_revision_id)
185
214
        assert revision is not None
 
215
        # FIXME: check verifiers ?
 
216
        if roundtrip_revid:
 
217
            revision.revision_id = roundtrip_revid
186
218
        return revision
187
219
 
188
220
    def has_revision(self, revision_id):
193
225
        return (git_commit_id in self._git)
194
226
 
195
227
    def has_revisions(self, revision_ids):
196
 
        ret = set()
197
 
        for revid in revision_ids:
198
 
            if self.has_revision(revid):
199
 
                ret.add(revid)
200
 
        return ret
 
228
        return set(filter(self.has_revision, revision_ids))
201
229
 
202
230
    def get_revisions(self, revids):
203
231
        return [self.get_revision(r) for r in revids]
229
257
                        ancestors=None):
230
258
        return GitVersionedFileChecker(self,
231
259
            text_key_references=text_key_references, ancestors=ancestors)
232
 
    
 
260
 
233
261
 
234
262
class GitVersionedFileChecker(repository._VersionedFileChecker):
235
263