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
This commit is contained in:
Thomas Orozco 2020-05-15 03:00:02 -07:00 committed by Facebook GitHub Bot
parent e96c923fba
commit 6676a7a476
3 changed files with 43 additions and 0 deletions

View File

@ -31,6 +31,8 @@ def _localrepoinit(orig, self, baseui, path=None, create=False):
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

View File

@ -96,3 +96,5 @@ Verify logging uses correct repo name
> EOF
$ python logverify.py | uniq
repo: repo
repo: client
repo: repo

View File

@ -0,0 +1,39 @@
#require jq
#chg-compatible
$ . "$TESTDIR/library.sh"
$ enable logginghelper
$ enable sampling
$ setconfig sampling.key.logginghelper=logginghelper
$ hg init repo123
$ cd repo123
$ export SCM_SAMPLING_FILEPATH="$TESTTMP/sample"
Check we got the repository name from the local path
$ hg status
$ tr '\0' '\n' < "$SCM_SAMPLING_FILEPATH" | jq -r .data.repo
repo123
$ rm "$SCM_SAMPLING_FILEPATH"
Check that it doesn't matter where we are in the repo
$ mkdir foobar
$ cd foobar
$ hg status
$ tr '\0' '\n' < "$SCM_SAMPLING_FILEPATH" | jq -r .data.repo
repo123
$ rm "$SCM_SAMPLING_FILEPATH"
$ cd ..
Check we got the repository name from the remote path
$ setconfig paths.default=ssh://foo.com//bar/repo456
$ hg status
$ tr '\0' '\n' < "$SCM_SAMPLING_FILEPATH" | jq -r .data.repo
repo456
$ rm "$SCM_SAMPLING_FILEPATH"