~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-21 04:15:04 UTC
  • mto: (1092.1.41) (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: aaron.bentley@utoronto.ca-20050821041504-866f53c120065af3
Added revision-based common-ancestor checking

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import gzip
28
28
from cStringIO import StringIO
29
 
import os
30
29
import urllib2
31
 
import urlparse
32
 
 
33
 
from bzrlib.errors import BzrError, BzrCheckError
34
 
from bzrlib.branch import Branch, BZR_BRANCH_FORMAT
35
 
from bzrlib.trace import mutter
36
 
from bzrlib.xml import serializer_v4
37
 
 
38
 
 
39
 
ENABLE_URLGRABBER = False
40
 
 
41
 
from bzrlib.errors import BzrError, NoSuchRevision
 
30
 
 
31
from errors import BzrError, BzrCheckError
 
32
from branch import Branch, BZR_BRANCH_FORMAT
 
33
from trace import mutter
 
34
 
 
35
# velocitynet.com.au transparently proxies connections and thereby
 
36
# breaks keep-alive -- sucks!
 
37
 
 
38
 
 
39
ENABLE_URLGRABBER = True
 
40
 
 
41
from bzrlib.errors import BzrError
42
42
 
43
43
class GetFailed(BzrError):
44
44
    def __init__(self, url, status):
84
84
    orig_url = url
85
85
    while True:
86
86
        try:
87
 
            fmt_url = url + '/.bzr/branch-format'
88
 
            ff = get_url(fmt_url)
 
87
            ff = get_url(url + '/.bzr/branch-format')
 
88
 
89
89
            fmt = ff.read()
90
90
            ff.close()
91
91
 
98
98
        except urllib2.URLError:
99
99
            pass
100
100
 
101
 
        scheme, host, path = list(urlparse.urlparse(url))[:3]
102
 
        # discard params, query, fragment
103
 
        
104
 
        # strip off one component of the path component
105
 
        idx = path.rfind('/')
106
 
        if idx == -1 or path == '/':
107
 
            raise BzrError('no branch root found for URL %s'
108
 
                           ' or enclosing directories'
109
 
                           % orig_url)
110
 
        path = path[:idx]
111
 
        url = urlparse.urlunparse((scheme, host, path, '', '', ''))
 
101
        try:
 
102
            idx = url.rindex('/')
 
103
        except ValueError:
 
104
            raise BzrError('no branch root found for URL %s' % orig_url)
 
105
 
 
106
        url = url[:idx]        
112
107
        
113
108
 
114
109
 
116
111
    def __init__(self, baseurl, find_root=True):
117
112
        """Create new proxy for a remote branch."""
118
113
        if find_root:
119
 
            self.base = _find_remote_root(baseurl)
 
114
            self.baseurl = _find_remote_root(baseurl)
120
115
        else:
121
 
            self.base = baseurl
 
116
            self.baseurl = baseurl
122
117
            self._check_format()
123
118
 
124
119
        self.inventory_store = RemoteStore(baseurl + '/.bzr/inventory-store/')
134
129
    def controlfile(self, filename, mode):
135
130
        if mode not in ('rb', 'rt', 'r'):
136
131
            raise BzrError("file mode %r not supported for remote branches" % mode)
137
 
        return get_url(self.base + '/.bzr/' + filename, False)
 
132
        return get_url(self.baseurl + '/.bzr/' + filename, False)
138
133
 
139
134
 
140
135
    def lock_read(self):
144
139
    def lock_write(self):
145
140
        from errors import LockError
146
141
        raise LockError("write lock not supported for remote branch %s"
147
 
                        % self.base)
 
142
                        % self.baseurl)
148
143
 
149
144
    def unlock(self):
150
145
        pass
151
146
    
152
147
 
153
148
    def relpath(self, path):
154
 
        if not path.startswith(self.base):
 
149
        if not path.startswith(self.baseurl):
155
150
            raise BzrError('path %r is not under base URL %r'
156
 
                           % (path, self.base))
157
 
        pl = len(self.base)
 
151
                           % (path, self.baseurl))
 
152
        pl = len(self.baseurl)
158
153
        return path[pl:].lstrip('/')
159
154
 
160
155
 
161
156
    def get_revision(self, revision_id):
162
 
        try:
163
 
            revf = self.revision_store[revision_id]
164
 
        except KeyError:
165
 
            raise NoSuchRevision(self, revision_id)
166
 
        r = serializer_v4.read_revision(revf)
 
157
        from bzrlib.revision import Revision
 
158
        from bzrlib.xml import unpack_xml
 
159
        revf = self.revision_store[revision_id]
 
160
        r = unpack_xml(Revision, revf)
167
161
        if r.revision_id != revision_id:
168
162
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
169
163
                                % (revision_id, r.revision_id))
184
178
        p = self._path(fileid)
185
179
        try:
186
180
            return get_url(p, compressed=True)
187
 
        except urllib2.URLError:
 
181
        except:
188
182
            raise KeyError(fileid)
189
183
    
190
184