~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Robert Collins
  • Date: 2006-01-18 03:09:39 UTC
  • mto: (1534.1.15 integration)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: robertc@robertcollins.net-20060118030939-c5c7106140cf444f
Tweak storage towards mergability.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
    def __init__(self, to_branch, from_branch, last_revision=None, pb=None):
91
91
        if to_branch == from_branch:
92
92
            raise Exception("can't fetch from a branch to itself")
 
93
        
93
94
        self.to_branch = to_branch
94
 
        self.to_repository = to_branch.repository
 
95
        self.from_branch = from_branch
 
96
        self._last_revision = last_revision
 
97
        if pb is None:
 
98
            self.pb = bzrlib.ui.ui_factory.progress_bar()
 
99
        else:
 
100
            self.pb = pb
 
101
        self.from_branch.lock_read()
 
102
        try:
 
103
            self.to_branch.lock_write()
 
104
            try:
 
105
                self.__fetch()
 
106
            finally:
 
107
                self.to_branch.unlock()
 
108
        finally:
 
109
            self.from_branch.unlock()
 
110
 
 
111
    def __fetch(self):
 
112
        """Primary worker function.
 
113
 
 
114
        This initialises all the needed variables, and then fetches the 
 
115
        requested revisions, finally clearing the progress bar.
 
116
        """
 
117
        self.to_repository = self.to_branch.repository
95
118
        self.to_weaves = self.to_repository.weave_store
96
119
        self.to_control = self.to_repository.control_weaves
97
 
        self.from_branch = from_branch
98
 
        self.from_repository = from_branch.repository
 
120
        self.from_repository = self.from_branch.repository
99
121
        self.from_weaves = self.from_repository.weave_store
100
122
        self.from_control = self.from_repository.control_weaves
101
123
        self.failed_revisions = []
104
126
        self.count_weaves = 0
105
127
        self.copied_file_ids = set()
106
128
        self.file_ids_names = {}
107
 
        if pb is None:
108
 
            self.pb = bzrlib.ui.ui_factory.progress_bar()
109
 
        else:
110
 
            self.pb = pb
111
 
        self.from_branch.lock_read()
112
129
        try:
113
 
            self._fetch_revisions(last_revision)
 
130
            self._fetch_revisions()
114
131
        finally:
115
 
            self.from_branch.unlock()
116
132
            self.pb.clear()
117
133
 
118
 
    def _fetch_revisions(self, last_revision):
119
 
        self.last_revision = self._find_last_revision(last_revision)
120
 
        mutter('fetch up to rev {%s}', self.last_revision)
121
 
        if (self.last_revision is not None and 
122
 
            self.to_repository.has_revision(self.last_revision)):
 
134
    def _fetch_revisions(self):
 
135
        self._find_last_revision()
 
136
        mutter('fetch up to rev {%s}', self._last_revision)
 
137
        if (self._last_revision is not None and 
 
138
            self.to_repository.has_revision(self._last_revision)):
123
139
            return
124
140
        try:
125
141
            revs_to_fetch = self._compare_ancestries()
126
142
        except WeaveError:
127
 
            raise InstallFailed([self.last_revision])
 
143
            raise InstallFailed([self._last_revision])
128
144
        self._copy_revisions(revs_to_fetch)
129
145
        self.new_ancestry = revs_to_fetch
130
146
 
131
 
    def _find_last_revision(self, last_revision):
 
147
    def _find_last_revision(self):
132
148
        """Find the limiting source revision.
133
149
 
134
150
        Every ancestor of that revision will be merged across.
135
151
 
136
152
        Returns the revision_id, or returns None if there's no history
137
153
        in the source branch."""
138
 
        if last_revision:
139
 
            return last_revision
 
154
        if self._last_revision:
 
155
            return
140
156
        self.pb.update('get source history')
141
157
        from_history = self.from_branch.revision_history()
142
158
        self.pb.update('get destination history')
143
159
        if from_history:
144
 
            return from_history[-1]
 
160
            self._last_revision = from_history[-1]
145
161
        else:
146
 
            return None                 # no history in the source branch
147
 
            
 
162
            # no history in the source branch
 
163
            self._last_revision = None
148
164
 
149
165
    def _compare_ancestries(self):
150
166
        """Get a list of revisions that must be copied.
153
169
        branch and not in the destination branch."""
154
170
        self.pb.update('get source ancestry')
155
171
        from_repository = self.from_branch.repository
156
 
        self.from_ancestry = from_repository.get_ancestry(self.last_revision)
 
172
        self.from_ancestry = from_repository.get_ancestry(self._last_revision)
157
173
 
158
174
        dest_last_rev = self.to_branch.last_revision()
159
175
        self.pb.update('get destination ancestry')