Mercurial > evolve
diff hgext/simple4server.py @ 866:c6dc5822e640
simple4server: add the wireproto command for obsolescence markers discovery
This come with its usual train of duplicated utility.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 05 Mar 2014 15:21:21 -0800 |
parents | aa722de36179 |
children | e9eeef0d07ec |
line wrap: on
line diff
--- a/hgext/simple4server.py Wed Mar 05 15:14:40 2014 -0800 +++ b/hgext/simple4server.py Wed Mar 05 15:21:21 2014 -0800 @@ -127,12 +127,52 @@ yield c return wireproto.streamres(data()) + +def _obsrelsethashtree(repo): + cache = [] + unfi = repo.unfiltered() + for i in unfi: + ctx = unfi[i] + entry = 0 + sha = util.sha1() + # add data from p1 + for p in ctx.parents(): + p = p.rev() + if p < 0: + p = node.nullid + else: + p = cache[p][1] + if p != node.nullid: + entry += 1 + sha.update(p) + tmarkers = repo.obsstore.relevantmarkers([ctx.node()]) + if tmarkers: + bmarkers = [obsolete._encodeonemarker(m) for m in tmarkers] + bmarkers.sort() + for m in bmarkers: + entry += 1 + sha.update(m) + if entry: + cache.append((ctx.node(), sha.digest())) + else: + cache.append((ctx.node(), node.nullid)) + return cache + +def _obshash(repo, nodes): + hashs = _obsrelsethashtree(repo) + nm = repo.changelog.nodemap + return [hashs[nm.get(n)][1] for n in nodes] + +def srv_obshash(repo, proto, nodes): + return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes))) + def capabilities(orig, repo, proto): """wrapper to advertise new capability""" caps = orig(repo, proto) if obsolete._enabled: caps += ' _evoext_pushobsmarkers_0' caps += ' _evoext_pullobsmarkers_0' + caps += ' _evoext_obshash_0' return caps def extsetup(ui): @@ -141,3 +181,4 @@ wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '') wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*') extensions.wrapfunction(wireproto, 'capabilities', capabilities) + wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')