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

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
182
182
    This is for use by fetchers and converters.
183
183
    """
184
184
 
 
185
    # This is a class variable so that the test suite can override it.
 
186
    known_graph_threshold = 100
 
187
 
185
188
    def __init__(self, source):
186
189
        """Constructor.
187
190
 
243
246
        # yet, and are unlikely to in non-rich-root environments anyway.
244
247
        root_id_order.sort(key=operator.itemgetter(0))
245
248
        # Create a record stream containing the roots to create.
246
 
        if len(revs) > 100:
247
 
            # XXX: not covered by tests, should have a flag to always run
248
 
            # this. -- mbp 20100129
249
 
            graph = self.source_repo.get_known_graph_ancestry(revs)
 
249
        if len(revs) > self.known_graph_threshold:
 
250
            graph = self.source.get_known_graph_ancestry(revs)
250
251
        new_roots_stream = _new_root_data_stream(
251
252
            root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
252
253
        return [('texts', new_roots_stream)]
253
254
 
254
255
 
255
 
def _get_rich_root_heads_graph(source_repo, revision_ids):
256
 
    """Get a Graph object suitable for asking heads() for new rich roots."""
257
 
    return 
258
 
 
259
 
 
260
256
def _new_root_data_stream(
261
257
    root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
262
258
    """Generate a texts substream of synthesised root entries.