~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Martin
  • Date: 2011-02-25 18:52:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5691.
  • Revision ID: gzlist@googlemail.com-20110225185253-y0kplvee84n7pvgn
Use correct format character for unsigned int gc_chk_sha1_record members

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 as _mod_graph,
 
31
    graph,
32
32
    tsort,
33
33
    versionedfile,
34
34
    )
35
35
""")
 
36
import bzrlib
36
37
from bzrlib import (
37
38
    errors,
38
39
    ui,
39
40
    )
40
 
from bzrlib.i18n import gettext
41
41
from bzrlib.revision import NULL_REVISION
42
42
from bzrlib.trace import mutter
43
43
 
94
94
        pb = ui.ui_factory.nested_progress_bar()
95
95
        pb.show_pct = pb.show_count = False
96
96
        try:
97
 
            pb.update(gettext("Finding revisions"), 0, 2)
 
97
            pb.update("Finding revisions", 0, 2)
98
98
            search_result = self._revids_to_fetch()
99
99
            mutter('fetching: %s', search_result)
100
100
            if search_result.is_empty():
101
101
                return
102
 
            pb.update(gettext("Fetching revisions"), 1, 2)
 
102
            pb.update("Fetching revisions", 1, 2)
103
103
            self._fetch_everything_for_search(search_result)
104
104
        finally:
105
105
            pb.finished()
161
161
        elif self._last_revision == NULL_REVISION:
162
162
            # fetch_spec is None + last_revision is null => empty fetch.
163
163
            # explicit limit of no revisions needed
164
 
            return _mod_graph.EmptySearchResult()
 
164
            return graph.EmptySearchResult()
165
165
        elif self._last_revision is not None:
166
 
            return _mod_graph.NotInOtherForRevs(self.to_repository,
 
166
            return graph.NotInOtherForRevs(self.to_repository,
167
167
                self.from_repository, [self._last_revision],
168
168
                find_ghosts=self.find_ghosts).execute()
169
169
        else: # self._last_revision is None:
170
 
            return _mod_graph.EverythingNotInOther(self.to_repository,
 
170
            return graph.EverythingNotInOther(self.to_repository,
171
171
                self.from_repository,
172
172
                find_ghosts=self.find_ghosts).execute()
173
173
 
318
318
                pass
319
319
            else:
320
320
                try:
321
 
                    parent_ids.append(tree.get_file_revision(root_id))
 
321
                    parent_ids.append(tree.inventory[root_id].revision)
322
322
                except errors.NoSuchId:
323
323
                    # not in the tree
324
324
                    pass
350
350
 
351
351
    Factors that go into determining the sort of fetch to perform:
352
352
     * did the caller specify any revision IDs?
353
 
     * did the caller specify a source branch (need to fetch its
354
 
       heads_to_fetch(), usually the tip + tags)
 
353
     * did the caller specify a source branch (need to fetch the tip + tags)
355
354
     * is there an existing target repo (don't need to refetch revs it
356
355
       already has)
357
356
     * target is stacked?  (similar to pre-existing target repo: even if
372
371
        self.source_repo = None
373
372
        self.target_repo = None
374
373
        self.target_repo_kind = None
375
 
        self.limit = None
376
374
 
377
375
    def add_revision_ids(self, revision_ids):
378
376
        """Add revision_ids to the set of revision_ids to be fetched."""
379
377
        self._explicit_rev_ids.update(revision_ids)
380
 
 
 
378
        
381
379
    def make_fetch_spec(self):
382
380
        """Build a SearchResult or PendingAncestryResult or etc."""
383
381
        if self.target_repo_kind is None or self.source_repo is None:
384
382
            raise AssertionError(
385
383
                'Incomplete FetchSpecFactory: %r' % (self.__dict__,))
386
384
        if len(self._explicit_rev_ids) == 0 and self.source_branch is None:
387
 
            if self.limit is not None:
388
 
                raise NotImplementedError(
389
 
                    "limit is only supported with a source branch set")
390
385
            # Caller hasn't specified any revisions or source branch
391
386
            if self.target_repo_kind == TargetRepoKinds.EMPTY:
392
 
                return _mod_graph.EverythingResult(self.source_repo)
 
387
                return graph.EverythingResult(self.source_repo)
393
388
            else:
394
389
                # We want everything not already in the target (or target's
395
390
                # fallbacks).
396
 
                return _mod_graph.EverythingNotInOther(
 
391
                return graph.EverythingNotInOther(
397
392
                    self.target_repo, self.source_repo).execute()
398
393
        heads_to_fetch = set(self._explicit_rev_ids)
 
394
        tags_to_fetch = set()
399
395
        if self.source_branch is not None:
400
 
            must_fetch, if_present_fetch = self.source_branch.heads_to_fetch()
 
396
            try:
 
397
                tags_to_fetch.update(
 
398
                    self.source_branch.tags.get_reverse_tag_dict())
 
399
            except errors.TagsNotSupported:
 
400
                pass
401
401
            if self.source_branch_stop_revision_id is not None:
402
 
                # Replace the tip rev from must_fetch with the stop revision
403
 
                # XXX: this might be wrong if the tip rev is also in the
404
 
                # must_fetch set for other reasons (e.g. it's the tip of
405
 
                # multiple loom threads?), but then it's pretty unclear what it
406
 
                # should mean to specify a stop_revision in that case anyway.
407
 
                must_fetch.discard(self.source_branch.last_revision())
408
 
                must_fetch.add(self.source_branch_stop_revision_id)
409
 
            heads_to_fetch.update(must_fetch)
410
 
        else:
411
 
            if_present_fetch = set()
 
402
                heads_to_fetch.add(self.source_branch_stop_revision_id)
 
403
            else:
 
404
                heads_to_fetch.add(self.source_branch.last_revision())
412
405
        if self.target_repo_kind == TargetRepoKinds.EMPTY:
413
406
            # PendingAncestryResult does not raise errors if a requested head
414
407
            # is absent.  Ideally it would support the
415
408
            # required_ids/if_present_ids distinction, but in practice
416
409
            # heads_to_fetch will almost certainly be present so this doesn't
417
410
            # matter much.
418
 
            all_heads = heads_to_fetch.union(if_present_fetch)
419
 
            ret = _mod_graph.PendingAncestryResult(all_heads, self.source_repo)
420
 
            if self.limit is not None:
421
 
                graph = self.source_repo.get_graph()
422
 
                topo_order = list(graph.iter_topo_order(ret.get_keys()))
423
 
                result_set = topo_order[:self.limit]
424
 
                ret = self.source_repo.revision_ids_to_search_result(result_set)
425
 
            return ret
426
 
        else:
427
 
            return _mod_graph.NotInOtherForRevs(self.target_repo, self.source_repo,
428
 
                required_ids=heads_to_fetch, if_present_ids=if_present_fetch,
429
 
                limit=self.limit).execute()
 
411
            all_heads = heads_to_fetch.union(tags_to_fetch)
 
412
            return graph.PendingAncestryResult(all_heads, self.source_repo)
 
413
        return graph.NotInOtherForRevs(self.target_repo, self.source_repo,
 
414
            required_ids=heads_to_fetch, if_present_ids=tags_to_fetch
 
415
            ).execute()
 
416
 
 
417