sapling/eden/scm/tests/stableidentifiers.py
Adam Simpkins ab3a7cb21f Move fb-mercurial sources into an eden/scm subdirectory.
Summary:
In preparation for merging fb-mercurial sources to the Eden repository,
move everything from the top-level directory into an `eden/scm`
subdirectory.
2019-11-13 16:04:48 -08:00

23 lines
743 B
Python

# An extension to make identifiers from util.makerandomidentifier into a stable
# incrementing sequence.
import os
from edenscm.hgext import extutil
from edenscm.mercurial import extensions, util
def makestableidentifier(orig, length=16):
stableidentifierfile = os.path.join(os.environ["TESTTMP"], "stableidentifier")
with extutil.flock(stableidentifierfile, "stableidentifier"):
try:
coid = int(open(stableidentifierfile).read().strip())
except Exception:
coid = 0
with open(stableidentifierfile, "w") as f:
f.write("%s\n" % (coid + 1))
return "%0*d" % (length, coid)
def uisetup(ui):
extensions.wrapfunction(util, "makerandomidentifier", makestableidentifier)