##// END OF EJS Templates
Simplify content type checking
mpm@selenic.com -
r752:c693eafd default
parent child Browse files
Show More
@@ -1743,7 +1743,13 b' class httprepository:'
1743 q.update(args)
1743 q.update(args)
1744 qs = urllib.urlencode(q)
1744 qs = urllib.urlencode(q)
1745 cu = "%s?%s" % (self.url, qs)
1745 cu = "%s?%s" % (self.url, qs)
1746 return urllib2.urlopen(cu)
1746 resp = urllib2.urlopen(cu)
1747
1748 if not resp.headers['content-type'].startswith('application/hg'):
1749 raise RepoError("'%s' does not appear to be an hg repository"
1750 % self.url)
1751
1752 return resp
1747
1753
1748 def heads(self):
1754 def heads(self):
1749 d = self.do_cmd("heads").read()
1755 d = self.do_cmd("heads").read()
@@ -1753,20 +1759,10 b' class httprepository:'
1753 self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n")
1759 self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n")
1754 raise
1760 raise
1755
1761
1756 def verify_hg_repo(self, resp):
1757 if (resp.headers['content-type'] == 'application/hg-0.1'):
1758 pass
1759 else:
1760 msg = """'%s' does not appear to be a valid hg repository -
1761 missing a 'Content-type: application/hg-0.1' HTTP header""" % (self.url,)
1762 raise RepoError(msg)
1763
1764 def branches(self, nodes):
1762 def branches(self, nodes):
1765 n = " ".join(map(hex, nodes))
1763 n = " ".join(map(hex, nodes))
1766 resp = self.do_cmd("branches", nodes=n);
1764 d = self.do_cmd("branches", nodes=n).read()
1767 self.verify_hg_repo(resp);
1768 try:
1765 try:
1769 d = resp.read()
1770 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
1766 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
1771 return br
1767 return br
1772 except:
1768 except:
@@ -1775,10 +1771,8 b" missing a 'Content-type: application/hg-"
1775
1771
1776 def between(self, pairs):
1772 def between(self, pairs):
1777 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
1773 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
1778 resp = self.do_cmd("between", pairs=n)
1774 d = self.do_cmd("between", pairs=n).read()
1779 self.verify_hg_repo(resp)
1780 try:
1775 try:
1781 d = resp.read()
1782 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
1776 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
1783 return p
1777 return p
1784 except:
1778 except:
@@ -1787,8 +1781,7 b" missing a 'Content-type: application/hg-"
1787
1781
1788 def changegroup(self, nodes):
1782 def changegroup(self, nodes):
1789 n = " ".join(map(hex, nodes))
1783 n = " ".join(map(hex, nodes))
1790 resp = self.do_cmd("changegroup", roots=n)
1784 f = self.do_cmd("changegroup", roots=n)
1791 self.verify_hg_repo(resp)
1792 bytes = 0
1785 bytes = 0
1793
1786
1794 class zread:
1787 class zread:
@@ -1807,7 +1800,7 b" missing a 'Content-type: application/hg-"
1807 d, self.buf = self.buf[:l], self.buf[l:]
1800 d, self.buf = self.buf[:l], self.buf[l:]
1808 return d
1801 return d
1809
1802
1810 return zread(resp)
1803 return zread(f)
1811
1804
1812 class remotelock:
1805 class remotelock:
1813 def __init__(self, repo):
1806 def __init__(self, repo):
General Comments 0
You need to be logged in to leave comments. Login now