/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

Add simple HACKING document.

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
 
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
 
101
106
 
102
107
    def all_revision_ids(self):
103
108
        ret = set([revision.NULL_REVISION])
104
 
        if self._git.heads() == []:
 
109
        heads = self._git.heads()
 
110
        if heads == {}:
105
111
            return ret
106
 
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in self._git.heads()]
 
112
        bzr_heads = [self.get_mapping().revision_id_foreign_to_bzr(h) for h in heads.itervalues()]
107
113
        ret = set(bzr_heads)
108
114
        graph = self.get_graph()
109
115
        for rev, parents in graph.iter_ancestry(bzr_heads):
139
145
        """See Repository.get_ancestry().
140
146
        """
141
147
        if revision_id is None:
142
 
            return self._all_revision_ids()
 
148
            return [None, revision.NULL_REVISION] + self._all_revision_ids()
143
149
        assert isinstance(revision_id, str)
144
150
        ancestry = []
145
151
        graph = self.get_graph()
146
152
        for rev, parents in graph.iter_ancestry([revision_id]):
147
 
            if rev == revision.NULL_REVISION:
148
 
                rev = None
149
153
            ancestry.append(rev)
150
154
        ancestry.reverse()
151
 
        return ancestry
152
 
 
153
 
    def import_revision_gist(self, source, revid):
154
 
        pass
 
155
        return [None] + ancestry
 
156
 
 
157
    def import_revision_gist(self, source, revid, parent_lookup):
 
158
        """Import the gist of a revision into this Git repository.
 
159
 
 
160
        """
 
161
        objects = []
 
162
        rev = source.get_revision(revid)
 
163
        for sha, object, path in inventory_to_tree_and_blobs(source, None, revid):
 
164
            if path == "":
 
165
                tree_sha = sha
 
166
            objects.append((object, path))
 
167
        commit = revision_to_commit(rev, tree_sha, parent_lookup)
 
168
        objects.append((commit, None))
 
169
        self._git.object_store.add_objects(objects)
 
170
        return commit.sha().hexdigest()
155
171
 
156
172
    def dfetch(self, source, stop_revision):
 
173
        """Import the gist of the ancestry of a particular revision."""
157
174
        if stop_revision is None:
158
175
            raise NotImplementedError
159
176
        revidmap = {}
 
177
        gitidmap = {}
160
178
        todo = []
161
 
        source.lock_read()
 
179
        source.lock_write()
162
180
        try:
163
181
            graph = source.get_graph()
164
 
            for revid, parents in graph.iter_ancestry([stop_revision]):
 
182
            ancestry = [x for x in source.get_ancestry(stop_revision) if x is not None]
 
183
            for revid in graph.iter_topo_order(ancestry):
165
184
                if not self.has_revision(revid):
166
185
                    todo.append(revid)
167
186
            pb = ui.ui_factory.nested_progress_bar()
168
187
            try:
169
 
                for i, revid in enumerate(reversed(todo)):
 
188
                for i, revid in enumerate(todo):
170
189
                    pb.update("pushing revisions", i, len(todo))
171
 
                    revidmap[revid] = self.import_revision_gist(source, revid)
 
190
                    git_commit = self.import_revision_gist(source, revid, gitidmap.__getitem__)
 
191
                    gitidmap[revid] = git_commit
 
192
                    git_revid = self.get_mapping().revision_id_foreign_to_bzr(git_commit)
 
193
                    revidmap[revid] = git_revid
172
194
            finally:
173
195
                pb.finished()
 
196
            source.fetch(self, revision_id=revidmap[stop_revision])
174
197
        finally:
175
198
            source.unlock()
176
199
        return revidmap
239
262
    def set_make_working_trees(self, trees):
240
263
        pass
241
264
 
242
 
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
265
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
243
266
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
244
267
 
245
268