28
28
from cStringIO import StringIO
31
from errors import BzrError, BzrCheckError
32
from branch import Branch, BZR_BRANCH_FORMAT
33
from trace import mutter
35
# velocitynet.com.au transparently proxies connections and thereby
36
# breaks keep-alive -- sucks!
39
ENABLE_URLGRABBER = True
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
39
ENABLE_URLGRABBER = False
41
from bzrlib.errors import BzrError, NoSuchRevision
43
class GetFailed(BzrError):
44
def __init__(self, url, status):
45
BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
42
49
if ENABLE_URLGRABBER:
44
import urlgrabber.keepalive
45
urlgrabber.keepalive.DEBUG = 0
50
import util.urlgrabber
51
import util.urlgrabber.keepalive
52
util.urlgrabber.keepalive.DEBUG = 0
46
53
def get_url(path, compressed=False):
51
58
mutter("grab url %s" % url)
52
url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
59
url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
60
if url_f.status != 200:
61
raise GetFailed(url, url_f.status)
89
98
except urllib2.URLError:
95
raise BzrError('no branch root found for URL %s' % orig_url)
101
scheme, host, path = list(urlparse.urlparse(url))[:3]
102
# discard params, query, fragment
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'
111
url = urlparse.urlunparse((scheme, host, path, '', '', ''))
147
161
def get_revision(self, revision_id):
148
from bzrlib.revision import Revision
149
from bzrlib.xml import unpack_xml
150
revf = self.revision_store[revision_id]
151
r = unpack_xml(Revision, revf)
163
revf = self.revision_store[revision_id]
165
raise NoSuchRevision(self, revision_id)
166
r = serializer_v4.read_revision(revf)
152
167
if r.revision_id != revision_id:
153
168
raise BzrCheckError('revision stored as {%s} actually contains {%s}'
154
169
% (revision_id, r.revision_id))