/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

Cope with new member variables in RepositoryFormat.

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,
40
38
from bzrlib.plugins.git.foreign import (
41
39
    versionedfiles,
42
40
    )
43
 
from bzrlib.plugins.git.mapping import default_mapping, mapping_registry, inventory_to_tree_and_blobs, revision_to_commit
 
41
from bzrlib.plugins.git.mapping import (
 
42
    default_mapping,
 
43
    inventory_to_tree_and_blobs,
 
44
    mapping_registry,
 
45
    revision_to_commit,
 
46
    )
44
47
from bzrlib.plugins.git.versionedfiles import GitTexts
45
48
 
46
49
import dulwich as git
 
50
import os
 
51
import time
47
52
 
48
53
 
49
54
class GitTags(object):
61
66
    _serializer = None
62
67
 
63
68
    def __init__(self, gitdir, lockfiles):
64
 
        ForeignRepository.__init__(self, GitFormat(), gitdir, lockfiles)
 
69
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
 
70
            lockfiles)
65
71
        from bzrlib.plugins.git import fetch
66
 
        repository.InterRepository.register_optimiser(fetch.InterGitRepository)
67
 
        repository.InterRepository.register_optimiser(fetch.InterGitNonGitRepository)
 
72
        for optimiser in [fetch.InterGitRepository, 
 
73
                          fetch.InterGitNonGitRepository]:
 
74
            repository.InterRepository.register_optimiser(optimiser)
68
75
 
69
76
    def is_shared(self):
70
77
        return True
84
91
 
85
92
 
86
93
class LocalGitRepository(GitRepository):
 
94
    """Git repository on the file system."""
87
95
 
88
96
    def __init__(self, gitdir, lockfiles):
89
97
        # FIXME: This also caches negatives. Need to be more careful 
101
109
 
102
110
    def all_revision_ids(self):
103
111
        ret = set([revision.NULL_REVISION])
104
 
        if self._git.heads() == []:
 
112
        heads = self._git.heads()
 
113
        if heads == {}:
105
114
            return ret
106
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
 
115
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
107
116
        ret = set(bzr_heads)
108
117
        graph = self.get_graph()
109
118
        for rev, parents in graph.iter_ancestry(bzr_heads):
139
148
        """See Repository.get_ancestry().
140
149
        """
141
150
        if revision_id is None:
142
 
            return self._all_revision_ids()
 
151
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
143
152
        assert isinstance(revision_id, str)
144
153
        ancestry = []
145
154
        graph = self.get_graph()
146
155
        for rev, parents in graph.iter_ancestry([revision_id]):
147
 
            if rev == revision.NULL_REVISION:
148
 
                rev = None
149
156
            ancestry.append(rev)
150
157
        ancestry.reverse()
151
 
        return ancestry
 
158
        return [None] + ancestry
152
159
 
153
160
    def import_revision_gist(self, source, revid, parent_lookup):
154
 
        """Impor the gist of another revision into this Git repository.
 
161
        """Import the gist of a revision into this Git repository.
155
162
 
156
163
        """
157
164
        objects = []
166
173
        return commit.sha().hexdigest()
167
174
 
168
175
    def dfetch(self, source, stop_revision):
 
176
        """Import the gist of the ancestry of a particular revision."""
169
177
        if stop_revision is None:
170
178
            raise NotImplementedError
171
179
        revidmap = {}
172
180
        gitidmap = {}
 
181
        def parent_lookup(revid):
 
182
            try:
 
183
                return gitidmap[revid]
 
184
            except KeyError:
 
185
                return self.lookup_git_revid(revid)[0]
173
186
        todo = []
174
187
        source.lock_write()
175
188
        try:
182
195
            try:
183
196
                for i, revid in enumerate(todo):
184
197
                    pb.update("pushing revisions", i, len(todo))
185
 
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
198
                    git_commit = self.import_revision_gist(source, revid,
 
199
                        parent_lookup)
186
200
                    gitidmap[revid] = git_commit
187
 
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
201
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(
 
202
                        git_commit)
188
203
                    revidmap[revid] = git_revid
189
204
            finally:
190
205
                pb.finished()
242
257
 
243
258
    def revision_tree(self, revision_id):
244
259
        revision_id = revision.ensure_null(revision_id)
245
 
 
246
260
        if revision_id == revision.NULL_REVISION:
247
261
            inv = inventory.Inventory(root_id=None)
248
262
            inv.revision_id = revision_id
249
263
            return revisiontree.RevisionTree(self, inv, revision_id)
250
 
 
251
264
        return GitRevisionTree(self, revision_id)
252
265
 
253
266
    def get_inventory(self, revision_id):
257
270
    def set_make_working_trees(self, trees):
258
271
        pass
259
272
 
260
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
273
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
274
        progress=None):
261
275
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
262
276
 
263
277
 
323
337
                self._build_inventory(hexsha, child_ie, child_path)
324
338
 
325
339
 
326
 
class GitFormat(object):
 
340
class GitRepositoryFormat(repository.RepositoryFormat):
327
341
 
328
342
    supports_tree_reference = False
329
343
    rich_root_data = True