hgext/simple4server.py
changeset 1248 4279ec5ff3a7
parent 1215 004e21b8d67b
parent 1246 c7db753ca300
child 1272 749c931aa47b
--- a/hgext/simple4server.py	Fri Apr 10 23:16:10 2015 -0400
+++ b/hgext/simple4server.py	Fri Apr 10 23:48:23 2015 -0400
@@ -24,6 +24,7 @@
 from mercurial import bundle2
 from mercurial import localrepo
 from mercurial import exchange
+from mercurial import node
 _pack = struct.pack
 
 gboptslist = gboptsmap = None
@@ -174,17 +175,27 @@
     return wireproto.streamres(proto.groupchunks(finaldata))
 
 
-# from evolve extension: 1a23c7c52a43
-def _obsrelsethashtree(repo):
-    """Build an obshash for every node in a repo
+# from evolve extension: 3249814dabd1
+def _obsrelsethashtreefm0(repo):
+    return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
 
-    return a [(node), (obshash)] list. in revision order."""
+# from evolve extension: 3249814dabd1
+def _obsrelsethashtreefm1(repo):
+    return _obsrelsethashtree(repo, obsolete._fm1encodeonemarker)
+
+# from evolve extension: 3249814dabd1
+def _obsrelsethashtree(repo, encodeonemarker):
     cache = []
     unfi = repo.unfiltered()
+    markercache = {}
     for i in unfi:
         ctx = unfi[i]
         entry = 0
         sha = util.sha1()
+        issue4587 = ctx.hex() == "195dbd1cef0c2f9f8bcf4ea303238105f716bda3"
+        if issue4587:
+            import sys
+            print >> sys.stderr, 'Witchcraft tracking: ON'
         # add data from p1
         for p in ctx.parents():
             p = p.rev()
@@ -195,37 +206,53 @@
             if p != node.nullid:
                 entry += 1
                 sha.update(p)
+                if issue4587:
+                    print >> sys.stderr, '  Parent: %r' % p
+                    print >> sys.stderr, '   Value: %s' % sha.hexdigest()
         tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
         if tmarkers:
-            bmarkers = [obsolete._fm0encodeonemarker(m) for m in tmarkers]
+            bmarkers = []
+            for m in tmarkers:
+                if not m in markercache:
+                    markercache[m] = encodeonemarker(m)
+                bmarkers.append(markercache[m])
             bmarkers.sort()
             for m in bmarkers:
                 entry += 1
                 sha.update(m)
+                if issue4587:
+                    print >> sys.stderr, '  Marker: %r' % m
+                    print >> sys.stderr, '   Value: %s' % sha.hexdigest()
         if entry:
             cache.append((ctx.node(), sha.digest()))
         else:
             cache.append((ctx.node(), node.nullid))
+        if issue4587:
+            print >> sys.stderr, '   Final: %s' % sha.hexdigest()
+            print >> sys.stderr, 'Witchcraft tracking: OFF'
     return cache
 
-# from evolve extension: 1a23c7c52a43
-def _obshash(repo, nodes):
-    """hash of binary version of relevant markers + obsparent
-
-    (special case so that all empty are hashed as nullid)"""
-    hashs = _obsrelsethashtree(repo)
+# from evolve extension: 3249814dabd1
+def _obshash(repo, nodes, version=0):
+    if version == 0:
+        hashs = _obsrelsethashtreefm0(repo)
+    elif version ==1:
+        hashs = _obsrelsethashtreefm1(repo)
+    else:
+        assert False
     nm = repo.changelog.nodemap
     revs = [nm.get(n) for n in nodes]
     return [r is None and node.nullid or hashs[r][1] for r in revs]
 
-# from evolve extension: 1a23c7c52a43
+# from evolve extension: 3249814dabd1
 def srv_obshash(repo, proto, nodes):
-    """give the obshash of a a set of node
-
-    Used for markes discovery"""
     return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes)))
 
-# from evolve extension: 1a23c7c52a43
+# from evolve extension: 3249814dabd1
+def srv_obshash1(repo, proto, nodes):
+    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes), version=1))
+
+# from evolve extension: 3249814dabd1
 def capabilities(orig, repo, proto):
     """wrapper to advertise new capability"""
     caps = orig(repo, proto)
@@ -234,6 +261,7 @@
         caps += ' _evoext_pushobsmarkers_0'
         caps += ' _evoext_pullobsmarkers_0'
         caps += ' _evoext_obshash_0'
+        caps += ' _evoext_obshash_1'
         caps += ' _evoext_getbundle_obscommon'
     return caps
 
@@ -273,6 +301,7 @@
         return capabilities(oldcap, repo, proto)
     wireproto.commands['capabilities'] = (newcap, args)
     wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
+    wireproto.commands['evoext_obshash1'] = (srv_obshash1, 'nodes')
     # specific simple4server content
     extensions.wrapfunction(pushkey, '_nslist', _nslist)
     pushkey._namespaces['namespaces'] = (lambda *x: False, pushkey._nslist)