comparison mercurial/commands.py @ 45497:ac7a3da0dbb6

config: add `--shared` flag to edit config file of shared source With `format.exp-share-safe` enabled, we now read the `.hg/hgrc` of the shared source also. This patch adds `--shared` flag to `hg config` command which can be used to edit that shared source config file. It only works if the repository is shared one and is shared using the safe method. Differential Revision: https://phab.mercurial-scm.org/D8659
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 17 Sep 2020 18:49:57 -0700
parents 07c424a13811
children 32ce4cbaec4b
comparison
equal deleted inserted replaced
45496:b71858b42963 45497:ac7a3da0dbb6
53 patch, 53 patch,
54 phases, 54 phases,
55 pycompat, 55 pycompat,
56 rcutil, 56 rcutil,
57 registrar, 57 registrar,
58 requirements,
58 revsetlang, 59 revsetlang,
59 rewriteutil, 60 rewriteutil,
60 scmutil, 61 scmutil,
61 server, 62 server,
62 shelve as shelvemod, 63 shelve as shelvemod,
64 streamclone, 65 streamclone,
65 tags as tagsmod, 66 tags as tagsmod,
66 ui as uimod, 67 ui as uimod,
67 util, 68 util,
68 verify as verifymod, 69 verify as verifymod,
70 vfs as vfsmod,
69 wireprotoserver, 71 wireprotoserver,
70 ) 72 )
71 from .utils import ( 73 from .utils import (
72 dateutil, 74 dateutil,
73 stringutil, 75 stringutil,
2139 b'config|showconfig|debugconfig', 2141 b'config|showconfig|debugconfig',
2140 [ 2142 [
2141 (b'u', b'untrusted', None, _(b'show untrusted configuration options')), 2143 (b'u', b'untrusted', None, _(b'show untrusted configuration options')),
2142 (b'e', b'edit', None, _(b'edit user config')), 2144 (b'e', b'edit', None, _(b'edit user config')),
2143 (b'l', b'local', None, _(b'edit repository config')), 2145 (b'l', b'local', None, _(b'edit repository config')),
2146 (
2147 b'',
2148 b'shared',
2149 None,
2150 _(b'edit shared source repository config (EXPERIMENTAL)'),
2151 ),
2144 (b'g', b'global', None, _(b'edit global config')), 2152 (b'g', b'global', None, _(b'edit global config')),
2145 ] 2153 ]
2146 + formatteropts, 2154 + formatteropts,
2147 _(b'[-u] [NAME]...'), 2155 _(b'[-u] [NAME]...'),
2148 helpcategory=command.CATEGORY_HELP, 2156 helpcategory=command.CATEGORY_HELP,
2177 2185
2178 :name: String. Config name. 2186 :name: String. Config name.
2179 :source: String. Filename and line number where the item is defined. 2187 :source: String. Filename and line number where the item is defined.
2180 :value: String. Config value. 2188 :value: String. Config value.
2181 2189
2190 The --shared flag can be used to edit the config file of shared source
2191 repository. It only works when you have shared using the experimental
2192 share safe feature.
2193
2182 Returns 0 on success, 1 if NAME does not exist. 2194 Returns 0 on success, 1 if NAME does not exist.
2183 2195
2184 """ 2196 """
2185 2197
2186 opts = pycompat.byteskwargs(opts) 2198 opts = pycompat.byteskwargs(opts)
2187 editopts = (b'edit', b'local', b'global') 2199 editopts = (b'edit', b'local', b'global', b'shared')
2188 if any(opts.get(o) for o in editopts): 2200 if any(opts.get(o) for o in editopts):
2189 if opts.get(b'local') and opts.get(b'global'): 2201 cmdutil.check_at_most_one_arg(opts, *editopts[1:])
2190 raise error.Abort(_(b"can't use --local and --global together"))
2191
2192 if opts.get(b'local'): 2202 if opts.get(b'local'):
2193 if not repo: 2203 if not repo:
2194 raise error.Abort(_(b"can't use --local outside a repository")) 2204 raise error.Abort(_(b"can't use --local outside a repository"))
2195 paths = [repo.vfs.join(b'hgrc')] 2205 paths = [repo.vfs.join(b'hgrc')]
2196 elif opts.get(b'global'): 2206 elif opts.get(b'global'):
2197 paths = rcutil.systemrcpath() 2207 paths = rcutil.systemrcpath()
2208 elif opts.get(b'shared'):
2209 if not repo.shared():
2210 raise error.Abort(
2211 _(b"repository is not shared; can't use --shared")
2212 )
2213 if requirements.SHARESAFE_REQUIREMENT not in repo.requirements:
2214 raise error.Abort(
2215 _(
2216 b"share safe feature not unabled; "
2217 b"unable to edit shared source repository config"
2218 )
2219 )
2220 paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')]
2198 else: 2221 else:
2199 paths = rcutil.userrcpath() 2222 paths = rcutil.userrcpath()
2200 2223
2201 for f in paths: 2224 for f in paths:
2202 if os.path.exists(f): 2225 if os.path.exists(f):