~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-20 13:28:35 UTC
  • mfrom: (5852.1.11 fetch-limit)
  • Revision ID: pqm@pqm.ubuntu.com-20110520132835-3rf01eu5mbkz3zos
(jelmer) Add limit argument to Branch.fetch(). (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.lazy_import import lazy_import
29
29
lazy_import(globals(), """
30
30
from bzrlib import (
31
 
    graph,
 
31
    graph as _mod_graph,
32
32
    tsort,
33
33
    versionedfile,
34
34
    )
160
160
        elif self._last_revision == NULL_REVISION:
161
161
            # fetch_spec is None + last_revision is null => empty fetch.
162
162
            # explicit limit of no revisions needed
163
 
            return graph.EmptySearchResult()
 
163
            return _mod_graph.EmptySearchResult()
164
164
        elif self._last_revision is not None:
165
 
            return graph.NotInOtherForRevs(self.to_repository,
 
165
            return _mod_graph.NotInOtherForRevs(self.to_repository,
166
166
                self.from_repository, [self._last_revision],
167
167
                find_ghosts=self.find_ghosts).execute()
168
168
        else: # self._last_revision is None:
169
 
            return graph.EverythingNotInOther(self.to_repository,
 
169
            return _mod_graph.EverythingNotInOther(self.to_repository,
170
170
                self.from_repository,
171
171
                find_ghosts=self.find_ghosts).execute()
172
172
 
371
371
        self.source_repo = None
372
372
        self.target_repo = None
373
373
        self.target_repo_kind = None
 
374
        self.limit = None
374
375
 
375
376
    def add_revision_ids(self, revision_ids):
376
377
        """Add revision_ids to the set of revision_ids to be fetched."""
377
378
        self._explicit_rev_ids.update(revision_ids)
378
 
        
 
379
 
379
380
    def make_fetch_spec(self):
380
381
        """Build a SearchResult or PendingAncestryResult or etc."""
381
382
        if self.target_repo_kind is None or self.source_repo is None:
382
383
            raise AssertionError(
383
384
                'Incomplete FetchSpecFactory: %r' % (self.__dict__,))
384
385
        if len(self._explicit_rev_ids) == 0 and self.source_branch is None:
 
386
            if self.limit is not None:
 
387
                raise NotImplementedError(
 
388
                    "limit is only supported with a source branch set")
385
389
            # Caller hasn't specified any revisions or source branch
386
390
            if self.target_repo_kind == TargetRepoKinds.EMPTY:
387
 
                return graph.EverythingResult(self.source_repo)
 
391
                return _mod_graph.EverythingResult(self.source_repo)
388
392
            else:
389
393
                # We want everything not already in the target (or target's
390
394
                # fallbacks).
391
 
                return graph.EverythingNotInOther(
 
395
                return _mod_graph.EverythingNotInOther(
392
396
                    self.target_repo, self.source_repo).execute()
393
397
        heads_to_fetch = set(self._explicit_rev_ids)
394
398
        if self.source_branch is not None:
411
415
            # heads_to_fetch will almost certainly be present so this doesn't
412
416
            # matter much.
413
417
            all_heads = heads_to_fetch.union(if_present_fetch)
414
 
            return graph.PendingAncestryResult(all_heads, self.source_repo)
415
 
        return graph.NotInOtherForRevs(self.target_repo, self.source_repo,
416
 
            required_ids=heads_to_fetch, if_present_ids=if_present_fetch
417
 
            ).execute()
418
 
 
419
 
 
 
418
            ret = _mod_graph.PendingAncestryResult(all_heads, self.source_repo)
 
419
            if self.limit is not None:
 
420
                graph = self.source_repo.get_graph()
 
421
                topo_order = list(graph.iter_topo_order(ret.get_keys()))
 
422
                result_set = topo_order[:self.limit]
 
423
                ret = self.source_repo.revision_ids_to_search_result(result_set)
 
424
            return ret
 
425
        else:
 
426
            return _mod_graph.NotInOtherForRevs(self.target_repo, self.source_repo,
 
427
                required_ids=heads_to_fetch, if_present_ids=if_present_fetch,
 
428
                limit=self.limit).execute()