mercurial/commands.py
changeset 52417 c97e0fd26225
parent 52416 0a81f3ef054c
child 52418 e98cea8fc858
equal deleted inserted replaced
52416:0a81f3ef054c 52417:c97e0fd26225
    51     obsutil,
    51     obsutil,
    52     patch,
    52     patch,
    53     phases,
    53     phases,
    54     pycompat,
    54     pycompat,
    55     registrar,
    55     registrar,
    56     requirements,
       
    57     revsetlang,
    56     revsetlang,
    58     rewriteutil,
    57     rewriteutil,
    59     scmutil,
    58     scmutil,
    60     server,
    59     server,
    61     shelve as shelvemod,
    60     shelve as shelvemod,
    62     state as statemod,
    61     state as statemod,
    63     tags as tagsmod,
    62     tags as tagsmod,
    64     ui as uimod,
       
    65     util,
    63     util,
    66     verify as verifymod,
    64     verify as verifymod,
    67     vfs as vfsmod,
       
    68     wireprotoserver,
    65     wireprotoserver,
    69 )
    66 )
    70 
    67 
    71 from .cmd_impls import graft as graft_impl
    68 from .cmd_impls import graft as graft_impl
    72 from .configuration import rcutil
    69 from .configuration import (
       
    70     command as config_command,
       
    71     rcutil,
       
    72 )
    73 from .utils import (
    73 from .utils import (
    74     dateutil,
    74     dateutil,
    75     procutil,
    75     procutil,
    76     stringutil,
    76     stringutil,
    77     urlutil,
    77     urlutil,
  2365       share safe feature.
  2365       share safe feature.
  2366 
  2366 
  2367     Returns 0 on success, 1 if NAME does not exist.
  2367     Returns 0 on success, 1 if NAME does not exist.
  2368 
  2368 
  2369     """
  2369     """
  2370 
  2370     edit_level = config_command.find_edit_level(ui, repo, opts)
  2371     editopts = ('edit', 'local', 'global', 'shared', 'non_shared')
  2371     if edit_level is not None:
  2372     if any(opts.get(o) for o in editopts):
  2372         return config_command.edit_config(ui, repo, edit_level)
  2373         cmdutil.check_at_most_one_arg(opts, *editopts[1:])
       
  2374         if opts.get('local'):
       
  2375             if not repo:
       
  2376                 raise error.InputError(
       
  2377                     _(b"can't use --local outside a repository")
       
  2378                 )
       
  2379             paths = [repo.vfs.join(b'hgrc')]
       
  2380         elif opts.get('global'):
       
  2381             paths = rcutil.systemrcpath()
       
  2382         elif opts.get('shared'):
       
  2383             if not repo.shared():
       
  2384                 raise error.InputError(
       
  2385                     _(b"repository is not shared; can't use --shared")
       
  2386                 )
       
  2387             if requirements.SHARESAFE_REQUIREMENT not in repo.requirements:
       
  2388                 raise error.InputError(
       
  2389                     _(
       
  2390                         b"share safe feature not enabled; "
       
  2391                         b"unable to edit shared source repository config"
       
  2392                     )
       
  2393                 )
       
  2394             paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')]
       
  2395         elif opts.get('non_shared'):
       
  2396             paths = [repo.vfs.join(b'hgrc-not-shared')]
       
  2397         else:
       
  2398             paths = rcutil.userrcpath()
       
  2399 
       
  2400         for f in paths:
       
  2401             if os.path.exists(f):
       
  2402                 break
       
  2403         else:
       
  2404             if opts.get('global'):
       
  2405                 samplehgrc = uimod.samplehgrcs[b'global']
       
  2406             elif opts.get('local'):
       
  2407                 samplehgrc = uimod.samplehgrcs[b'local']
       
  2408             else:
       
  2409                 samplehgrc = uimod.samplehgrcs[b'user']
       
  2410 
       
  2411             f = paths[0]
       
  2412             util.writefile(f, util.tonativeeol(samplehgrc))
       
  2413 
       
  2414         editor = ui.geteditor()
       
  2415         ui.system(
       
  2416             b"%s \"%s\"" % (editor, f),
       
  2417             onerr=error.InputError,
       
  2418             errprefix=_(b"edit failed"),
       
  2419             blockedtag=b'config_edit',
       
  2420         )
       
  2421         return
       
  2422     ui.pager(b'config')
  2373     ui.pager(b'config')
  2423     fm = ui.formatter(b'config', pycompat.byteskwargs(opts))
  2374     fm = ui.formatter(b'config', pycompat.byteskwargs(opts))
  2424     for t, f in rcutil.rccomponents():
  2375     for t, f in rcutil.rccomponents():
  2425         if t == b'path':
  2376         if t == b'path':
  2426             ui.debug(b'read config from: %s\n' % f)
  2377             ui.debug(b'read config from: %s\n' % f)