sapling/hgext3rd/logginghelper.py

48 lines
1.3 KiB
Python
Raw Normal View History

[reporootlog] report the repo root to the scm wrappers Summary: The SCM wrappers do not have a reliable and easy way of detecting the repo root. For instance, if someone does hg log /full/path/to/repo/content, we cannot actually determine that /full/path/to/repo is the repo root. We have to somehow integrate an overly large portion of mercurial's commmand parsing infrastrastructure to accomplish this. However, since mercurial knows the repo root, just extract that knowledge and send it down to the client. Test Plan: ``` [dev8692]:~> USE_DIST_HG= FB_HG_DIAGS= hg log --config 'sampling.key.reporootlog=perfpipe_dev_command_timers' --config 'extensions.reporootlog=work/facebook-hg-rpms/fb-hgext/hgext3rd/reporootlog.py' work/facebook-hg-rpms/smoketest.sh chg: enabled by /etc/mercurial/usechg <snipped for brevity> internal stats file: /tmp/scm-internal-stats5BoW29 hg profiling mode: LSPROFILER stats: { "int": { "builddate": 1469712764, "cachehitratio": 50, "consumed": 302, "diffcachehitratio": -1, "elapsed": 130, "errorcode": 0, "filesnotincachehitratio": -1, "time": 1469819716 }, "normal": { "chg": "true", "command": "log", "evolution": "createmarkers", "evolutionext": "-*- empty -*-", "fastmanifest": "-*- empty -*-", "filesystem": "", "fsmonitor_ext": "-*- not present -*-", "fsmonitor_mode": "on", "fullcommand": "\/usr\/bin\/hg log --config sampling.key.reporootlog=perfpipe_dev_command_timers --config extensions.reporootlog=work\/facebook-hg-rpms\/fb-hgext\/hgext3rd\/reporootlog.py work\/facebook-hg-rpms\/smoketest.sh", "generaldelta": "false", "host": "dev8692.prn1", "iftype": "disconnected", "interactive": "true", "kernel": "4.0.9-30_fbk4_2311_gd3e5a5c", "metrics_type": "fastmanifest-filesnotincachehitratio", "msg": "", "parent": "\/bin\/bash", "remotefilelog": "false", "repo": "work\/facebook-hg-rpms", "scm": "hg", "sid": "", "source": "hg", "sqldirstate": "false", "sqldirstate_enabled": "-*- not present -*-", "sqldirstate_loaded": "-*- empty -*-", "sqldirstate_upgrade": "True", "sshclient": "localhost", "tw_job_cluster": "", "tw_job_name": "", "tw_job_user": "", "tw_oncall_team": "", "tw_task_id": "", "user": "ttung", "version": "3.8.4+443-d0746b" } } [dev8692]:~> ``` Without this change, the repo would be "unknown-repo": ``` [dev8692]:~> USE_DIST_HG= FB_HG_DIAGS= hg log --config 'sampling.key.reporootlog=perfpipe_dev_command_timers' work/facebook-hg-rpms/smoketest.sh 2>&1 | grep repo "fullcommand": "\/usr\/bin\/hg log --config sampling.key.reporootlog=perfpipe_dev_command_timers work\/facebook-hg-rpms\/smoketest.sh", "repo": "unknown-repo", [dev8692]:~> ``` Reviewers: #mercurial, rmcelroy, quark Reviewed By: quark Subscribers: quark, mitrandir, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D3643342 Tasks: 11194713 Signature: t1:3643342:1470163958:8d56291dad575c7ea7186cf5d00420798c5303ab
2016-08-02 21:59:52 +03:00
# reporootlog.py - log the repo root
#
# Copyright 2016 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""this extension logs different pieces of information that will be used
by SCM wrappers
::
[logging]
# list of config options to log
configoptions = section1.option1,section2.option2
[reporootlog] report the repo root to the scm wrappers Summary: The SCM wrappers do not have a reliable and easy way of detecting the repo root. For instance, if someone does hg log /full/path/to/repo/content, we cannot actually determine that /full/path/to/repo is the repo root. We have to somehow integrate an overly large portion of mercurial's commmand parsing infrastrastructure to accomplish this. However, since mercurial knows the repo root, just extract that knowledge and send it down to the client. Test Plan: ``` [dev8692]:~> USE_DIST_HG= FB_HG_DIAGS= hg log --config 'sampling.key.reporootlog=perfpipe_dev_command_timers' --config 'extensions.reporootlog=work/facebook-hg-rpms/fb-hgext/hgext3rd/reporootlog.py' work/facebook-hg-rpms/smoketest.sh chg: enabled by /etc/mercurial/usechg <snipped for brevity> internal stats file: /tmp/scm-internal-stats5BoW29 hg profiling mode: LSPROFILER stats: { "int": { "builddate": 1469712764, "cachehitratio": 50, "consumed": 302, "diffcachehitratio": -1, "elapsed": 130, "errorcode": 0, "filesnotincachehitratio": -1, "time": 1469819716 }, "normal": { "chg": "true", "command": "log", "evolution": "createmarkers", "evolutionext": "-*- empty -*-", "fastmanifest": "-*- empty -*-", "filesystem": "", "fsmonitor_ext": "-*- not present -*-", "fsmonitor_mode": "on", "fullcommand": "\/usr\/bin\/hg log --config sampling.key.reporootlog=perfpipe_dev_command_timers --config extensions.reporootlog=work\/facebook-hg-rpms\/fb-hgext\/hgext3rd\/reporootlog.py work\/facebook-hg-rpms\/smoketest.sh", "generaldelta": "false", "host": "dev8692.prn1", "iftype": "disconnected", "interactive": "true", "kernel": "4.0.9-30_fbk4_2311_gd3e5a5c", "metrics_type": "fastmanifest-filesnotincachehitratio", "msg": "", "parent": "\/bin\/bash", "remotefilelog": "false", "repo": "work\/facebook-hg-rpms", "scm": "hg", "sid": "", "source": "hg", "sqldirstate": "false", "sqldirstate_enabled": "-*- not present -*-", "sqldirstate_loaded": "-*- empty -*-", "sqldirstate_upgrade": "True", "sshclient": "localhost", "tw_job_cluster": "", "tw_job_name": "", "tw_job_user": "", "tw_oncall_team": "", "tw_task_id": "", "user": "ttung", "version": "3.8.4+443-d0746b" } } [dev8692]:~> ``` Without this change, the repo would be "unknown-repo": ``` [dev8692]:~> USE_DIST_HG= FB_HG_DIAGS= hg log --config 'sampling.key.reporootlog=perfpipe_dev_command_timers' work/facebook-hg-rpms/smoketest.sh 2>&1 | grep repo "fullcommand": "\/usr\/bin\/hg log --config sampling.key.reporootlog=perfpipe_dev_command_timers work\/facebook-hg-rpms\/smoketest.sh", "repo": "unknown-repo", [dev8692]:~> ``` Reviewers: #mercurial, rmcelroy, quark Reviewed By: quark Subscribers: quark, mitrandir, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D3643342 Tasks: 11194713 Signature: t1:3643342:1470163958:8d56291dad575c7ea7186cf5d00420798c5303ab
2016-08-02 21:59:52 +03:00
"""
import os
from mercurial import (
extensions,
localrepo,
)
def _localrepoinit(orig, self, baseui, path=None, create=False):
orig(self, baseui, path, create)
reponame = self.ui.config('paths', 'default', path)
if reponame:
reponame = os.path.basename(reponame)
configoptstolog = self.ui.configlist('logging', 'configoptions')
kwargs = {'repo': reponame}
for option in configoptstolog:
splitted = option.split('.')
if len(splitted) != 2:
continue
section, name = splitted
value = self.ui.config(section, name, None)
if value is not None:
kwargs[name] = value
self.ui.log("logginghelper",
[reporootlog] report the repo root to the scm wrappers Summary: The SCM wrappers do not have a reliable and easy way of detecting the repo root. For instance, if someone does hg log /full/path/to/repo/content, we cannot actually determine that /full/path/to/repo is the repo root. We have to somehow integrate an overly large portion of mercurial's commmand parsing infrastrastructure to accomplish this. However, since mercurial knows the repo root, just extract that knowledge and send it down to the client. Test Plan: ``` [dev8692]:~> USE_DIST_HG= FB_HG_DIAGS= hg log --config 'sampling.key.reporootlog=perfpipe_dev_command_timers' --config 'extensions.reporootlog=work/facebook-hg-rpms/fb-hgext/hgext3rd/reporootlog.py' work/facebook-hg-rpms/smoketest.sh chg: enabled by /etc/mercurial/usechg <snipped for brevity> internal stats file: /tmp/scm-internal-stats5BoW29 hg profiling mode: LSPROFILER stats: { "int": { "builddate": 1469712764, "cachehitratio": 50, "consumed": 302, "diffcachehitratio": -1, "elapsed": 130, "errorcode": 0, "filesnotincachehitratio": -1, "time": 1469819716 }, "normal": { "chg": "true", "command": "log", "evolution": "createmarkers", "evolutionext": "-*- empty -*-", "fastmanifest": "-*- empty -*-", "filesystem": "", "fsmonitor_ext": "-*- not present -*-", "fsmonitor_mode": "on", "fullcommand": "\/usr\/bin\/hg log --config sampling.key.reporootlog=perfpipe_dev_command_timers --config extensions.reporootlog=work\/facebook-hg-rpms\/fb-hgext\/hgext3rd\/reporootlog.py work\/facebook-hg-rpms\/smoketest.sh", "generaldelta": "false", "host": "dev8692.prn1", "iftype": "disconnected", "interactive": "true", "kernel": "4.0.9-30_fbk4_2311_gd3e5a5c", "metrics_type": "fastmanifest-filesnotincachehitratio", "msg": "", "parent": "\/bin\/bash", "remotefilelog": "false", "repo": "work\/facebook-hg-rpms", "scm": "hg", "sid": "", "source": "hg", "sqldirstate": "false", "sqldirstate_enabled": "-*- not present -*-", "sqldirstate_loaded": "-*- empty -*-", "sqldirstate_upgrade": "True", "sshclient": "localhost", "tw_job_cluster": "", "tw_job_name": "", "tw_job_user": "", "tw_oncall_team": "", "tw_task_id": "", "user": "ttung", "version": "3.8.4+443-d0746b" } } [dev8692]:~> ``` Without this change, the repo would be "unknown-repo": ``` [dev8692]:~> USE_DIST_HG= FB_HG_DIAGS= hg log --config 'sampling.key.reporootlog=perfpipe_dev_command_timers' work/facebook-hg-rpms/smoketest.sh 2>&1 | grep repo "fullcommand": "\/usr\/bin\/hg log --config sampling.key.reporootlog=perfpipe_dev_command_timers work\/facebook-hg-rpms\/smoketest.sh", "repo": "unknown-repo", [dev8692]:~> ``` Reviewers: #mercurial, rmcelroy, quark Reviewed By: quark Subscribers: quark, mitrandir, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D3643342 Tasks: 11194713 Signature: t1:3643342:1470163958:8d56291dad575c7ea7186cf5d00420798c5303ab
2016-08-02 21:59:52 +03:00
"", # ui.log requires a format string as args[0].
**kwargs)
def uisetup(ui):
extensions.wrapfunction(localrepo.localrepository,
'__init__', _localrepoinit)