/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 fetch.py

Merge thin-pack work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib import osutils, ui, urlutils
18
 
from bzrlib.errors import InvalidRevisionId
 
18
from bzrlib.errors import InvalidRevisionId, NoSuchRevision
19
19
from bzrlib.inventory import Inventory
20
20
from bzrlib.repository import InterRepository
21
21
from bzrlib.trace import info
26
26
        GitRepository, 
27
27
        GitFormat,
28
28
        )
 
29
from bzrlib.plugins.git.shamap import GitObjectConverter
29
30
from bzrlib.plugins.git.remote import RemoteGitRepository
30
31
 
31
32
import dulwich as git
126
127
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
127
128
 
128
129
 
129
 
def import_git_objects(repo, mapping, object_iter, pb=None):
 
130
def import_git_objects(repo, mapping, object_iter, target_git_object_retriever, 
 
131
        pb=None):
130
132
    """Import a set of git objects into a bzr repository.
131
133
 
132
134
    :param repo: Bazaar repository
159
161
        def lookup_object(sha):
160
162
            if sha in object_iter:
161
163
                return object_iter[sha]
162
 
            return reconstruct_git_object(repo, mapping, sha)
 
164
            return target_git_object_retriever(sha)
163
165
        parent_invs = [repo.get_inventory(r) for r in rev.parent_ids]
164
166
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, 
165
167
            lookup_object)
166
168
        repo.add_revision(rev.revision_id, rev, inv)
167
169
 
168
170
 
169
 
def reconstruct_git_commit(repo, rev):
170
 
    raise NotImplementedError(self.reconstruct_git_commit)
171
 
 
172
 
 
173
171
def reconstruct_git_object(repo, mapping, sha):
174
 
    # Commit
175
 
    revid = mapping.revision_id_foreign_to_bzr(sha)
176
 
    try:
177
 
        rev = repo.get_revision(revid)
178
 
    except NoSuchRevision:
179
 
        pass
180
 
    else:
181
 
        return reconstruct_git_commit(rev)
 
172
    import pdb; pdb.set_trace()
182
173
 
183
174
    # TODO: Tree
184
175
    # TODO: Blob
204
195
        create_pb = None
205
196
        if pb is None:
206
197
            create_pb = pb = ui.ui_factory.nested_progress_bar()
 
198
        target_git_object_retriever = GitObjectConverter(self.target, mapping)
 
199
        
207
200
        try:
208
201
            self.target.lock_write()
209
202
            try:
210
203
                self.target.start_write_group()
211
204
                try:
212
205
                    objects_iter = self.source.fetch_objects(determine_wants, 
213
 
                                graph_walker, progress)
214
 
                    import_git_objects(self.target, mapping, objects_iter, pb)
 
206
                                graph_walker, 
 
207
                                target_git_object_retriever.__getitem__, 
 
208
                                progress)
 
209
                    import_git_objects(self.target, mapping, objects_iter, 
 
210
                            target_git_object_retriever, pb)
215
211
                finally:
216
212
                    self.target.commit_write_group()
217
213
            finally: