/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

Fix tests, split up InterGitNonGitRepository.

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>
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
16
17
 
17
18
"""An adapter between a Git Repository and a Bazaar Branch"""
18
19
 
19
 
import os
20
 
import time
21
 
 
22
20
import bzrlib
23
21
from bzrlib import (
24
22
    errors,
32
30
    urlutils,
33
31
    )
34
32
from bzrlib.foreign import (
35
 
        ForeignRepository,
36
 
        )
37
 
from bzrlib.trace import mutter
38
 
from bzrlib.transport import get_transport
 
33
    ForeignRepository,
 
34
    )
 
35
from bzrlib.trace import (
 
36
    mutter,
 
37
    )
 
38
from bzrlib.transport import (
 
39
    get_transport,
 
40
    )
39
41
 
40
42
from bzrlib.plugins.git.foreign import (
41
43
    versionedfiles,
42
44
    )
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
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 (
 
52
    GitTexts,
 
53
    )
45
54
 
46
55
import dulwich as git
 
56
import os
 
57
import time
47
58
 
48
59
 
49
60
class GitTags(object):
61
72
    _serializer = None
62
73
 
63
74
    def __init__(self, gitdir, lockfiles):
64
 
        ForeignRepository.__init__(self, GitFormat(), gitdir, lockfiles)
65
 
        from bzrlib.plugins.git import fetch
66
 
        repository.InterRepository.register_optimiser(fetch.InterGitRepository)
67
 
        repository.InterRepository.register_optimiser(fetch.InterGitNonGitRepository)
 
75
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
 
76
            lockfiles)
 
77
        from bzrlib.plugins.git import fetch, push
 
78
        for optimiser in [fetch.InterRemoteGitNonGitRepository, 
 
79
                          fetch.InterLocalGitNonGitRepository,
 
80
                          fetch.InterGitRepository,
 
81
                          push.InterToGitRepository]:
 
82
            repository.InterRepository.register_optimiser(optimiser)
68
83
 
69
84
    def is_shared(self):
70
85
        return True
84
99
 
85
100
 
86
101
class LocalGitRepository(GitRepository):
 
102
    """Git repository on the file system."""
87
103
 
88
104
    def __init__(self, gitdir, lockfiles):
89
105
        # FIXME: This also caches negatives. Need to be more careful 
101
117
 
102
118
    def all_revision_ids(self):
103
119
        ret = set([revision.NULL_REVISION])
104
 
        if self._git.heads() == []:
 
120
        heads = self._git.heads()
 
121
        if heads == {}:
105
122
            return ret
106
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
 
123
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
107
124
        ret = set(bzr_heads)
108
125
        graph = self.get_graph()
109
126
        for rev, parents in graph.iter_ancestry(bzr_heads):
139
156
        """See Repository.get_ancestry().
140
157
        """
141
158
        if revision_id is None:
142
 
            return self._all_revision_ids()
 
159
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
143
160
        assert isinstance(revision_id, str)
144
161
        ancestry = []
145
162
        graph = self.get_graph()
146
163
        for rev, parents in graph.iter_ancestry([revision_id]):
147
 
            if rev == revision.NULL_REVISION:
148
 
                rev = None
149
164
            ancestry.append(rev)
150
165
        ancestry.reverse()
151
 
        return ancestry
 
166
        return [None] + ancestry
152
167
 
153
168
    def import_revision_gist(self, source, revid, parent_lookup):
154
 
        """Impor the gist of another revision into this Git repository.
 
169
        """Import the gist of a revision into this Git repository.
155
170
 
156
171
        """
157
172
        objects = []
166
181
        return commit.sha().hexdigest()
167
182
 
168
183
    def dfetch(self, source, stop_revision):
 
184
        """Import the gist of the ancestry of a particular revision."""
169
185
        if stop_revision is None:
170
186
            raise NotImplementedError
171
187
        revidmap = {}
172
188
        gitidmap = {}
 
189
        def parent_lookup(revid):
 
190
            try:
 
191
                return gitidmap[revid]
 
192
            except KeyError:
 
193
                return self.lookup_git_revid(revid)[0]
173
194
        todo = []
174
195
        source.lock_write()
175
196
        try:
182
203
            try:
183
204
                for i, revid in enumerate(todo):
184
205
                    pb.update("pushing revisions", i, len(todo))
185
 
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
206
                    git_commit = self.import_revision_gist(source, revid,
 
207
                        parent_lookup)
186
208
                    gitidmap[revid] = git_commit
187
 
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
209
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(
 
210
                        git_commit)
188
211
                    revidmap[revid] = git_revid
189
212
            finally:
190
213
                pb.finished()
242
265
 
243
266
    def revision_tree(self, revision_id):
244
267
        revision_id = revision.ensure_null(revision_id)
245
 
 
246
268
        if revision_id == revision.NULL_REVISION:
247
269
            inv = inventory.Inventory(root_id=None)
248
270
            inv.revision_id = revision_id
249
271
            return revisiontree.RevisionTree(self, inv, revision_id)
250
 
 
251
272
        return GitRevisionTree(self, revision_id)
252
273
 
253
274
    def get_inventory(self, revision_id):
257
278
    def set_make_working_trees(self, trees):
258
279
        pass
259
280
 
260
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
281
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
282
        progress=None):
261
283
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
262
284
 
263
285
 
323
345
                self._build_inventory(hexsha, child_ie, child_path)
324
346
 
325
347
 
326
 
class GitFormat(object):
 
348
class GitRepositoryFormat(repository.RepositoryFormat):
327
349
 
328
350
    supports_tree_reference = False
329
351
    rich_root_data = True