/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

Try to import nothing other than __init__ when not opening git repositories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2007 Canonical Ltd
2
 
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
17
16
 
18
17
"""An adapter between a Git Repository and a Bazaar Branch"""
19
18
 
20
 
import dulwich as git
21
19
import os
22
20
import time
23
21
 
24
22
import bzrlib
25
23
from bzrlib import (
 
24
    deprecated_graph,
26
25
    errors,
27
26
    graph,
28
27
    inventory,
30
29
    repository,
31
30
    revision,
32
31
    revisiontree,
33
 
    ui,
34
32
    urlutils,
 
33
    versionedfile,
35
34
    )
36
35
from bzrlib.foreign import (
37
36
        ForeignRepository,
42
41
from bzrlib.plugins.git.foreign import (
43
42
    versionedfiles,
44
43
    )
45
 
from bzrlib.plugins.git.mapping import (
46
 
    default_mapping,
47
 
    inventory_to_tree_and_blobs,
48
 
    mapping_registry,
49
 
    revision_to_commit,
50
 
    )
51
 
from bzrlib.plugins.git.versionedfiles import GitTexts
 
44
from bzrlib.plugins.git.mapping import default_mapping, mapping_registry
 
45
 
 
46
import dulwich as git
52
47
 
53
48
 
54
49
class GitTags(object):
100
95
        self.texts = None
101
96
        self.signatures = versionedfiles.VirtualSignatureTexts(self)
102
97
        self.revisions = versionedfiles.VirtualRevisionTexts(self)
103
 
        self.inventories = versionedfiles.VirtualInventoryTexts(self)
104
 
        self.texts = GitTexts(self)
105
98
        self.tags = GitTags(self._git.get_tags())
106
99
 
107
100
    def all_revision_ids(self):
108
101
        ret = set([revision.NULL_REVISION])
109
 
        heads = self._git.heads()
110
 
        if heads == {}:
 
102
        if self._git.heads() == []:
111
103
            return ret
112
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
 
104
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
113
105
        ret = set(bzr_heads)
114
106
        graph = self.get_graph()
115
107
        for rev, parents in graph.iter_ancestry(bzr_heads):
145
137
        """See Repository.get_ancestry().
146
138
        """
147
139
        if revision_id is None:
148
 
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
 
140
            return self._all_revision_ids()
149
141
        assert isinstance(revision_id, str)
150
142
        ancestry = []
151
143
        graph = self.get_graph()
152
144
        for rev, parents in graph.iter_ancestry([revision_id]):
 
145
            if rev == revision.NULL_REVISION:
 
146
                rev = None
153
147
            ancestry.append(rev)
154
148
        ancestry.reverse()
155
 
        return [None] + ancestry
156
 
 
157
 
    def import_revision_gist(self, source, revid, parent_lookup):
158
 
        """Import the gist of a revision into this Git repository.
159
 
 
160
 
        """
161
 
        objects = []
162
 
        rev = source.get_revision(revid)
163
 
        for sha, object, path in inventory_to_tree_and_blobs(source, None, revid):
164
 
            if path == "":
165
 
                tree_sha = sha
166
 
            objects.append((object, path))
167
 
        commit = revision_to_commit(rev, tree_sha, parent_lookup)
168
 
        objects.append((commit, None))
169
 
        self._git.object_store.add_objects(objects)
170
 
        return commit.sha().hexdigest()
171
 
 
172
 
    def dfetch(self, source, stop_revision):
173
 
        """Import the gist of the ancestry of a particular revision."""
174
 
        if stop_revision is None:
175
 
            raise NotImplementedError
176
 
        revidmap = {}
177
 
        gitidmap = {}
178
 
        todo = []
179
 
        source.lock_write()
180
 
        try:
181
 
            graph = source.get_graph()
182
 
            ancestry = [x for x in source.get_ancestry(stop_revision) if x is not None]
183
 
            for revid in graph.iter_topo_order(ancestry):
184
 
                if not self.has_revision(revid):
185
 
                    todo.append(revid)
186
 
            pb = ui.ui_factory.nested_progress_bar()
187
 
            try:
188
 
                for i, revid in enumerate(todo):
189
 
                    pb.update("pushing revisions", i, len(todo))
190
 
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
191
 
                    gitidmap[revid] = git_commit
192
 
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
193
 
                    revidmap[revid] = git_revid
194
 
            finally:
195
 
                pb.finished()
196
 
            source.fetch(self, revision_id=revidmap[stop_revision])
197
 
        finally:
198
 
            source.unlock()
199
 
        return revidmap
 
149
        return ancestry
200
150
 
201
151
    def get_signature_text(self, revision_id):
202
152
        raise errors.NoSuchRevision(self, revision_id)
262
212
    def set_make_working_trees(self, trees):
263
213
        pass
264
214
 
265
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
215
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
266
216
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
267
217
 
268
218