2021-01-11 21:44:56 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
2019-04-04 21:23:56 +03:00
|
|
|
# An extension to make identifiers from util.makerandomidentifier into a stable
|
|
|
|
# incrementing sequence.
|
|
|
|
import os
|
|
|
|
|
2021-01-11 21:44:56 +03:00
|
|
|
from edenscm.hgext import extutil, clienttelemetry
|
2019-04-04 21:23:56 +03:00
|
|
|
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:
|
2020-05-07 19:05:16 +03:00
|
|
|
with open(stableidentifierfile) as f:
|
|
|
|
coid = int(f.read().strip())
|
2019-04-04 21:23:56 +03:00
|
|
|
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)
|
2021-01-11 21:44:56 +03:00
|
|
|
clienttelemetry._correlator = "stableidentifiers:correlator"
|