~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: Martin Pool
  • Date: 2005-05-09 06:09:42 UTC
  • Revision ID: mbp@sourcefrog.net-20050509060942-d9c9efd7feed0894
- more indicators at top of test output
- tidy up remotebranch stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import gzip
29
29
from sets import Set
30
30
from cStringIO import StringIO
31
 
import urllib2
32
31
 
33
32
from errors import BzrError, BzrCheckError
34
 
from branch import Branch, BZR_BRANCH_FORMAT
35
 
from trace import mutter
 
33
from branch import Branch
36
34
 
37
35
# velocitynet.com.au transparently proxies connections and thereby
38
36
# breaks keep-alive -- sucks!
45
43
    import urllib2
46
44
    if compressed:
47
45
        url += '.gz'
48
 
    mutter("get_url %s" % url)
49
46
    url_f = urllib2.urlopen(url)
50
47
    if compressed:
51
48
        return gzip.GzipFile(fileobj=StringIO(url_f.read()))
52
49
    else:
53
50
        return url_f
54
51
 
55
 
 
56
52
if ENABLE_URLGRABBER:
57
53
    import urlgrabber
58
54
    import urlgrabber.keepalive
71
67
            raise BzrError("remote fetch failed: %r: %s" % (url, e))
72
68
 
73
69
 
74
 
 
75
 
def _find_remote_root(url):
76
 
    """Return the prefix URL that corresponds to the branch root."""
77
 
    orig_url = url
78
 
    while True:
79
 
        try:
80
 
            ff = get_url(url + '/.bzr/branch-format')
81
 
 
82
 
            fmt = ff.read()
83
 
            ff.close()
84
 
 
85
 
            fmt = fmt.rstrip('\r\n')
86
 
            if fmt != BZR_BRANCH_FORMAT.rstrip('\r\n'):
87
 
                raise BzrError("sorry, branch format %r not supported at url %s"
88
 
                               % (fmt, url))
89
 
            
90
 
            return url
91
 
        except urllib2.URLError:
92
 
            pass
93
 
 
94
 
        try:
95
 
            idx = url.rindex('/')
96
 
        except ValueError:
97
 
            raise BzrError('no branch root found for URL %s' % orig_url)
98
 
 
99
 
        url = url[:idx]        
100
 
        
101
 
 
102
 
 
103
70
class RemoteBranch(Branch):
104
 
    def __init__(self, baseurl, find_root=True, lock_mode='r'):
 
71
    def __init__(self, baseurl):
105
72
        """Create new proxy for a remote branch."""
106
 
        if lock_mode not in ('', 'r'):
107
 
            raise BzrError('lock mode %r is not supported for remote branches'
108
 
                           % lock_mode)
109
 
 
110
 
        if find_root:
111
 
            self.baseurl = _find_remote_root(baseurl)
112
 
        else:
113
 
            self.baseurl = baseurl
114
 
            self._check_format()
115
 
 
116
 
    def __str__(self):
117
 
        return '%s(%r)' % (self.__class__.__name__, self.baseurl)
118
 
 
119
 
    __repr__ = __str__
 
73
        self.baseurl = baseurl
 
74
        self._check_format()
120
75
 
121
76
    def controlfile(self, filename, mode):
122
77
        if mode not in ('rb', 'rt', 'r'):
130
85
    def _need_writelock(self):
131
86
        raise BzrError("cannot get write lock on HTTP remote branch")
132
87
 
133
 
    def relpath(self, path):
134
 
        if not path.startswith(self.baseurl):
135
 
            raise BzrError('path %r is not under base URL %r'
136
 
                           % (path, self.baseurl))
137
 
        pl = len(self.baseurl)
138
 
        return path[pl:].lstrip('/')
139
 
 
140
88
    def get_revision(self, revision_id):
141
89
        from revision import Revision
142
90
        revf = get_url(self.baseurl + '/.bzr/revision-store/' + revision_id,