/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

Support bzr.dev.

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
 
 
20
import dulwich as git
19
21
import os
20
22
import time
21
23
 
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
 
45
from bzrlib.plugins.git.mapping import (
 
46
    default_mapping,
 
47
    inventory_to_tree_and_blobs,
 
48
    mapping_registry,
 
49
    revision_to_commit,
 
50
    )
44
51
from bzrlib.plugins.git.versionedfiles import GitTexts
45
52
 
46
 
import dulwich as git
47
 
 
48
53
 
49
54
class GitTags(object):
50
55
 
63
68
    def __init__(self, gitdir, lockfiles):
64
69
        ForeignRepository.__init__(self, GitFormat(), gitdir, lockfiles)
65
70
        from bzrlib.plugins.git import fetch
66
 
        repository.InterRepository.register_optimiser(fetch.InterGitRepository)
67
 
        repository.InterRepository.register_optimiser(fetch.InterGitNonGitRepository)
 
71
        for optimiser in [fetch.InterGitRepository, 
 
72
                          fetch.InterGitNonGitRepository]:
 
73
            repository.InterRepository.register_optimiser(optimiser)
68
74
 
69
75
    def is_shared(self):
70
76
        return True
84
90
 
85
91
 
86
92
class LocalGitRepository(GitRepository):
 
93
    """Git repository on the file system."""
87
94
 
88
95
    def __init__(self, gitdir, lockfiles):
89
96
        # FIXME: This also caches negatives. Need to be more careful 
101
108
 
102
109
    def all_revision_ids(self):
103
110
        ret = set([revision.NULL_REVISION])
104
 
        if self._git.heads() == []:
 
111
        heads = self._git.heads()
 
112
        if heads == {}:
105
113
            return ret
106
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
 
114
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
107
115
        ret = set(bzr_heads)
108
116
        graph = self.get_graph()
109
117
        for rev, parents in graph.iter_ancestry(bzr_heads):
139
147
        """See Repository.get_ancestry().
140
148
        """
141
149
        if revision_id is None:
142
 
            return self._all_revision_ids()
 
150
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
143
151
        assert isinstance(revision_id, str)
144
152
        ancestry = []
145
153
        graph = self.get_graph()
146
154
        for rev, parents in graph.iter_ancestry([revision_id]):
147
 
            if rev == revision.NULL_REVISION:
148
 
                rev = None
149
155
            ancestry.append(rev)
150
156
        ancestry.reverse()
151
 
        return ancestry
 
157
        return [None] + ancestry
152
158
 
153
159
    def import_revision_gist(self, source, revid, parent_lookup):
154
 
        """Impor the gist of another revision into this Git repository.
 
160
        """Import the gist of a revision into this Git repository.
155
161
 
156
162
        """
157
163
        objects = []
166
172
        return commit.sha().hexdigest()
167
173
 
168
174
    def dfetch(self, source, stop_revision):
 
175
        """Import the gist of the ancestry of a particular revision."""
169
176
        if stop_revision is None:
170
177
            raise NotImplementedError
171
178
        revidmap = {}
182
189
            try:
183
190
                for i, revid in enumerate(todo):
184
191
                    pb.update("pushing revisions", i, len(todo))
185
 
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
192
                    git_commit = self.import_revision_gist(source, revid,
 
193
                        gitidmap.__getitem__)
186
194
                    gitidmap[revid] = git_commit
187
 
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
195
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(
 
196
                        git_commit)
188
197
                    revidmap[revid] = git_revid
189
198
            finally:
190
199
                pb.finished()
242
251
 
243
252
    def revision_tree(self, revision_id):
244
253
        revision_id = revision.ensure_null(revision_id)
245
 
 
246
254
        if revision_id == revision.NULL_REVISION:
247
255
            inv = inventory.Inventory(root_id=None)
248
256
            inv.revision_id = revision_id
249
257
            return revisiontree.RevisionTree(self, inv, revision_id)
250
 
 
251
258
        return GitRevisionTree(self, revision_id)
252
259
 
253
260
    def get_inventory(self, revision_id):
257
264
    def set_make_working_trees(self, trees):
258
265
        pass
259
266
 
260
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
267
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
268
        progress=None):
261
269
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
262
270
 
263
271