/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 breezy/fetch.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import operator
28
28
 
29
 
from ..lazy_import import lazy_import
 
29
from .lazy_import import lazy_import
30
30
lazy_import(globals(), """
31
31
from breezy import (
32
32
    tsort,
36
36
    vf_search,
37
37
    )
38
38
""")
39
 
from .. import (
 
39
from . import (
40
40
    errors,
41
41
    ui,
42
42
    )
43
 
from ..i18n import gettext
44
 
from ..revision import NULL_REVISION
45
 
from ..sixish import (
 
43
from .i18n import gettext
 
44
from .revision import NULL_REVISION
 
45
from .sixish import (
46
46
    viewvalues,
47
47
    )
48
 
from ..trace import mutter
 
48
from .trace import mutter
49
49
 
50
50
 
51
51
class RepoFetcher(object):
56
56
    """
57
57
 
58
58
    def __init__(self, to_repository, from_repository, last_revision=None,
59
 
                 find_ghosts=True, fetch_spec=None):
 
59
        find_ghosts=True, fetch_spec=None):
60
60
        """Create a repo fetcher.
61
61
 
62
62
        :param last_revision: If set, try to limit to the data this revision
74
74
        self._last_revision = last_revision
75
75
        self._fetch_spec = fetch_spec
76
76
        self.find_ghosts = find_ghosts
77
 
        with self.from_repository.lock_read():
78
 
            mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
79
 
                   str(self.from_repository), str(self.from_repository._format),
80
 
                   str(self.to_repository), str(self.to_repository._format))
 
77
        self.from_repository.lock_read()
 
78
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
 
79
               str(self.from_repository), str(self.from_repository._format),
 
80
               str(self.to_repository), str(self.to_repository._format))
 
81
        try:
81
82
            self.__fetch()
 
83
        finally:
 
84
            self.from_repository.unlock()
82
85
 
83
86
    def __fetch(self):
84
87
        """Primary worker function.
98
101
            pb.show_pct = pb.show_count = False
99
102
            pb.update(gettext("Finding revisions"), 0, 2)
100
103
            search_result = self._revids_to_fetch()
101
 
            mutter('fetching: %s', str(search_result))
 
104
            mutter('fetching: %s', search_result)
102
105
            if search_result.is_empty():
103
106
                return
104
107
            pb.update(gettext("Fetching revisions"), 1, 2)
115
118
        # moment, so that it can feed the progress information back to this
116
119
        # function?
117
120
        if (self.from_repository._format.rich_root_data and
118
 
                not self.to_repository._format.rich_root_data):
 
121
            not self.to_repository._format.rich_root_data):
119
122
            raise errors.IncompatibleRepositories(
120
123
                self.from_repository, self.to_repository,
121
124
                "different rich-root support")
161
164
            return vf_search.EmptySearchResult()
162
165
        elif self._last_revision is not None:
163
166
            return vf_search.NotInOtherForRevs(self.to_repository,
164
 
                                               self.from_repository, [
165
 
                                                   self._last_revision],
166
 
                                               find_ghosts=self.find_ghosts).execute()
167
 
        else:  # self._last_revision is None:
 
167
                self.from_repository, [self._last_revision],
 
168
                find_ghosts=self.find_ghosts).execute()
 
169
        else: # self._last_revision is None:
168
170
            return vf_search.EverythingNotInOther(self.to_repository,
169
 
                                                  self.from_repository,
170
 
                                                  find_ghosts=self.find_ghosts).execute()
 
171
                self.from_repository,
 
172
                find_ghosts=self.find_ghosts).execute()
171
173
 
172
174
 
173
175
class Inter1and2Helper(object):
208
210
    def _find_root_ids(self, revs, parent_map, graph):
209
211
        revision_root = {}
210
212
        for tree in self.iter_rev_trees(revs):
211
 
            root_id = tree.path2id('')
212
 
            revision_id = tree.get_file_revision(u'')
 
213
            root_id = tree.get_root_id()
 
214
            revision_id = tree.get_file_revision(u'', root_id)
213
215
            revision_root[revision_id] = root_id
214
216
        # Find out which parents we don't already know root ids for
215
217
        parents = set(viewvalues(parent_map))
218
220
        # Limit to revisions present in the versionedfile
219
221
        parents = graph.get_parent_map(parents)
220
222
        for tree in self.iter_rev_trees(parents):
221
 
            root_id = tree.path2id('')
 
223
            root_id = tree.get_root_id()
222
224
            revision_root[tree.get_revision_id()] = root_id
223
225
        return revision_root
224
226
 
232
234
        rev_order = tsort.topo_sort(parent_map)
233
235
        rev_id_to_root_id = self._find_root_ids(revs, parent_map, graph)
234
236
        root_id_order = [(rev_id_to_root_id[rev_id], rev_id) for rev_id in
235
 
                         rev_order]
 
237
            rev_order]
236
238
        # Guaranteed stable, this groups all the file id operations together
237
239
        # retaining topological order within the revisions of a file id.
238
240
        # File id splits and joins would invalidate this, but they don't exist
247
249
 
248
250
 
249
251
def _new_root_data_stream(
250
 
        root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
 
252
    root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
251
253
    """Generate a texts substream of synthesised root entries.
