[PATCH evolve-ext] touch: make sure the new noise number is different from the old one

Jun Wu quark at fb.com
Sat Apr 2 01:09:26 UTC 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1459558346 -3600
#      Sat Apr 02 01:52:26 2016 +0100
# Node ID ed7b2174e2f41a432b5000d54f48d11387f41eba
# Parent  9ae4e79a28f3c09e76567f68be3d6f82e650e55b
touch: make sure the new noise number is different from the old one

Before this patch, there is no check to ensure the new touch noise is different
from the old one. It may cause issues in some situations where the generated
random numbers are the same. For example, when running with chg, the forked
request handler process will inherit the state of random from its parent, which
is always same if the parent process hasn't changed. Another example is when
debugging, people may want to unrandomize everything to get reproducible
results.

This patch addresses the issue by changing the way the new touch-noise is
calculated to make sure it will be different from the old one.

Another patch will make chg change random state per request.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2990,7 +2990,9 @@
         for r in revs:
             ctx = repo[r]
             extra = ctx.extra().copy()
-            extra['__touch-noise__'] = random.randint(0, 0xffffffff)
+            noise = int(extra.get('__touch-noise__', 0))
+            noise += random.randint(1, 0xffffffff) & 0xffffffff
+            extra['__touch-noise__'] = str(noise)
             # search for touched parent
             p1 = ctx.p1().node()
             p2 = ctx.p2().node()


More information about the Mercurial-devel mailing list