[Request] [+- ] D8524: phabricator: load .arcconfig during reposetup (issue6331)
sfink (Steve Fink)
phabricator at mercurial-scm.org
Fri May 15 00:15:36 UTC 2020
sfink created this revision.
Herald added subscribers: mercurial-patches, Kwan.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Wrapping localrepo's loadhgrc() was not working for me because it is too late to wrap loadhgrc when the extension is loaded.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D8524
AFFECTED FILES
hgext/phabricator.py
CHANGE DETAILS
diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -41,6 +41,9 @@
# API token. Get it from https://$HOST/conduit/login/
example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+phabricator.url and callsign will fallback to values from repo's .arcconfig if
+available.
"""
from __future__ import absolute_import
@@ -165,16 +168,18 @@
]
- at eh.wrapfunction(localrepo, "loadhgrc")
-def _loadhgrc(orig, ui, wdirvfs, hgvfs, requirements):
+def reposetup(ui, repo):
"""Load ``.arcconfig`` content into a ui instance on repository open.
"""
- result = False
+ # Only check for .arcconfig on a localrepo.
+ if not hasattr(repo, 'wvfs'):
+ return
+
arcconfig = {}
try:
# json.loads only accepts bytes from 3.6+
- rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig"))
+ rawparams = encoding.unifromlocal(repo.wvfs.read(b'.arcconfig'))
# json.loads only returns unicode strings
arcconfig = pycompat.rapply(
lambda x: encoding.unitolocal(x)
@@ -182,25 +187,19 @@
else x,
pycompat.json_loads(rawparams),
)
-
- result = True
except ValueError:
- ui.warn(_(b"invalid JSON in %s\n") % wdirvfs.join(b".arcconfig"))
+ ui.warn(_(b"invalid JSON in %s\n") % repo.wvfs.join('.arcconfig'))
except IOError:
pass
cfg = util.sortdict()
+ source = repo.wvfs.join(b".arcconfig")
if b"repository.callsign" in arcconfig:
- cfg[(b"phabricator", b"callsign")] = arcconfig[b"repository.callsign"]
+ ui.setconfig(b"phabricator", b"callsign", arcconfig[b"repository.callsign"], source=source)
if b"phabricator.uri" in arcconfig:
- cfg[(b"phabricator", b"url")] = arcconfig[b"phabricator.uri"]
-
- if cfg:
- ui.applyconfig(cfg, source=wdirvfs.join(b".arcconfig"))
-
- return orig(ui, wdirvfs, hgvfs, requirements) or result # Load .hg/hgrc
+ ui.setconfig(b"phabricator", b"url", arcconfig[b"phabricator.uri"], source=source)
def vcrcommand(name, flags, spec, helpcategory=None, optionalrepo=False):
@@ -328,13 +327,18 @@
def readurltoken(ui):
"""return conduit url, token and make sure they exist
- Currently read from [auth] config section. In the future, it might
- make sense to read from .arcconfig and .arcrc as well.
+ Read token from [auth] config section. Read url from [phabricator] config
+ section or repo's .arcconfig. In the future, it might make sense to read
+ tokens from ~/.arcrc as well.
"""
url = ui.config(b'phabricator', b'url')
if not url:
raise error.Abort(
- _(b'config %s.%s is required') % (b'phabricator', b'url')
+ _(
+ b'unable to read phabricator uri from from config %s.%s or %s '
+ b'file in repo'
+ )
+ % (b'phabricator', b'url', b'.arcconfig')
)
res = httpconnectionmod.readauthforuri(ui, url, util.url(url).user)
To: sfink, #hg-reviewers
Cc: Kwan, mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200515/1529700b/attachment-0001.html>
More information about the Mercurial-patches
mailing list