Mercurial > hg
comparison hgext/phabricator.py @ 44127:59b3fe1e2021
phabricator: use .arcconfig for the callsign if not set locally (issue6243)
This makes things easier for people working with more than one repository
because this file can be committed to each repository. The bug report asks to
read <repo>/.arcrc, but AFAICT, that file lives in ~/ and holds the credentials.
And we already track an .arcconfig file. Any callsign set globally is still
used if that is all that is present, but .arcconfig will override it if
available. The idea behind letting the local hgrc override .arcconfig is that
the developer may need to do testing against another server, and not dirty the
working directory.
Originally I was going to just try to read the callsign in `getrepophid()` if it
wasn't present in the hg config. That works fine, but I think it also makes
sense to read the URL from this file too. That would have worked less well
because `readurltoken()` doesn't have access to the repo object to know where to
find the file. Supplimenting the config mechanism is less magical because it
reports the source and value of the properties used, and it doesn't need to read
the file twice.
Invalid hgrc files generally cause the program to abort. I only flagged it as a
warning here because it's not our config file, not crucial to the whole program
operating, and really shouldn't be corrupt in the typical case where it is
checked into the repo.
Differential Revision: https://phab.mercurial-scm.org/D7934
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 17 Jan 2020 14:21:40 -0500 |
parents | a7c4bcf7018a |
children | ff396501e841 |
comparison
equal
deleted
inserted
replaced
44126:e2278581b1c6 | 44127:59b3fe1e2021 |
---|---|
64 encoding, | 64 encoding, |
65 error, | 65 error, |
66 exthelper, | 66 exthelper, |
67 graphmod, | 67 graphmod, |
68 httpconnection as httpconnectionmod, | 68 httpconnection as httpconnectionmod, |
69 localrepo, | |
69 logcmdutil, | 70 logcmdutil, |
70 match, | 71 match, |
71 mdiff, | 72 mdiff, |
72 obsutil, | 73 obsutil, |
73 parser, | 74 parser, |
99 | 100 |
100 cmdtable = eh.cmdtable | 101 cmdtable = eh.cmdtable |
101 command = eh.command | 102 command = eh.command |
102 configtable = eh.configtable | 103 configtable = eh.configtable |
103 templatekeyword = eh.templatekeyword | 104 templatekeyword = eh.templatekeyword |
105 uisetup = eh.finaluisetup | |
104 | 106 |
105 # developer config: phabricator.batchsize | 107 # developer config: phabricator.batchsize |
106 eh.configitem( | 108 eh.configitem( |
107 b'phabricator', b'batchsize', default=12, | 109 b'phabricator', b'batchsize', default=12, |
108 ) | 110 ) |
148 b', otherwise will mock all http requests using the specified vcr file.' | 150 b', otherwise will mock all http requests using the specified vcr file.' |
149 b' (ADVANCED)' | 151 b' (ADVANCED)' |
150 ), | 152 ), |
151 ), | 153 ), |
152 ] | 154 ] |
155 | |
156 | |
157 @eh.wrapfunction(localrepo, "loadhgrc") | |
158 def _loadhgrc(orig, ui, wdirvfs, hgvfs, requirements): | |
159 """Load ``.arcconfig`` content into a ui instance on repository open. | |
160 """ | |
161 result = False | |
162 arcconfig = {} | |
163 | |
164 try: | |
165 # json.loads only accepts bytes from 3.6+ | |
166 rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig")) | |
167 # json.loads only returns unicode strings | |
168 arcconfig = pycompat.rapply( | |
169 lambda x: encoding.unitolocal(x) | |
170 if isinstance(x, pycompat.unicode) | |
171 else x, | |
172 pycompat.json_loads(rawparams), | |
173 ) | |
174 | |
175 result = True | |
176 except ValueError: | |
177 ui.warn(_(b"invalid JSON in %s\n") % wdirvfs.join(b".arcconfig")) | |
178 except IOError: | |
179 pass | |
180 | |
181 if b"repository.callsign" in arcconfig: | |
182 ui.applyconfig( | |
183 {(b"phabricator", b"callsign"): arcconfig[b"repository.callsign"]}, | |
184 source=wdirvfs.join(b".arcconfig"), | |
185 ) | |
186 | |
187 return orig(ui, wdirvfs, hgvfs, requirements) or result # Load .hg/hgrc | |
153 | 188 |
154 | 189 |
155 def vcrcommand(name, flags, spec, helpcategory=None, optionalrepo=False): | 190 def vcrcommand(name, flags, spec, helpcategory=None, optionalrepo=False): |
156 fullflags = flags + _VCR_FLAGS | 191 fullflags = flags + _VCR_FLAGS |
157 | 192 |