/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

Partially fix pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import bzrlib
23
23
from bzrlib import (
24
 
    deprecated_graph,
25
24
    errors,
26
25
    graph,
27
26
    inventory,
29
28
    repository,
30
29
    revision,
31
30
    revisiontree,
 
31
    ui,
32
32
    urlutils,
33
 
    versionedfile,
34
33
    )
35
34
from bzrlib.foreign import (
36
35
        ForeignRepository,
41
40
from bzrlib.plugins.git.foreign import (
42
41
    versionedfiles,
43
42
    )
44
 
from bzrlib.plugins.git.mapping import default_mapping
 
43
from bzrlib.plugins.git.mapping import default_mapping, mapping_registry, inventory_to_tree_and_blobs, revision_to_commit
 
44
from bzrlib.plugins.git.versionedfiles import GitTexts
45
45
 
46
 
from bzrlib.plugins.git import git
 
46
import dulwich as git
47
47
 
48
48
 
49
49
class GitTags(object):
95
95
        self.texts = None
96
96
        self.signatures = versionedfiles.VirtualSignatureTexts(self)
97
97
        self.revisions = versionedfiles.VirtualRevisionTexts(self)
 
98
        self.inventories = versionedfiles.VirtualInventoryTexts(self)
 
99
        self.texts = GitTexts(self)
98
100
        self.tags = GitTags(self._git.get_tags())
99
101
 
100
102
    def all_revision_ids(self):
125
127
            if revision_id == revision.NULL_REVISION:
126
128
                parent_map[revision_id] = ()
127
129
                continue
128
 
            hexsha = self.lookup_git_revid(revision_id, self.get_mapping())
 
130
            hexsha, mapping = self.lookup_git_revid(revision_id)
129
131
            commit  = self._git.commit(hexsha)
130
132
            if commit is None:
131
133
                continue
132
134
            else:
133
 
                parent_map[revision_id] = [self.get_mapping().revision_id_foreign_to_bzr(p) for p in commit.parents]
 
135
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
134
136
        return parent_map
135
137
 
136
138
    def get_ancestry(self, revision_id, topo_sorted=True):
148
150
        ancestry.reverse()
149
151
        return ancestry
150
152
 
 
153
    def import_revision_gist(self, source, revid, parent_lookup):
 
154
        """Impor the gist of another revision into this Git repository.
 
155
 
 
156
        """
 
157
        objects = []
 
158
        rev = source.get_revision(revid)
 
159
        for sha, object, path in inventory_to_tree_and_blobs(source, None, revid):
 
160
            if path == "":
 
161
                tree_sha = sha
 
162
            objects.append((object, path))
 
163
        commit = revision_to_commit(rev, tree_sha, parent_lookup)
 
164
        objects.append((commit, None))
 
165
        self._git.object_store.add_objects(objects)
 
166
        return commit.sha().hexdigest()
 
167
 
 
168
    def dfetch(self, source, stop_revision):
 
169
        if stop_revision is None:
 
170
            raise NotImplementedError
 
171
        revidmap = {}
 
172
        gitidmap = {}
 
173
        todo = []
 
174
        source.lock_write()
 
175
        try:
 
176
            graph = source.get_graph()
 
177
            ancestry = [x for x in source.get_ancestry(stop_revision) if x is not None]
 
178
            for revid in graph.iter_topo_order(ancestry):
 
179
                if not self.has_revision(revid):
 
180
                    todo.append(revid)
 
181
            pb = ui.ui_factory.nested_progress_bar()
 
182
            try:
 
183
                for i, revid in enumerate(todo):
 
184
                    pb.update("pushing revisions", i, len(todo))
 
185
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
186
                    gitidmap[revid] = git_commit
 
187
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
188
                    revidmap[revid] = git_revid
 
189
            finally:
 
190
                pb.finished()
 
191
            source.fetch(self, revision_id=revidmap[stop_revision])
 
192
        finally:
 
193
            source.unlock()
 
194
        return revidmap
 
195
 
151
196
    def get_signature_text(self, revision_id):
152
197
        raise errors.NoSuchRevision(self, revision_id)
153
198
 
163
208
    def has_signature_for_revision_id(self, revision_id):
164
209
        return False
165
210
 
166
 
    def lookup_git_revid(self, bzr_revid, mapping):
 
211
    def lookup_git_revid(self, bzr_revid):
167
212
        try:
168
 
            return mapping.revision_id_bzr_to_foreign(bzr_revid)
 
213
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
169
214
        except errors.InvalidRevisionId:
170
215
            raise errors.NoSuchRevision(self, bzr_revid)
171
216
 
172
217
    def get_revision(self, revision_id):
173
 
        git_commit_id = self.lookup_git_revid(revision_id, self.get_mapping())
 
218
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
174
219
        try:
175
220
            commit = self._git.commit(git_commit_id)
176
221
        except KeyError:
177
222
            raise errors.NoSuchRevision(self, revision_id)
178
223
        # print "fetched revision:", git_commit_id
179
 
        revision = self.get_mapping().import_commit(commit)
 
224
        revision = mapping.import_commit(commit)
180
225
        assert revision is not None
181
226
        return revision
182
227
 
203
248
            inv.revision_id = revision_id
204
249
            return revisiontree.RevisionTree(self, inv, revision_id)
205
250
 
206
 
        return GitRevisionTree(self, self.get_mapping(), revision_id)
 
251
        return GitRevisionTree(self, revision_id)
207
252
 
208
253
    def get_inventory(self, revision_id):
209
254
        assert revision_id != None
212
257
    def set_make_working_trees(self, trees):
213
258
        pass
214
259
 
215
 
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
260
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
216
261
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
217
262
 
218
263
 
219
264
class GitRevisionTree(revisiontree.RevisionTree):
220
265
 
221
 
    def __init__(self, repository, mapping, revision_id):
 
266
    def __init__(self, repository, revision_id):
222
267
        self._repository = repository
223
268
        self.revision_id = revision_id
224
269
        assert isinstance(revision_id, str)
225
 
        self.mapping = mapping
226
 
        git_id = repository.lookup_git_revid(revision_id, self.mapping)
 
270
        git_id, self.mapping = repository.lookup_git_revid(revision_id)
227
271
        try:
228
272
            commit = repository._git.commit(git_id)
229
273
        except KeyError, r: