~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Martin Pool
  • Date: 2005-09-22 13:32:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050922133202-347cfd35d2941dd5
- simple weave-based annotate code (not complete)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.progress import ProgressBar
24
24
from bzrlib.xml5 import serializer_v5
25
25
from bzrlib.osutils import sha_string, split_lines
26
 
from bzrlib.errors import InstallFailed, NoSuchRevision, WeaveError
 
26
from bzrlib.errors import NoSuchRevision
27
27
 
28
28
"""Copying of history from one branch to another.
29
29
 
87
87
    def __init__(self, to_branch, from_branch, last_revision=None, pb=None):
88
88
        self.to_branch = to_branch
89
89
        self.to_weaves = to_branch.weave_store
90
 
        self.to_control = to_branch.control_weaves
 
90
        self.to_control = to_branch.control_weaves
91
91
        self.from_branch = from_branch
92
92
        self.from_weaves = from_branch.weave_store
93
 
        self.from_control = from_branch.control_weaves
 
93
        self.from_control = from_branch.control_weaves
94
94
        self.failed_revisions = []
95
95
        self.count_copied = 0
96
96
        self.count_total = 0
99
99
            self.pb = bzrlib.ui.ui_factory.progress_bar()
100
100
        else:
101
101
            self.pb = pb
102
 
        try:
103
 
            self.last_revision = self._find_last_revision(last_revision)
104
 
        except NoSuchRevision, e:
105
 
            mutter('failed getting last revision: %s', e)
106
 
            raise InstallFailed([last_revision])
 
102
        self.last_revision = self._find_last_revision(last_revision)
107
103
        mutter('fetch up to rev {%s}', self.last_revision)
108
 
        try:
109
 
            revs_to_fetch = self._compare_ancestries()
110
 
        except WeaveError:
111
 
            raise InstallFailed([self.last_revision])
 
104
        revs_to_fetch = self._compare_ancestries()
112
105
        self._copy_revisions(revs_to_fetch)
113
106
        self.new_ancestry = revs_to_fetch
114
107
 
 
108
        
115
109
 
116
110
    def _find_last_revision(self, last_revision):
117
111
        """Find the limiting source revision.
124
118
        from_history = self.from_branch.revision_history()
125
119
        self.pb.update('get destination history')
126
120
        if last_revision:
127
 
            self.from_branch.get_revision(last_revision)
128
 
            return last_revision
 
121
            if last_revision not in from_history:
 
122
                raise NoSuchRevision(self.from_branch, last_revision)
 
123
            else:
 
124
                return last_revision
129
125
        elif from_history:
130
126
            return from_history[-1]
131
127
        else:
155
151
        mutter('need to get %d revisions in total', len(to_fetch))
156
152
        self.count_total = len(to_fetch)
157
153
        return to_fetch
 
154
                
 
155
 
158
156
 
159
157
    def _copy_revisions(self, revs_to_fetch):
160
158
        i = 0
161
159
        for rev_id in revs_to_fetch:
162
160
            i += 1
163
 
            if rev_id is None:
164
 
                continue
165
161
            if self.to_branch.has_revision(rev_id):
166
162
                continue
167
163
            self.pb.update('fetch revision', i, self.count_total)