##// END OF EJS Templates
Push capability checking into protocol-level code.
Bryan O'Sullivan -
r5259:65dc7076 default
parent child Browse files
Show More
@@ -1645,11 +1645,7 b' def incoming(ui, repo, source="default",'
1645 other = hg.repository(ui, source)
1645 other = hg.repository(ui, source)
1646 ui.status(_('comparing with %s\n') % source)
1646 ui.status(_('comparing with %s\n') % source)
1647 if revs:
1647 if revs:
1648 if 'lookup' in other.capabilities:
1648 revs = [other.lookup(rev) for rev in revs]
1649 revs = [other.lookup(rev) for rev in revs]
1650 else:
1651 error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
1652 raise util.Abort(error)
1653 incoming = repo.findincoming(other, heads=revs, force=opts["force"])
1649 incoming = repo.findincoming(other, heads=revs, force=opts["force"])
1654 if not incoming:
1650 if not incoming:
1655 try:
1651 try:
@@ -1667,8 +1663,6 b' def incoming(ui, repo, source="default",'
1667 if revs is None:
1663 if revs is None:
1668 cg = other.changegroup(incoming, "incoming")
1664 cg = other.changegroup(incoming, "incoming")
1669 else:
1665 else:
1670 if 'changegroupsubset' not in other.capabilities:
1671 raise util.Abort(_("Partial incoming cannot be done because other repository doesn't support changegroupsubset."))
1672 cg = other.changegroupsubset(incoming, revs, 'incoming')
1666 cg = other.changegroupsubset(incoming, revs, 'incoming')
1673 bundletype = other.local() and "HG10BZ" or "HG10UN"
1667 bundletype = other.local() and "HG10BZ" or "HG10UN"
1674 fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
1668 fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
@@ -2078,10 +2072,11 b' def pull(ui, repo, source="default", **o'
2078 other = hg.repository(ui, source)
2072 other = hg.repository(ui, source)
2079 ui.status(_('pulling from %s\n') % (source))
2073 ui.status(_('pulling from %s\n') % (source))
2080 if revs:
2074 if revs:
2081 if 'lookup' in other.capabilities:
2075 try:
2082 revs = [other.lookup(rev) for rev in revs]
2076 revs = [other.lookup(rev) for rev in revs]
2083 else:
2077 except repo.NoCapability:
2084 error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
2078 error = _("Other repository doesn't support revision lookup, "
2079 "so a rev cannot be specified.")
2085 raise util.Abort(error)
2080 raise util.Abort(error)
2086
2081
2087 modheads = repo.pull(other, heads=revs, force=opts['force'])
2082 modheads = repo.pull(other, heads=revs, force=opts['force'])
@@ -354,6 +354,7 b' class httprepository(remoterepository):'
354 fp.close()
354 fp.close()
355
355
356 def lookup(self, key):
356 def lookup(self, key):
357 self.requirecap('lookup', _('look up remote revision'))
357 d = self.do_cmd("lookup", key = key).read()
358 d = self.do_cmd("lookup", key = key).read()
358 success, data = d[:-1].split(' ', 1)
359 success, data = d[:-1].split(' ', 1)
359 if int(success):
360 if int(success):
@@ -391,6 +392,7 b' class httprepository(remoterepository):'
391 return util.chunkbuffer(zgenerator(f))
392 return util.chunkbuffer(zgenerator(f))
392
393
393 def changegroupsubset(self, bases, heads, source):
394 def changegroupsubset(self, bases, heads, source):
395 self.requirecap('changegroupsubset', _('look up remote changes'))
394 baselst = " ".join([hex(n) for n in bases])
396 baselst = " ".join([hex(n) for n in bases])
395 headlst = " ".join([hex(n) for n in heads])
397 headlst = " ".join([hex(n) for n in heads])
396 f = self.do_cmd("changegroupsubset", bases=baselst, heads=headlst)
398 f = self.do_cmd("changegroupsubset", bases=baselst, heads=headlst)
@@ -9,16 +9,26 b''
9 class RepoError(Exception):
9 class RepoError(Exception):
10 pass
10 pass
11
11
12 class NoCapability(RepoError):
13 pass
14
12 class repository(object):
15 class repository(object):
13 def capable(self, name):
16 def capable(self, name):
14 '''tell whether repo supports named capability.
17 '''tell whether repo supports named capability.
15 return False if not supported.
18 return False if not supported.
16 if boolean capability, return True.
19 if boolean capability, return True.
17 if string capability, return string.'''
20 if string capability, return string.'''
21 if name in self.capabilities:
22 return True
18 name_eq = name + '='
23 name_eq = name + '='
19 for cap in self.capabilities:
24 for cap in self.capabilities:
20 if name == cap:
21 return True
22 if cap.startswith(name_eq):
25 if cap.startswith(name_eq):
23 return cap[len(name_eq):]
26 return cap[len(name_eq):]
24 return False
27 return False
28
29 def requirecap(self, name, purpose):
30 '''raise an exception if the given capability is not present'''
31 if not self.capable(name):
32 raise NoCapability(_('cannot %s; remote repository does not '
33 'support the %r capability') %
34 (purpose, name))
@@ -131,6 +131,7 b' class sshrepository(remoterepository):'
131 self.call("unlock")
131 self.call("unlock")
132
132
133 def lookup(self, key):
133 def lookup(self, key):
134 self.requirecap('lookup', _('look up remote revision'))
134 d = self.call("lookup", key=key)
135 d = self.call("lookup", key=key)
135 success, data = d[:-1].split(" ", 1)
136 success, data = d[:-1].split(" ", 1)
136 if int(success):
137 if int(success):
@@ -168,6 +169,7 b' class sshrepository(remoterepository):'
168 return self.do_cmd("changegroup", roots=n)
169 return self.do_cmd("changegroup", roots=n)
169
170
170 def changegroupsubset(self, bases, heads, kind):
171 def changegroupsubset(self, bases, heads, kind):
172 self.requirecap('changegroupsubset', _('look up remote changes'))
171 bases = " ".join(map(hex, bases))
173 bases = " ".join(map(hex, bases))
172 heads = " ".join(map(hex, heads))
174 heads = " ".join(map(hex, heads))
173 return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
175 return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
General Comments 0
You need to be logged in to leave comments. Login now