/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

merge bzr.dev r4164

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
that has merged into it.  As the first step of a merge, pull, or
22
22
branch operation we copy history from the source into the destination
23
23
branch.
24
 
 
25
 
The copying is done in a slightly complicated order.  We don't want to
26
 
add a revision to the store until everything it refers to is also
27
 
stored, so that if a revision is present we can totally recreate it.
28
 
However, we can't know what files are included in a revision until we
29
 
read its inventory.  So we query the inventory store of the source for
30
 
the ids we need, and then pull those ids and then return to the inventories.
31
24
"""
32
25
 
33
26
import operator
34
27
 
35
28
import bzrlib
36
 
import bzrlib.errors as errors
 
29
from bzrlib import (
 
30
    errors,
 
31
    symbol_versioning,
 
32
    )
37
33
from bzrlib.errors import InstallFailed
38
34
from bzrlib.progress import ProgressPhase
39
35
from bzrlib.revision import NULL_REVISION
42
38
import bzrlib.ui
43
39
from bzrlib.versionedfile import FulltextContentFactory
44
40
 
45
 
# TODO: Avoid repeatedly opening weaves so many times.
46
 
 
47
 
# XXX: This doesn't handle ghost (not present in branch) revisions at
48
 
# all yet.  I'm not sure they really should be supported.
49
 
 
50
 
# NOTE: This doesn't copy revisions which may be present but not
51
 
# merged into the last revision.  I'm not sure we want to do that.
52
 
 
53
 
# - get a list of revisions that need to be pulled in
54
 
# - for each one, pull in that revision file
55
 
#   and get the inventory, and store the inventory with right
56
 
#   parents.
57
 
# - and get the ancestry, and store that with right parents too
58
 
# - and keep a note of all file ids and version seen
59
 
# - then go through all files; for each one get the weave,
60
 
#   and add in all file versions
61
 
 
62
41
 
63
42
class RepoFetcher(object):
64
43
    """Pull revisions and texts from one repository to another.
65
44
 
66
 
    last_revision
67
 
        if set, try to limit to the data this revision references.
68
 
 
69
45
    This should not be used directly, it's essential a object to encapsulate
70
46
    the logic in InterRepository.fetch().
71
47
    """
74
50
        pb=None, find_ghosts=True, fetch_spec=None):
75
51
        """Create a repo fetcher.
76
52
 
 
53
        :param last_revision: If set, try to limit to the data this revision
 
54
            references.
77
55
        :param find_ghosts: If True search the entire history for ghosts.
78
56
        :param _write_group_acquired_callable: Don't use; this parameter only
79
57
            exists to facilitate a hack done in InterPackRepo.fetch.  We would
80
58
            like to remove this parameter.
 
59
        :param pb: ProgressBar object to use; deprecated and ignored.
 
60
            This method will just create one on top of the stack.
81
61
        """
 
62
        if pb is not None:
 
63
            symbol_versioning.warn(
 
64
                symbol_versioning.deprecated_in((1, 14, 0))
 
65
                % "pb parameter to RepoFetcher.__init__")
 
66
            # and for simplicity it is in fact ignored
82
67
        if to_repository.has_same_location(from_repository):
83
68
            # repository.fetch should be taking care of this case.
84
69
            raise errors.BzrError('RepoFetcher run '
91
76
        self._last_revision = last_revision
92
77
        self._fetch_spec = fetch_spec
93
78
        self.find_ghosts = find_ghosts
94
 
        if pb is None:
95
 
            self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
96
 
            self.nested_pb = self.pb
97
 
        else:
98
 
            self.pb = pb
99
 
            self.nested_pb = None
100
79
        self.from_repository.lock_read()
 
80
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
 
81
               self.from_repository, self.from_repository._format,
 
82
               self.to_repository, self.to_repository._format)
101
83
        try:
102
 
            try:
103
 
                self.__fetch()
104
 
            finally:
105
 
                if self.nested_pb is not None:
106
 
                    self.nested_pb.finished()
 
84
            self.__fetch()
107
85
        finally:
108
86
            self.from_repository.unlock()
109
87
 
121
99
        # assert not missing
122
100
        self.count_total = 0
123
101
        self.file_ids_names = {}
124
 
        pp = ProgressPhase('Transferring', 4, self.pb)
 
102
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
103
        pb.show_pct = pb.show_count = False
125
104
        try:
126
 
            pp.next_phase()
 
105
            pb.update("Finding revisions", 0, 2)
127
106
            search = self._revids_to_fetch()
128
107
            if search is None:
129
108
                return
130
 
            self._fetch_everything_for_search(search, pp)
 
109
            pb.update("Fetching revisions", 1, 2)
 
110
            self._fetch_everything_for_search(search)
131
111
        finally:
132
 
            self.pb.clear()
 
112
            pb.finished()
133
113
 
134
 
    def _fetch_everything_for_search(self, search, pp):
 
114
    def _fetch_everything_for_search(self, search):
135
115
        """Fetch all data for the given set of revisions."""
136
116
        # The first phase is "file".  We pass the progress bar for it directly
137
117
        # into item_keys_introduced_by, which has more information about how
146
126
            raise errors.IncompatibleRepositories(
147
127
                self.from_repository, self.to_repository,
148
128
                "different rich-root support")
149
 
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
129
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
150
130
        try:
 
131
            pb.update("Get stream source")
151
132
            source = self.from_repository._get_source(
152
133
                self.to_repository._format)
153
134
            stream = source.get_stream(search)
154
135
            from_format = self.from_repository._format
 
136
            pb.update("Inserting stream")
155
137
            resume_tokens, missing_keys = self.sink.insert_stream(
156
138
                stream, from_format, [])
157
139
            if missing_keys:
 
140
                pb.update("Missing keys")
158
141
                stream = source.get_stream_for_missing_keys(missing_keys)
 
142
                pb.update("Inserting missing keys")
159
143
                resume_tokens, missing_keys = self.sink.insert_stream(
160
144
                    stream, from_format, resume_tokens)
161
145
            if missing_keys:
166
150
                raise AssertionError(
167
151
                    "second push failed to commit the fetch %r." % (
168
152
                        resume_tokens,))
 
153
            pb.update("Finishing stream")
169
154
            self.sink.finished()
170
155
        finally:
171
 
            if self.pb is not None:
172
 
                self.pb.finished()
 
156
            pb.finished()
173
157
 
174
158
    def _revids_to_fetch(self):
175
159
        """Determines the exact revisions needed from self.from_repository to