hgext/phabricator.py
changeset 44127 59b3fe1e2021
parent 44076 a7c4bcf7018a
child 44128 ff396501e841
--- a/hgext/phabricator.py	Fri Jan 17 13:29:47 2020 -0500
+++ b/hgext/phabricator.py	Fri Jan 17 14:21:40 2020 -0500
@@ -66,6 +66,7 @@
     exthelper,
     graphmod,
     httpconnection as httpconnectionmod,
+    localrepo,
     logcmdutil,
     match,
     mdiff,
@@ -101,6 +102,7 @@
 command = eh.command
 configtable = eh.configtable
 templatekeyword = eh.templatekeyword
+uisetup = eh.finaluisetup
 
 # developer config: phabricator.batchsize
 eh.configitem(
@@ -152,6 +154,39 @@
 ]
 
 
+@eh.wrapfunction(localrepo, "loadhgrc")
+def _loadhgrc(orig, ui, wdirvfs, hgvfs, requirements):
+    """Load ``.arcconfig`` content into a ui instance on repository open.
+    """
+    result = False
+    arcconfig = {}
+
+    try:
+        # json.loads only accepts bytes from 3.6+
+        rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig"))
+        # json.loads only returns unicode strings
+        arcconfig = pycompat.rapply(
+            lambda x: encoding.unitolocal(x)
+            if isinstance(x, pycompat.unicode)
+            else x,
+            pycompat.json_loads(rawparams),
+        )
+
+        result = True
+    except ValueError:
+        ui.warn(_(b"invalid JSON in %s\n") % wdirvfs.join(b".arcconfig"))
+    except IOError:
+        pass
+
+    if b"repository.callsign" in arcconfig:
+        ui.applyconfig(
+            {(b"phabricator", b"callsign"): arcconfig[b"repository.callsign"]},
+            source=wdirvfs.join(b".arcconfig"),
+        )
+
+    return orig(ui, wdirvfs, hgvfs, requirements) or result  # Load .hg/hgrc
+
+
 def vcrcommand(name, flags, spec, helpcategory=None, optionalrepo=False):
     fullflags = flags + _VCR_FLAGS