/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

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    errors,
21
21
    ui,
22
22
    )
23
 
from bzrlib.graph import (
24
 
    PendingAncestryResult,
25
 
    )
26
23
from bzrlib.repository import (
27
24
    InterRepository,
28
25
    )
116
113
    def dfetch_refs(self, update_refs):
117
114
        """Fetch non-roundtripped revisions into the target repository.
118
115
 
119
 
        :param update_refs: Generate refs to fetch. Receives dictionary 
 
116
        :param update_refs: Generate refs to fetch. Receives dictionary
120
117
            with old names to old git shas. Should return a dictionary
121
118
            of new names to Bazaar revision ids.
122
119
        :return: revision id map, old refs dictionary and new refs dictionary
126
123
    def fetch_refs(self, update_refs):
127
124
        """Fetch possibly roundtripped revisions into the target repository.
128
125
 
129
 
        :param update_refs: Generate refs to fetch. Receives dictionary 
130
 
            with old refs (git shas), returns dictionary of new names to 
 
126
        :param update_refs: Generate refs to fetch. Receives dictionary
 
127
            with old refs (git shas), returns dictionary of new names to
131
128
            git shas.
132
129
        :return: old refs, new refs
133
130
        """
142
139
        self.target_store = self.target._git.object_store
143
140
        self.target_refs = self.target._git.refs
144
141
 
145
 
    def _revision_needs_fetching(self, revid):
 
142
    def _revision_needs_fetching(self, sha_id, revid):
146
143
        if revid == NULL_REVISION:
147
144
            return False
148
 
        try:
149
 
            sha_id = self.source_store._lookup_revision_sha1(revid)
150
 
        except KeyError:
151
 
            raise errors.NoSuchRevision(self.source, revid)
 
145
        if sha_id is None:
 
146
            try:
 
147
                sha_id = self.source_store._lookup_revision_sha1(revid)
 
148
            except KeyError:
 
149
                return False
152
150
        try:
153
151
            return (sha_id not in self.target_store)
154
152
        except errors.NoSuchRevision:
158
156
    def missing_revisions(self, stop_revisions):
159
157
        """Find the revisions that are missing from the target repository.
160
158
 
161
 
        :param stop_revisions: Revisions to check for
 
159
        :param stop_revisions: Revisions to check for (tuples with
 
160
            Git SHA1, bzr revid)
162
161
        :return: sequence of missing revisions, in topological order
163
162
        :raise: NoSuchRevision if the stop_revisions are not present in
164
163
            the source
165
164
        """
 
165
        revid_sha_map = {}
 
166
        stop_revids = []
 
167
        stop_sha1s = []
 
168
        for (sha1, revid) in stop_revisions:
 
169
            if sha1 is not None and revid is not None:
 
170
                revid_sha_map[revid] = sha1
 
171
            elif sha1 is not None:
 
172
                stop_sha1s.append(sha1)
 
173
            else:
 
174
                assert revid is not None
 
175
                stop_revids.append(revid)
166
176
        missing = []
167
177
        graph = self.source.get_graph()
168
178
        pb = ui.ui_factory.nested_progress_bar()
169
179
        try:
170
 
            for revid, _ in graph.iter_ancestry(stop_revisions):
 
180
            for revid, _ in graph.iter_ancestry(stop_revids):
171
181
                assert type(revid) is str
172
182
                pb.update("determining revisions to fetch", len(missing))
173
 
                if self._revision_needs_fetching(revid):
 
183
                sha1 = revid_sha_map.get(revid)
 
184
                if self._revision_needs_fetching(sha1, revid):
174
185
                    missing.append(revid)
175
186
        finally:
176
187
            pb.finished()
 
188
        for sha1 in stop_sha1s:
 
189
            try:
 
190
                (kind, (revid, tree_sha, verifiers)) = self.source_store.lookup_git_sha(sha1)
 
191
            except KeyError:
 
192
                continue
 
193
            else:
 
194
                missing.append(revid)
 
195
                revid_sha_map[revid] = sha1
177
196
        return graph.iter_topo_order(missing)
178
197
 
179
198
    def _get_target_bzr_refs(self):
186
205
        refs = self.target._git.get_refs()
187
206
        for k, v in refs.iteritems():
188
207
            try:
189
 
                (kind, (revid, treesha)) = self.source_store.lookup_git_sha(v)
 
208
                (kind, type_data) = self.source_store.lookup_git_sha(v)
190
209
            except KeyError:
191
210
                revid = None
 
211
            else:
 
212
                if kind == "commit":
 
213
                    revid = type_data[0]
 
214
                else:
 
215
                    revid = None
192
216
            bzr_refs[k] = (v, revid)
193
217
        return bzr_refs
194
218
 
197
221
        try:
198
222
            old_refs = self._get_target_bzr_refs()
199
223
            new_refs = update_refs(old_refs)
200
 
            # FIXME: Keep track of already looked up revid<->sha mappings
201
 
            fetch_spec = PendingAncestryResult(
202
 
                [revid for sha, revid in new_refs.values()], self.source)
203
 
            self.fetch(fetch_spec=fetch_spec)
 
224
            self.fetch(mapped_refs=new_refs.values())
204
225
        finally:
205
226
            self.source.unlock()
206
227
        return old_refs, new_refs
232
253
        revidmap = {}
233
254
        self.source.lock_read()
234
255
        try:
235
 
            todo = list(self.missing_revisions([revid for sha, revid in stop_revisions]))
 
256
            todo = list(self.missing_revisions(stop_revisions))
236
257
            pb = ui.ui_factory.nested_progress_bar()
237
258
            try:
238
259
                object_generator = self._get_missing_objects_iterator(pb)
249
270
        return revidmap, gitidmap
250
271
 
251
272
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
252
 
            fetch_spec=None):
253
 
        if revision_id is not None:
254
 
            stop_revisions = [revision_id]
 
273
            fetch_spec=None, mapped_refs=None):
 
274
        if mapped_refs is not None:
 
275
            stop_revisions = mapped_refs
 
276
        elif revision_id is not None:
 
277
            stop_revisions = [(None, revision_id)]
255
278
        elif fetch_spec is not None:
256
 
            stop_revisions = fetch_spec.heads
 
279
            stop_revisions = [(None, revid) for revid in fetch_spec.heads]
257
280
        else:
258
 
            stop_revisions = self.source.all_revision_ids()
 
281
            stop_revisions = [(None, revid) for revid in self.source.all_revision_ids()]
259
282
        self.source.lock_read()
260
283
        try:
261
284
            todo = list(self.missing_revisions(stop_revisions))