~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: Robert Collins
  • Date: 2005-09-06 15:39:59 UTC
  • mto: (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050906153959-c79d671a510ca2fc
move RemoteStore to store.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
# breaks keep-alive -- sucks!
37
37
 
38
38
 
39
 
ENABLE_URLGRABBER = True
 
39
ENABLE_URLGRABBER = False
40
40
 
41
 
from bzrlib.errors import BzrError
 
41
from bzrlib.errors import BzrError, NoSuchRevision
42
42
 
43
43
class GetFailed(BzrError):
44
44
    def __init__(self, url, status):
106
106
        url = url[:idx]        
107
107
        
108
108
 
109
 
 
110
109
class RemoteBranch(Branch):
 
110
 
111
111
    def __init__(self, baseurl, find_root=True):
112
112
        """Create new proxy for a remote branch."""
 
113
        # circular import protection
 
114
        from bzrlib.store import RemoteStore
113
115
        if find_root:
114
116
            self.baseurl = _find_remote_root(baseurl)
115
117
        else:
116
118
            self.baseurl = baseurl
117
119
            self._check_format()
118
 
 
119
120
        self.inventory_store = RemoteStore(baseurl + '/.bzr/inventory-store/')
120
121
        self.text_store = RemoteStore(baseurl + '/.bzr/text-store/')
121
122
        self.revision_store = RemoteStore(baseurl + '/.bzr/revision-store/')
156
157
    def get_revision(self, revision_id):
157
158
        from bzrlib.revision import Revision
158
159
        from bzrlib.xml import unpack_xml
159
 
        revf = self.revision_store[revision_id]
 
160
        try:
 
161
            revf = self.revision_store[revision_id]
 
162
        except KeyError:
 
163
            raise NoSuchRevision(self, revision_id)
160
164
        r = unpack_xml(Revision, revf)
161
165
        if r.revision_id != revision_id:
162
166
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
163
167
                                % (revision_id, r.revision_id))
164
168
        return r
165
169
 
166
 
 
167
 
class RemoteStore(object):
168
 
    def __init__(self, baseurl):
169
 
        self._baseurl = baseurl
170
 
        
171
 
 
172
 
    def _path(self, name):
173
 
        if '/' in name:
174
 
            raise ValueError('invalid store id', name)
175
 
        return self._baseurl + '/' + name
176
 
        
177
 
    def __getitem__(self, fileid):
178
 
        p = self._path(fileid)
179
 
        try:
180
 
            return get_url(p, compressed=True)
181
 
        except:
182
 
            raise KeyError(fileid)
183
 
    
184
 
 
185