sapling/eden/scm/edenscm/hgext/logginghelper.py
Thomas Orozco 6676a7a476 logginghelper: use repo basename as repo name
Summary:
When we don't provide a repo name, scm_telem_log will run `hg config` to try
and get the path, and fall back to using the basename of the repo directory.

However, this is a bit undesirable, because if we ran this code we already
checked the path, so the repo URL isn't going to magically materialize once `hg
config` asks for it, which means we make a completely redundant call to hg from
scm_telem_log.

By just doing this in logginghelper, we avoid this extra roundtrip.

Reviewed By: StanislavGlebik

Differential Revision: D21572027

fbshipit-source-id: 58e5ab2e3e525edef1ecde039cd968eab8d89172
2020-05-15 03:02:00 -07:00

75 lines
2.1 KiB
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.
# reporootlog.py - log the repo root
"""this extension logs different pieces of information that will be used
by SCM wrappers
::
[loggedconfigs]
# list of config options to log
name1 = section1.option1
name2 = section2.option2
"""
import os
from edenscm.mercurial import extensions, localrepo, registrar
configtable = {}
configitem = registrar.configitem(configtable)
def _localrepoinit(orig, self, baseui, path=None, create=False):
orig(self, baseui, path, create)
reponame = self.ui.config("paths", "default")
if reponame:
reponame = os.path.basename(reponame).split("?")[0]
if path and not reponame:
reponame = os.path.basename(path)
kwargs = {"repo": reponame}
# The configs being read here are user defined, so we need to suppress
# warnings telling us to register them.
with self.ui.configoverride({("devel", "all-warnings"): False}):
for targetname, option in self.ui.configitems("loggedconfigs"):
split = option.split(".")
if len(split) != 2:
continue
section, name = split
value = self.ui.config(section, name)
if value is not None:
kwargs[targetname] = value
obsstore_size = 0
try:
obsstore_size = self.svfs.stat("obsstore").st_size
except Exception:
# just ignore exception, it's better than failing the whole command
pass
kwargs["obsstore_size"] = obsstore_size
if "treestate" in self.requirements:
dirstateformat = "treestate"
elif "treedirstate" in self.requirements:
dirstateformat = "treedirstate"
else:
dirstateformat = "flatdirstate"
kwargs["dirstate_format"] = dirstateformat
self.ui.log(
"logginghelper", "", **kwargs # ui.log requires a format string as args[0].
)
def uisetup(ui):
extensions.wrapfunction(localrepo.localrepository, "__init__", _localrepoinit)