~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 15:06:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110420150617-i41caxgemg32tq1r
Start adding tests that _worth_saving_limit works as expected.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Copying of history from one branch to another.
18
19
 
19
20
The basic plan is that every branch knows the history of everything
22
23
branch.
23
24
"""
24
25
 
25
 
from __future__ import absolute_import
26
 
 
27
26
import operator
28
27
 
29
28
from bzrlib.lazy_import import lazy_import
30
29
lazy_import(globals(), """
31
30
from bzrlib import (
 
31
    graph,
32
32
    tsort,
33
33
    versionedfile,
34
 
    vf_search,
35
34
    )
36
35
""")
37
36
from bzrlib import (
38
37
    errors,
39
38
    ui,
40
39
    )
41
 
from bzrlib.i18n import gettext
42
40
from bzrlib.revision import NULL_REVISION
43
41
from bzrlib.trace import mutter
44
42
 
95
93
        pb = ui.ui_factory.nested_progress_bar()
96
94
        pb.show_pct = pb.show_count = False
97
95
        try:
98
 
            pb.update(gettext("Finding revisions"), 0, 2)
 
96
            pb.update("Finding revisions", 0, 2)
99
97
            search_result = self._revids_to_fetch()
100
98
            mutter('fetching: %s', search_result)
101
99
            if search_result.is_empty():
102
100
                return
103
 
            pb.update(gettext("Fetching revisions"), 1, 2)
 
101
            pb.update("Fetching revisions", 1, 2)
104
102
            self._fetch_everything_for_search(search_result)
105
103
        finally:
106
104
            pb.finished()
162
160
        elif self._last_revision == NULL_REVISION:
163
161
            # fetch_spec is None + last_revision is null => empty fetch.
164
162
            # explicit limit of no revisions needed
165
 
            return vf_search.EmptySearchResult()
 
163
            return graph.EmptySearchResult()
166
164
        elif self._last_revision is not None:
167
 
            return vf_search.NotInOtherForRevs(self.to_repository,
 
165
            return graph.NotInOtherForRevs(self.to_repository,
168
166
                self.from_repository, [self._last_revision],
169
167
                find_ghosts=self.find_ghosts).execute()
170
168
        else: # self._last_revision is None:
171
 
            return vf_search.EverythingNotInOther(self.to_repository,
 
169
            return graph.EverythingNotInOther(self.to_repository,
172
170
                self.from_repository,
173
171
                find_ghosts=self.find_ghosts).execute()
174
172
 
203
201
        revs = list(revs)
204
202
        while revs:
205
203
            for tree in self.source.revision_trees(revs[:100]):
206
 
                if tree.root_inventory.revision_id is None:
207
 
                    tree.root_inventory.revision_id = tree.get_revision_id()
 
204
                if tree.inventory.revision_id is None:
 
205
                    tree.inventory.revision_id = tree.get_revision_id()
208
206
                yield tree
209
207
            revs = revs[100:]
210
208
 
211
209
    def _find_root_ids(self, revs, parent_map, graph):
212
210
        revision_root = {}
213
211
        for tree in self.iter_rev_trees(revs):
 
212
            revision_id = tree.inventory.root.revision
214
213
            root_id = tree.get_root_id()
215
 
            revision_id = tree.get_file_revision(root_id, u"")
216
214
            revision_root[revision_id] = root_id
217
215
        # Find out which parents we don't already know root ids for
218
216
        parents = set()
373
371
        self.source_repo = None
374
372
        self.target_repo = None
375
373
        self.target_repo_kind = None
376
 
        self.limit = None
377
374
 
378
375
    def add_revision_ids(self, revision_ids):
379
376
        """Add revision_ids to the set of revision_ids to be fetched."""
380
377
        self._explicit_rev_ids.update(revision_ids)
381
 
 
 
378
        
382
379
    def make_fetch_spec(self):
383
380
        """Build a SearchResult or PendingAncestryResult or etc."""
384
381
        if self.target_repo_kind is None or self.source_repo is None:
385
382
            raise AssertionError(
386
383
                'Incomplete FetchSpecFactory: %r' % (self.__dict__,))
387
384
        if len(self._explicit_rev_ids) == 0 and self.source_branch is None:
388
 
            if self.limit is not None:
389
 
                raise NotImplementedError(
390
 
                    "limit is only supported with a source branch set")
391
385
            # Caller hasn't specified any revisions or source branch
392
386
            if self.target_repo_kind == TargetRepoKinds.EMPTY:
393
 
                return vf_search.EverythingResult(self.source_repo)
 
387
                return graph.EverythingResult(self.source_repo)
394
388
            else:
395
389
                # We want everything not already in the target (or target's
396
390
                # fallbacks).
397
 
                return vf_search.EverythingNotInOther(
 
391
                return graph.EverythingNotInOther(
398
392
                    self.target_repo, self.source_repo).execute()
399
393
        heads_to_fetch = set(self._explicit_rev_ids)
400
394
        if self.source_branch is not None:
417
411
            # heads_to_fetch will almost certainly be present so this doesn't
418
412
            # matter much.
419
413
            all_heads = heads_to_fetch.union(if_present_fetch)
420
 
            ret = vf_search.PendingAncestryResult(all_heads, self.source_repo)
421
 
            if self.limit is not None:
422
 
                graph = self.source_repo.get_graph()
423
 
                topo_order = list(graph.iter_topo_order(ret.get_keys()))
424
 
                result_set = topo_order[:self.limit]
425
 
                ret = self.source_repo.revision_ids_to_search_result(result_set)
426
 
            return ret
427
 
        else:
428
 
            return vf_search.NotInOtherForRevs(self.target_repo, self.source_repo,
429
 
                required_ids=heads_to_fetch, if_present_ids=if_present_fetch,
430
 
                limit=self.limit).execute()
 
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