mercurial/httprepo.py
changeset 7637 1d54e2f6c0b7
parent 7342 1dcd2cc6878b
child 7641 d2f753830f80
equal deleted inserted replaced
7636:e3f8c6d6b72e 7637:1d54e2f6c0b7
     7 # of the GNU General Public License, incorporated herein by reference.
     7 # of the GNU General Public License, incorporated herein by reference.
     8 
     8 
     9 from node import bin, hex, nullid
     9 from node import bin, hex, nullid
    10 from i18n import _
    10 from i18n import _
    11 import repo, os, urllib, urllib2, urlparse, zlib, util, httplib
    11 import repo, os, urllib, urllib2, urlparse, zlib, util, httplib
    12 import errno, socket, changegroup, statichttprepo
    12 import errno, socket, changegroup, statichttprepo, error, url
    13 import url
       
    14 
    13 
    15 def zgenerator(f):
    14 def zgenerator(f):
    16     zd = zlib.decompressobj()
    15     zd = zlib.decompressobj()
    17     try:
    16     try:
    18         for chunk in util.filechunkiter(f):
    17         for chunk in util.filechunkiter(f):
    46 
    45 
    47     def get_caps(self):
    46     def get_caps(self):
    48         if self.caps is None:
    47         if self.caps is None:
    49             try:
    48             try:
    50                 self.caps = util.set(self.do_read('capabilities').split())
    49                 self.caps = util.set(self.do_read('capabilities').split())
    51             except repo.RepoError:
    50             except error.RepoError:
    52                 self.caps = util.set()
    51                 self.caps = util.set()
    53             self.ui.debug(_('capabilities: %s\n') %
    52             self.ui.debug(_('capabilities: %s\n') %
    54                           (' '.join(self.caps or ['none'])))
    53                           (' '.join(self.caps or ['none'])))
    55         return self.caps
    54         return self.caps
    56 
    55 
    97         # accept old "text/plain" and "application/hg-changegroup" for now
    96         # accept old "text/plain" and "application/hg-changegroup" for now
    98         if not (proto.startswith('application/mercurial-') or
    97         if not (proto.startswith('application/mercurial-') or
    99                 proto.startswith('text/plain') or
    98                 proto.startswith('text/plain') or
   100                 proto.startswith('application/hg-changegroup')):
    99                 proto.startswith('application/hg-changegroup')):
   101             self.ui.debug(_("Requested URL: '%s'\n") % cu)
   100             self.ui.debug(_("Requested URL: '%s'\n") % cu)
   102             raise repo.RepoError(_("'%s' does not appear to be an hg repository")
   101             raise error.RepoError(_("'%s' does not appear to be an hg repository")
   103                                % self._url)
   102                                   % self._url)
   104 
   103 
   105         if proto.startswith('application/mercurial-'):
   104         if proto.startswith('application/mercurial-'):
   106             try:
   105             try:
   107                 version = proto.split('-', 1)[1]
   106                 version = proto.split('-', 1)[1]
   108                 version_info = tuple([int(n) for n in version.split('.')])
   107                 version_info = tuple([int(n) for n in version.split('.')])
   109             except ValueError:
   108             except ValueError:
   110                 raise repo.RepoError(_("'%s' sent a broken Content-Type "
   109                 raise error.RepoError(_("'%s' sent a broken Content-Type "
   111                                      "header (%s)") % (self._url, proto))
   110                                         "header (%s)") % (self._url, proto))
   112             if version_info > (0, 1):
   111             if version_info > (0, 1):
   113                 raise repo.RepoError(_("'%s' uses newer protocol %s") %
   112                 raise error.RepoError(_("'%s' uses newer protocol %s") %
   114                                    (self._url, version))
   113                                       (self._url, version))
   115 
   114 
   116         return resp
   115         return resp
   117 
   116 
   118     def do_read(self, cmd, **args):
   117     def do_read(self, cmd, **args):
   119         fp = self.do_cmd(cmd, **args)
   118         fp = self.do_cmd(cmd, **args)
   127         self.requirecap('lookup', _('look up remote revision'))
   126         self.requirecap('lookup', _('look up remote revision'))
   128         d = self.do_cmd("lookup", key = key).read()
   127         d = self.do_cmd("lookup", key = key).read()
   129         success, data = d[:-1].split(' ', 1)
   128         success, data = d[:-1].split(' ', 1)
   130         if int(success):
   129         if int(success):
   131             return bin(data)
   130             return bin(data)
   132         raise repo.RepoError(data)
   131         raise error.RepoError(data)
   133 
   132 
   134     def heads(self):
   133     def heads(self):
   135         d = self.do_read("heads")
   134         d = self.do_read("heads")
   136         try:
   135         try:
   137             return map(bin, d[:-1].split(" "))
   136             return map(bin, d[:-1].split(" "))
   231             inst = httpsrepository(ui, path)
   230             inst = httpsrepository(ui, path)
   232         else:
   231         else:
   233             inst = httprepository(ui, path)
   232             inst = httprepository(ui, path)
   234         inst.between([(nullid, nullid)])
   233         inst.between([(nullid, nullid)])
   235         return inst
   234         return inst
   236     except repo.RepoError:
   235     except error.RepoError:
   237         ui.note('(falling back to static-http)\n')
   236         ui.note('(falling back to static-http)\n')
   238         return statichttprepo.instance(ui, "static-" + path, create)
   237         return statichttprepo.instance(ui, "static-" + path, create)