/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 push.py

Fix compatibility with newer versions of Dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Push implementation that simply prints message saying push is not supported."""
18
18
 
19
19
from bzrlib import (
 
20
    errors,
20
21
    ui,
21
22
    )
22
23
from bzrlib.repository import (
29
30
from bzrlib.plugins.git.errors import (
30
31
    NoPushSupport,
31
32
    )
32
 
from bzrlib.plugins.git.mapping import (
33
 
    extract_unusual_modes,
34
 
    )
35
33
from bzrlib.plugins.git.object_store import (
36
34
    BazaarObjectStore,
37
35
    )
56
54
        """
57
55
        self.source = source
58
56
        self._object_store = store
59
 
        self._revids = set()
60
 
        self._sent_shas = set()
61
57
        self._pending = []
62
58
        self.pb = pb
63
59
 
64
60
    def import_revisions(self, revids):
65
 
        self._revids.update(revids)
66
61
        for i, revid in enumerate(revids):
67
62
            if self.pb:
68
63
                self.pb.update("pushing revisions", i, len(revids))
69
64
            git_commit = self.import_revision(revid)
70
65
            yield (revid, git_commit)
71
66
 
72
 
    def need_sha(self, sha):
73
 
        if sha in self._sent_shas:
74
 
            return False
75
 
        (type, (fileid, revid)) = self._object_store._idmap.lookup_git_sha(sha)
76
 
        assert type in ("blob", "tree")
77
 
        if revid in self._revids:
78
 
            # Not sent yet, and part of the set of revisions to send
79
 
            return True
80
 
        # Not changed in the revisions to send, so either not necessary
81
 
        # or already present remotely (as git doesn't do ghosts)
82
 
        return False
83
 
 
84
 
    def queue(self, sha, obj, path, ie=None, inv=None):
85
 
        if obj is None:
86
 
            obj = (ie, inv)
87
 
        self._pending.append((obj, path))
88
 
        self._sent_shas.add(sha)
89
 
 
90
67
    def import_revision(self, revid):
91
68
        """Import the gist of a revision into this Git repository.
92
69
 
93
70
        """
94
 
        inv = self.source.get_inventory(revid)
 
71
        tree = self._object_store.tree_cache.revision_tree(revid)
95
72
        rev = self.source.get_revision(revid)
96
 
        unusual_modes = extract_unusual_modes(rev)
97
 
        todo = [inv.root]
98
 
        tree_sha = None
99
 
        while todo:
100
 
            ie = todo.pop()
101
 
            (sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv, unusual_modes)
102
 
            if ie.parent_id is None:
103
 
                tree_sha = sha
104
 
            if not self.need_sha(sha):
105
 
                continue
106
 
            self.queue(sha, object, inv.id2path(ie.file_id), ie, inv)
107
 
            if ie.kind == "directory":
108
 
                todo.extend(ie.children.values())
109
 
        assert tree_sha is not None
110
 
        commit = self._object_store._get_commit(rev, tree_sha)
111
 
        self.queue(commit.id, commit, None)
 
73
        commit = None
 
74
        for path, obj, ie in self._object_store._revision_to_objects(rev, tree):
 
75
            if obj.type_name == "commit":
 
76
                commit = obj
 
77
            self._pending.append((obj, path))
112
78
        return commit.id
113
79
 
114
80
    def __len__(self):
115
81
        return len(self._pending)
116
82
 
117
83
    def __iter__(self):
118
 
        for i, (object, path) in enumerate(self._pending):
119
 
            if self.pb:
120
 
                self.pb.update("writing pack objects", i, len(self))
121
 
            if isinstance(object, tuple):
122
 
                object = self._object_store._get_ie_object(*object)
123
 
            yield (object, path)   
 
84
        return iter(self._pending)
124
85
 
125
86
 
126
87
class InterToGitRepository(InterRepository):
141
102
        """See InterRepository.copy_content."""
142
103
        self.fetch(revision_id, pb, find_ghosts=False)
143
104
 
144
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
 
105
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
145
106
            fetch_spec=None):
146
107
        raise NoPushSupport()
147
108
 
162
123
            pb.finished()
163
124
 
164
125
    def dfetch_refs(self, refs):
 
126
        old_refs = self.target._git.get_refs()
165
127
        new_refs = {}
166
128
        revidmap, gitidmap = self.dfetch(refs.values())
167
129
        for name, revid in refs.iteritems():
171
133
                gitid = self.source_store._lookup_revision_sha1(revid)
172
134
            self.target._git.refs[name] = gitid
173
135
            new_refs[name] = gitid
174
 
        return revidmap, new_refs
 
136
        return revidmap, old_refs, new_refs
175
137
 
176
138
    def dfetch(self, stop_revisions):
177
139
        """Import the gist of the ancestry of a particular revision."""
183
145
            def check_revid(revid):
184
146
                if revid == NULL_REVISION:
185
147
                    return True
186
 
                return (self.source_store._lookup_revision_sha1(revid) in target_store)
 
148
                try:
 
149
                    return (self.source_store._lookup_revision_sha1(revid) in target_store)
 
150
                except errors.NoSuchRevision:
 
151
                    # Ghost, can't dpush
 
152
                    return True
187
153
            todo = list(self.missing_revisions(stop_revisions, check_revid))
188
154
            pb = ui.ui_factory.nested_progress_bar()
189
155
            try:
193
159
                    new_bzr_revid = self.mapping.revision_id_foreign_to_bzr(git_commit)
194
160
                    revidmap[old_bzr_revid] = new_bzr_revid
195
161
                    gitidmap[old_bzr_revid] = git_commit
196
 
                target_store.add_objects(object_generator) 
 
162
                target_store.add_objects(object_generator)
197
163
            finally:
198
164
                pb.finished()
199
165
        finally:
203
169
    @staticmethod
204
170
    def is_compatible(source, target):
205
171
        """Be compatible with GitRepository."""
206
 
        return (not isinstance(source, GitRepository) and 
 
172
        return (not isinstance(source, GitRepository) and
207
173
                isinstance(target, LocalGitRepository))
208
174
 
209
175
 
212
178
    def dfetch_refs(self, new_refs):
213
179
        """Import the gist of the ancestry of a particular revision."""
214
180
        revidmap = {}
 
181
        old_refs = {}
215
182
        def determine_wants(refs):
216
183
            ret = {}
 
184
            old_refs.update(new_refs)
217
185
            for name, revid in new_refs.iteritems():
218
186
                ret[name] = self.source_store._lookup_revision_sha1(revid)
219
187
            return ret
223
191
                    self.source_store.generate_pack_contents)
224
192
        finally:
225
193
            self.source.unlock()
226
 
        return revidmap, new_refs
 
194
        return revidmap, old_refs, new_refs
227
195
 
228
196
    @staticmethod
229
197
    def is_compatible(source, target):
230
198
        """Be compatible with GitRepository."""
231
 
        return (not isinstance(source, GitRepository) and 
 
199
        return (not isinstance(source, GitRepository) and
232
200
                isinstance(target, RemoteGitRepository))