sapling/eden/scm/tests/stableidentifiers.py
Mark Thomas 052e7c3877 check-code: convert to Python 3
Summary:
Update `contrib/check-code.py` to Python 3.

Mostly it was already compatible, however stricter regular expression parsing
revealed a case where one of our tests wasn't working, and as a result lots of
instances of `open(file).read()` existed that this test should have caught.

I have fixed up most of the instances in the code, although there are many
in the test suite that I have ignored for now.

Reviewed By: quark-zju

Differential Revision: D21427212

fbshipit-source-id: 7461a7c391e0ade947f779a2b476ca937fd24a8d
2020-05-07 09:07:50 -07:00

24 lines
772 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:
with open(stableidentifierfile) as f:
coid = int(f.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)