Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 50829:7d54b877782e
config: migrate `opts` to native kwargs
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 20 Aug 2023 01:08:58 -0400 |
parents | afddb0d5be4f |
children | de3191c0cec9 |
comparison
equal
deleted
inserted
replaced
50828:afddb0d5be4f | 50829:7d54b877782e |
---|---|
2311 | 2311 |
2312 Returns 0 on success, 1 if NAME does not exist. | 2312 Returns 0 on success, 1 if NAME does not exist. |
2313 | 2313 |
2314 """ | 2314 """ |
2315 | 2315 |
2316 opts = pycompat.byteskwargs(opts) | 2316 editopts = ('edit', 'local', 'global', 'shared', 'non_shared') |
2317 editopts = (b'edit', b'local', b'global', b'shared', b'non_shared') | |
2318 if any(opts.get(o) for o in editopts): | 2317 if any(opts.get(o) for o in editopts): |
2319 cmdutil.check_at_most_one_arg(opts, *editopts[1:]) | 2318 cmdutil.check_at_most_one_arg(opts, *editopts[1:]) |
2320 if opts.get(b'local'): | 2319 if opts.get('local'): |
2321 if not repo: | 2320 if not repo: |
2322 raise error.InputError( | 2321 raise error.InputError( |
2323 _(b"can't use --local outside a repository") | 2322 _(b"can't use --local outside a repository") |
2324 ) | 2323 ) |
2325 paths = [repo.vfs.join(b'hgrc')] | 2324 paths = [repo.vfs.join(b'hgrc')] |
2326 elif opts.get(b'global'): | 2325 elif opts.get('global'): |
2327 paths = rcutil.systemrcpath() | 2326 paths = rcutil.systemrcpath() |
2328 elif opts.get(b'shared'): | 2327 elif opts.get('shared'): |
2329 if not repo.shared(): | 2328 if not repo.shared(): |
2330 raise error.InputError( | 2329 raise error.InputError( |
2331 _(b"repository is not shared; can't use --shared") | 2330 _(b"repository is not shared; can't use --shared") |
2332 ) | 2331 ) |
2333 if requirements.SHARESAFE_REQUIREMENT not in repo.requirements: | 2332 if requirements.SHARESAFE_REQUIREMENT not in repo.requirements: |
2336 b"share safe feature not enabled; " | 2335 b"share safe feature not enabled; " |
2337 b"unable to edit shared source repository config" | 2336 b"unable to edit shared source repository config" |
2338 ) | 2337 ) |
2339 ) | 2338 ) |
2340 paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')] | 2339 paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')] |
2341 elif opts.get(b'non_shared'): | 2340 elif opts.get('non_shared'): |
2342 paths = [repo.vfs.join(b'hgrc-not-shared')] | 2341 paths = [repo.vfs.join(b'hgrc-not-shared')] |
2343 else: | 2342 else: |
2344 paths = rcutil.userrcpath() | 2343 paths = rcutil.userrcpath() |
2345 | 2344 |
2346 for f in paths: | 2345 for f in paths: |
2347 if os.path.exists(f): | 2346 if os.path.exists(f): |
2348 break | 2347 break |
2349 else: | 2348 else: |
2350 if opts.get(b'global'): | 2349 if opts.get('global'): |
2351 samplehgrc = uimod.samplehgrcs[b'global'] | 2350 samplehgrc = uimod.samplehgrcs[b'global'] |
2352 elif opts.get(b'local'): | 2351 elif opts.get('local'): |
2353 samplehgrc = uimod.samplehgrcs[b'local'] | 2352 samplehgrc = uimod.samplehgrcs[b'local'] |
2354 else: | 2353 else: |
2355 samplehgrc = uimod.samplehgrcs[b'user'] | 2354 samplehgrc = uimod.samplehgrcs[b'user'] |
2356 | 2355 |
2357 f = paths[0] | 2356 f = paths[0] |
2366 errprefix=_(b"edit failed"), | 2365 errprefix=_(b"edit failed"), |
2367 blockedtag=b'config_edit', | 2366 blockedtag=b'config_edit', |
2368 ) | 2367 ) |
2369 return | 2368 return |
2370 ui.pager(b'config') | 2369 ui.pager(b'config') |
2371 fm = ui.formatter(b'config', opts) | 2370 fm = ui.formatter(b'config', pycompat.byteskwargs(opts)) |
2372 for t, f in rcutil.rccomponents(): | 2371 for t, f in rcutil.rccomponents(): |
2373 if t == b'path': | 2372 if t == b'path': |
2374 ui.debug(b'read config from: %s\n' % f) | 2373 ui.debug(b'read config from: %s\n' % f) |
2375 elif t == b'resource': | 2374 elif t == b'resource': |
2376 ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1])) | 2375 ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1])) |
2377 elif t == b'items': | 2376 elif t == b'items': |
2378 # Don't print anything for 'items'. | 2377 # Don't print anything for 'items'. |
2379 pass | 2378 pass |
2380 else: | 2379 else: |
2381 raise error.ProgrammingError(b'unknown rctype: %s' % t) | 2380 raise error.ProgrammingError(b'unknown rctype: %s' % t) |
2382 untrusted = bool(opts.get(b'untrusted')) | 2381 untrusted = bool(opts.get('untrusted')) |
2383 | 2382 |
2384 selsections = selentries = [] | 2383 selsections = selentries = [] |
2385 if values: | 2384 if values: |
2386 selsections = [v for v in values if b'.' not in v] | 2385 selsections = [v for v in values if b'.' not in v] |
2387 selentries = [v for v in values if b'.' in v] | 2386 selentries = [v for v in values if b'.' in v] |
2388 uniquesel = len(selentries) == 1 and not selsections | 2387 uniquesel = len(selentries) == 1 and not selsections |
2389 selsections = set(selsections) | 2388 selsections = set(selsections) |
2390 selentries = set(selentries) | 2389 selentries = set(selentries) |
2391 | 2390 |
2392 matched = False | 2391 matched = False |
2393 all_known = opts[b'exp_all_known'] | 2392 all_known = opts['exp_all_known'] |
2394 show_source = ui.debugflag or opts.get(b'source') | 2393 show_source = ui.debugflag or opts.get('source') |
2395 entries = ui.walkconfig(untrusted=untrusted, all_known=all_known) | 2394 entries = ui.walkconfig(untrusted=untrusted, all_known=all_known) |
2396 for section, name, value in entries: | 2395 for section, name, value in entries: |
2397 source = ui.configsource(section, name, untrusted) | 2396 source = ui.configsource(section, name, untrusted) |
2398 value = pycompat.bytestr(value) | 2397 value = pycompat.bytestr(value) |
2399 defaultvalue = ui.configdefault(section, name) | 2398 defaultvalue = ui.configdefault(section, name) |