Commits

Anonymous committed c6dc582

simple4server: add the wireproto command for obsolescence markers discovery

This come with its usual train of duplicated utility.

Comments (0)

Files changed (1)

hgext/simple4server.py

             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):
     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')