sapling/eden/scm/tests/stableidentifiers.py
Thomas Orozco 9d7b0267dd revisionstore: pass client correlator
Summary:
We used to get those in the old (Python) LFS extension, but didn't have them in
the new one. However, this is helpful to correlate requests to LFS with data in
hg logs. It's also convenient to be able to identify whether a set of requests
are part of the same session or not.

This diffs threads the client correlator through to the LFS store from the
Python, similarly to how it's done in EdenAPI.

Reviewed By: DurhamG

Differential Revision: D25804930

fbshipit-source-id: a5d5508617fa4184344834bbd8e3423816aa7668
2021-01-11 10:46:20 -08:00

30 lines
1022 B
Python

# 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.
# An extension to make identifiers from util.makerandomidentifier into a stable
# incrementing sequence.
import os
from edenscm.hgext import extutil, clienttelemetry
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)
clienttelemetry._correlator = "stableidentifiers:correlator"