252
254
 
253
255
    Used in fetches that do rich-root upgrades.
254
 
 
 
256
    
255
257
    :param root_keys_to_create: iterable of (root_id, rev_id) pairs describing
256
258
        the root entries to create.
257
259
    :param rev_id_to_root_id_map: dict of known rev_id -> root_id mappings for
265
267
        root_id, rev_id = root_key
266
268
        parent_keys = _parent_keys_for_root_version(
267
269
            root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph)
268
 
        yield versionedfile.ChunkedContentFactory(
269
 
            root_key, parent_keys, None, [])
 
270
        yield versionedfile.FulltextContentFactory(
 
271
            root_key, parent_keys, None, '')
270
272
 
271
273
 
272
274
def _parent_keys_for_root_version(
273
 
        root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph=None):
 
275
    root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph=None):
274
276
    """Get the parent keys for a given root id.
275
 
 
 
277
    
276
278
    A helper function for _new_root_data_stream.
277
279
    """
278
280
    # Include direct parents of the revision, but only if they used the same
293
295
                # But set parent_root_id to None since we don't really know
294
296
                parent_root_id = None
295
297
            else:
296
 
                parent_root_id = tree.path2id('')
 
298
                parent_root_id = tree.get_root_id()
297
299
            rev_id_to_root_id_map[parent_id] = None
298
300
            # XXX: why not:
299
301
            #   rev_id_to_root_id_map[parent_id] = parent_root_id
315
317
                pass
316
318
            else:
317
319
                try:
318
 
                    parent_ids.append(
319
 
                        tree.get_file_revision(
320
 
                            tree.id2path(root_id, recurse='none')))
 
320
                    parent_ids.append(tree.get_file_revision(tree.id2path(root_id), root_id))
321
321
                except errors.NoSuchId:
322
322
                    # not in the tree
323
323
                    pass
335
335
 
336
336
class TargetRepoKinds(object):
337
337
    """An enum-like set of constants.
338
 
 
 
338
    
339
339
    They are the possible values of FetchSpecFactory.target_repo_kinds.
340
340
    """
341
 
 
 
341
    
342
342
    PREEXISTING = 'preexisting'
343
343
    STACKED = 'stacked'
344
344
    EMPTY = 'empty'
420
420
                graph = self.source_repo.get_graph()
421
421
                topo_order = list(graph.iter_topo_order(ret.get_keys()))
422
422
                result_set = topo_order[:self.limit]
423
 
                ret = self.source_repo.revision_ids_to_search_result(
424
 
                    result_set)
 
423
                ret = self.source_repo.revision_ids_to_search_result(result_set)
425
424
            return ret
426
425
        else:
427
426
            return vf_search.NotInOtherForRevs(self.target_repo, self.source_repo,
428
 
                                               required_ids=heads_to_fetch, if_present_ids=if_present_fetch,
429
 
                                               limit=self.limit).execute()
 
427
                required_ids=heads_to_fetch, if_present_ids=if_present_fetch,
 
428
                limit=self.limit).execute()