/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

  • Committer: Jelmer Vernooij
  • Date: 2009-03-27 13:04:03 UTC
  • mto: (0.200.305 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090327130403-6imiy7o0amdmx6yn
Fix versionedfiles.

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.InterGitRepository, 
 
79
                          fetch.InterGitNonGitRepository,
 
80
                          push.InterToGitRepository]:
 
81
            repository.InterRepository.register_optimiser(optimiser)
68
82
 
69
83
    def is_shared(self):
70
84
        return True
84
98
 
85
99
 
86
100
class LocalGitRepository(GitRepository):
 
101
    """Git repository on the file system."""
87
102
 
88
103
    def __init__(self, gitdir, lockfiles):
89
104
        # FIXME: This also caches negatives. Need to be more careful 
101
116
 
102
117
    def all_revision_ids(self):
103
118
        ret = set([revision.NULL_REVISION])
104
 
        if self._git.heads() == []:
 
119
        heads = self._git.heads()
 
120
        if heads == {}:
105
121
            return ret
106
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
 
122
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
107
123
        ret = set(bzr_heads)
108
124
        graph = self.get_graph()
109
125
        for rev, parents in graph.iter_ancestry(bzr_heads):
139
155
        """See Repository.get_ancestry().
140
156
        """
141
157
        if revision_id is None:
142
 
            return self._all_revision_ids()
 
158
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
143
159
        assert isinstance(revision_id, str)
144
160
        ancestry = []
145
161
        graph = self.get_graph()
146
162
        for rev, parents in graph.iter_ancestry([revision_id]):
147
 
            if rev == revision.NULL_REVISION:
148
 
                rev = None
149
163
            ancestry.append(rev)
150
164
        ancestry.reverse()
151
 
        return ancestry
 
165
        return [None] + ancestry
152
166
 
153
167
    def import_revision_gist(self, source, revid, parent_lookup):
154
 
        """Impor the gist of another revision into this Git repository.
 
168
        """Import the gist of a revision into this Git repository.
155
169
 
156
170
        """
157
171
        objects = []
166
180
        return commit.sha().hexdigest()
167
181
 
168
182
    def dfetch(self, source, stop_revision):
 
183
        """Import the gist of the ancestry of a particular revision."""
169
184
        if stop_revision is None:
170
185
            raise NotImplementedError
171
186
        revidmap = {}
172
187
        gitidmap = {}
 
188
        def parent_lookup(revid):
 
189
            try:
 
190
                return gitidmap[revid]
 
191
            except KeyError:
 
192
                return self.lookup_git_revid(revid)[0]
173
193
        todo = []
174
194
        source.lock_write()
175
195
        try:
182
202
            try:
183
203
                for i, revid in enumerate(todo):
184
204
                    pb.update("pushing revisions", i, len(todo))
185
 
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
205
                    git_commit = self.import_revision_gist(source, revid,
 
206
                        parent_lookup)
186
207
                    gitidmap[revid] = git_commit
187
 
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
208
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(
 
209
                        git_commit)
188
210
                    revidmap[revid] = git_revid
189
211
            finally:
190
212
                pb.finished()
242
264
 
243
265
    def revision_tree(self, revision_id):
244
266
        revision_id = revision.ensure_null(revision_id)
245
 
 
246
267
        if revision_id == revision.NULL_REVISION:
247
268
            inv = inventory.Inventory(root_id=None)
248
269
            inv.revision_id = revision_id
249
270
            return revisiontree.RevisionTree(self, inv, revision_id)
250
 
 
251
271
        return GitRevisionTree(self, revision_id)
252
272
 
253
273
    def get_inventory(self, revision_id):
257
277
    def set_make_working_trees(self, trees):
258
278
        pass
259
279
 
260
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
280
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
281
        progress=None):
261
282
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
262
283
 
263
284
 
323
344
                self._build_inventory(hexsha, child_ie, child_path)
324
345
 
325
346
 
326
 
class GitFormat(object):
 
347
class GitRepositoryFormat(repository.RepositoryFormat):
327
348
 
328
349
    supports_tree_reference = False
329
350
    rich_root_data = True