changeset 52744:25b344f2aeef

dispatch: add support for the `--config-file` global option Previously, loading a one-off config file for a command could be tricky- only the system level `*.rc` file processing supported scanning a directory of files (and the current user may not have the permission to modify those directories). Setting `HGRCPATH=...` worked, but also disabled the normal processing of all system level and user level config files, and there was no way to add the normal path processing into `HGRCPATH`. Therefore, there was no easy way to append a config file to the normally processed config. Some programs have taken to rewriting config into the repo level hgrc, and removing it when they're done. This makes that hack unnecessary. Some config options (like `[auth]`) shouldn't be passed on the command line for security reasons, so the existing `--config` isn't sufficient. The config items here are handled very similarly to `--config` items, namely any item supercedes the same item in the system, user, and repo the configs. The files are processed in the order they were specified, and any `--config` item will override an item in one of these files, regardless of the order they were specified on the command line. I don't like having to disable `ui.detailed-exit-code` in `test-config.t` to appease chg, but since the (bad?) behavior also occurs with `--config`, whatever is going on was existing behavior and not a problem with this change in particular. I don't see an obvious reason for this behavior difference, and don't want to hold this up for something that nobody seems to have complained about. Also note that when there are certain parsing errors (e.g. `hg --confi "foo.bar=baz"` in `test-globalopts.t` tripped this), the code still plows through where `_parse_config_files()` is called in `dispatch.py`, but `cmdargs` isn't initialized. I'd expect a failure like that to bail out earlier, but just avoid the problem by using `pycompat.sysargv`.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 29 Jan 2025 16:09:06 -0500
parents 1ccbca64610a
children 8780d5707812
files mercurial/chgserver.py mercurial/commands.py mercurial/dispatch.py tests/test-commandserver.t tests/test-completion.t tests/test-config.t tests/test-extension.t tests/test-gendoc-ro.t tests/test-globalopts.t tests/test-help.t
diffstat 10 files changed, 403 insertions(+), 182 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/chgserver.py	Wed Jan 29 16:04:39 2025 -0500
+++ b/mercurial/chgserver.py	Wed Jan 29 16:09:06 2025 -0500
@@ -268,6 +268,7 @@
 
     # command line args
     options = dispatch._earlyparseopts(newui, args)
+    dispatch._parse_config_files(newui, args, options[b'config_file'])
     dispatch._parseconfig(newui, options[b'config'])
 
     # stolen from tortoisehg.util.copydynamicconfig()
--- a/mercurial/commands.py	Wed Jan 29 16:04:39 2025 -0500
+++ b/mercurial/commands.py	Wed Jan 29 16:09:06 2025 -0500
@@ -120,6 +120,13 @@
         _(b'set/override config option (use \'section.name=value\')'),
         _(b'CONFIG'),
     ),
+    (
+        b'',
+        b'config-file',
+        [],
+        _(b'load config file to set/override config options'),
+        _(b'HGRC'),
+    ),
     (b'', b'debug', None, _(b'enable debugging output')),
     (b'', b'debugger', None, _(b'start debugger')),
     (
--- a/mercurial/dispatch.py	Wed Jan 29 16:04:39 2025 -0500
+++ b/mercurial/dispatch.py	Wed Jan 29 16:09:06 2025 -0500
@@ -17,6 +17,9 @@
 import sys
 import traceback
 
+from typing import (
+    Iterable,
+)
 
 from .i18n import _
 
@@ -26,6 +29,7 @@
     cmdutil,
     color,
     commands,
+    config as configmod,
     demandimport,
     encoding,
     error,
@@ -387,13 +391,22 @@
                 debugtrace = {b'pdb': pdb.set_trace}
                 debugmortem = {b'pdb': pdb.post_mortem}
 
-                # read --config before doing anything else
-                # (e.g. to change trust settings for reading .hg/hgrc)
+                # read --config-file and --config before doing anything else
+                # (e.g. to change trust settings for reading .hg/hgrc).
+
+                # cmdargs may not have been initialized here (in the case of an
+                # error), so use pycompat.sysargv instead.
+                file_cfgs = _parse_config_files(
+                    req.ui, pycompat.sysargv, req.earlyoptions[b'config_file']
+                )
                 cfgs = _parseconfig(req.ui, req.earlyoptions[b'config'])
 
                 if req.repo:
                     # copy configs that were passed on the cmdline (--config) to
                     # the repo ui
+                    for sec, name, val, source in file_cfgs:
+                        req.repo.ui.setconfig(sec, name, val, source=source)
+
                     for sec, name, val in cfgs:
                         req.repo.ui.setconfig(
                             sec, name, val, source=b'--config'
@@ -875,6 +888,48 @@
     return configs
 
 
+def _parse_config_files(
+    ui, cmdargs: list[bytes], config_files: Iterable[bytes]
+) -> list[tuple[bytes, bytes, bytes, bytes]]:
+    """parse the --config-file options from the command line
+
+    A list of tuples containing (section, name, value, source) is returned,
+    in the order they were read.
+    """
+
+    configs: list[tuple[bytes, bytes, bytes, bytes]] = []
+
+    cfg = configmod.config()
+
+    for file in config_files:
+        try:
+            cfg.read(file)
+        except error.ConfigError as e:
+            raise error.InputError(
+                _(b'invalid --config-file content at %s') % e.location,
+                hint=e.message,
+            )
+        except FileNotFoundError:
+            hint = None
+            if b'--cwd' in cmdargs:
+                hint = _(b"this file is resolved before --cwd is processed")
+
+            raise error.InputError(
+                _(b'missing file "%s" for --config-file') % file, hint=hint
+            )
+
+    for section in cfg.sections():
+        for item in cfg.items(section):
+            name = item[0]
+            value = item[1]
+            src = cfg.source(section, name)
+
+            ui.setconfig(section, name, value, src)
+            configs.append((section, name, value, src))
+
+    return configs
+
+
 def _earlyparseopts(ui, args):
     options = {}
     fancyopts.fancyopts(
@@ -892,7 +947,13 @@
     """Split args into a list of possible early options and remainder args"""
     shortoptions = b'R:'
     # TODO: perhaps 'debugger' should be included
-    longoptions = [b'cwd=', b'repository=', b'repo=', b'config=']
+    longoptions = [
+        b'cwd=',
+        b'repository=',
+        b'repo=',
+        b'config=',
+        b'config-file=',
+    ]
     return fancyopts.earlygetopt(
         args, shortoptions, longoptions, gnu=True, keepsep=True
     )
@@ -1097,6 +1158,10 @@
 
         if options[b"config"] != req.earlyoptions[b"config"]:
             raise error.InputError(_(b"option --config may not be abbreviated"))
+        if options[b"config_file"] != req.earlyoptions[b"config_file"]:
+            raise error.InputError(
+                _(b"option --config-file may not be abbreviated")
+            )
         if options[b"cwd"] != req.earlyoptions[b"cwd"]:
             raise error.InputError(_(b"option --cwd may not be abbreviated"))
         if options[b"repository"] != req.earlyoptions[b"repository"]:
--- a/tests/test-commandserver.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-commandserver.t	Wed Jan 29 16:09:06 2025 -0500
@@ -1173,3 +1173,47 @@
   $ cd ..
 
 #endif
+
+Test the --config-file behavior (this will be used by SCM Manager to add auth
+and proxy info instead of rewriting the repo hgrc file during pulls and
+imports).
+
+  $ cat > config-file.rc <<EOF
+  > [auth]
+  > temporary.schemes = https
+  > temporary.prefix = server.org
+  > temporary.password = password
+  > temporary.username = user
+  > EOF
+
+  >>> from hgclient import check, readchannel, runcommand
+  >>> @check
+  ... def checkruncommand(server):
+  ...     # hello block
+  ...     readchannel(server)
+  ... 
+  ...     # no file
+  ...     runcommand(server, [b'config', b'auth'])
+  ...     # with file
+  ...     runcommand(server,
+  ...                [b'config', b'auth', b'--config-file', b'config-file.rc'])
+  ...     # with file and overriding --config
+  ...     runcommand(server,
+  ...                [b'config', b'auth', b'--config-file', b'config-file.rc',
+  ...                 b'--config', b'auth.temporary.username=cli-user'])
+  ...     # previous configs aren't cached
+  ...     runcommand(server, [b'config', b'auth'])
+  *** runcommand config auth
+   [1]
+  *** runcommand config auth --config-file config-file.rc
+  auth.temporary.schemes=https
+  auth.temporary.prefix=server.org
+  auth.temporary.password=password
+  auth.temporary.username=user
+  *** runcommand config auth --config-file config-file.rc --config auth.temporary.username=cli-user
+  auth.temporary.schemes=https
+  auth.temporary.prefix=server.org
+  auth.temporary.password=password
+  auth.temporary.username=cli-user
+  *** runcommand config auth
+   [1]
--- a/tests/test-completion.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-completion.t	Wed Jan 29 16:09:06 2025 -0500
@@ -176,6 +176,7 @@
   $ hg debugcomplete --options | sort
   --color
   --config
+  --config-file
   --cwd
   --debug
   --debugger
@@ -206,6 +207,7 @@
   --cmdserver
   --color
   --config
+  --config-file
   --cwd
   --daemon
   --daemon-postexec
--- a/tests/test-config.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-config.t	Wed Jan 29 16:09:06 2025 -0500
@@ -456,6 +456,20 @@
   > logtemplate = "value-B\n"
   > EOF
 
+  $ cat > config-file.rc <<EOF
+  > [config-test]
+  > basic = value-CONFIG-FILE
+  > [ui]
+  > logtemplate = "value-CONFIG-FILE\n"
+  > EOF
+
+  $ cat > config-file2.rc <<EOF
+  > [config-test]
+  > basic = value-CONFIG-FILE-2
+  > [ui]
+  > logtemplate = "value-CONFIG-FILE-2\n"
+  > EOF
+
 
   $ cat > included.rc << EOF
   > [config-test]
@@ -510,6 +524,25 @@
   $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic --config config-test.basic=value-CLI
   value-CLI
 
+  $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic --config-file config-file.rc
+  value-CONFIG-FILE
+
+--config-file args are processed in order of appearance
+
+  $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic \
+  >    --config-file config-file.rc --config-file config-file2.rc
+  value-CONFIG-FILE-2
+
+--config overrides --config-file, regardless of order
+
+  $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic \
+  >    --config config-test.basic=value-CLI --config-file config-file.rc
+  value-CLI
+
+  $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic \
+  >    --config-file config-file.rc --config config-test.basic=value-CLI
+  value-CLI
+
 Alias ordering
 --------------
 
@@ -544,3 +577,46 @@
 
   $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r . --config ui.logtemplate="value-CLI\n"
   value-CLI
+
+
+  $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r . --config-file config-file.rc
+  value-CONFIG-FILE
+
+--config overrides --config-file
+
+  $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r . \
+  >     --config ui.logtemplate="value-CLI\n" --config-file config-file.rc
+  value-CLI
+
+
+Bad --config-file usage
+-----------------------
+
+For some reason, chg doesn't honor the detailed-exit-code=True setting, and
+exits with 255 for these cases that would normally exit with 10 for InputError.
+The exit code alone can't be conditionalized in the test here, and this failure
+to honor the setting is also true when passing a malformed --config, so disable
+the config for now.
+
+  $ cat >> $HGRCPATH <<EOF
+  > [ui]
+  > detailed-exit-code = False
+  > EOF
+
+  $ cat > not-a-config-file.txt <<EOF
+  >   this is a bad config file line
+  > EOF
+
+  $ hg config auth --config-file not-a-config-file.txt
+  abort: invalid --config-file content at not-a-config-file.txt:1
+  (unexpected leading whitespace:   this is a bad config file line)
+  [255]
+
+  $ hg config auth --config-file non-existent-file.rc
+  abort: missing file "non-existent-file.rc" for --config-file
+  [255]
+
+  $ hg config auth --config-file non-existent-file.rc --cwd ..
+  abort: missing file "non-existent-file.rc" for --config-file
+  (this file is resolved before --cwd is processed)
+  [255]
--- a/tests/test-extension.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-extension.t	Wed Jan 29 16:09:06 2025 -0500
@@ -682,28 +682,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
 
 
@@ -721,28 +723,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
 
 
@@ -1034,28 +1038,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
 Make sure that single '-v' option shows help and built-ins only for 'dodo' command
   $ hg help -v dodo
@@ -1071,28 +1077,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
 In case when extension name doesn't match any of its commands,
 help message should ask for '-v' to get list of built-in aliases
@@ -1146,28 +1154,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
   $ hg help -v -e dudu
   dudu extension -
@@ -1182,28 +1192,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
 Disabled extension commands:
 
--- a/tests/test-gendoc-ro.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-gendoc-ro.t	Wed Jan 29 16:09:06 2025 -0500
@@ -5,5 +5,5 @@
 until the localization is corrected.
   $ $TESTDIR/check-gendoc ro
   checking for parse errors
-  gendoc.txt:58: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string.
-  gendoc.txt:58: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string.
+  gendoc.txt:61: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string.
+  gendoc.txt:61: (WARNING/2) Inline interpreted text or phrase reference start-string without end-string.
--- a/tests/test-globalopts.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-globalopts.t	Wed Jan 29 16:09:06 2025 -0500
@@ -138,7 +138,11 @@
 earlygetopt with illegal abbreviations:
 
   $ hg --confi "foo.bar=baz"
-  abort: option --config may not be abbreviated
+  hg: option --confi not a unique prefix
+  (use 'hg help -v' for a list of global options)
+  [10]
+  $ hg --config-f "foo"
+  abort: option --config-file may not be abbreviated
   [10]
   $ hg --cw a tip
   abort: option --cwd may not be abbreviated
--- a/tests/test-help.t	Wed Jan 29 16:04:39 2025 -0500
+++ b/tests/test-help.t	Wed Jan 29 16:09:06 2025 -0500
@@ -437,28 +437,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
   
   (use 'hg help' for the full list of commands)
 
@@ -537,28 +539,30 @@
   
   global options ([+] can be repeated):
   
-   -R --repository REPO   repository root directory or name of overlay bundle
-                          file
-      --cwd DIR           change working directory
-   -y --noninteractive    do not prompt, automatically pick the first choice for
-                          all prompts
-   -q --quiet             suppress output
-   -v --verbose           enable additional output
-      --color TYPE        when to colorize (boolean, always, auto, never, or
-                          debug)
-      --config CONFIG [+] set/override config option (use 'section.name=value')
-      --debug             enable debugging output
-      --debugger          start debugger
-      --encoding ENCODE   set the charset encoding (default: ascii)
-      --encodingmode MODE set the charset encoding mode (default: strict)
-      --traceback         always print a traceback on exception
-      --time              time how long the command takes
-      --profile           print command execution profile
-      --version           output version information and exit
-   -h --help              display help and exit
-      --hidden            consider hidden changesets
-      --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
+   -R --repository REPO      repository root directory or name of overlay bundle
+                             file
+      --cwd DIR              change working directory
+   -y --noninteractive       do not prompt, automatically pick the first choice
+                             for all prompts
+   -q --quiet                suppress output
+   -v --verbose              enable additional output
+      --color TYPE           when to colorize (boolean, always, auto, never, or
+                             debug)
+      --config CONFIG [+]    set/override config option (use
+                             'section.name=value')
+      --config-file HGRC [+] load config file to set/override config options
+      --debug                enable debugging output
+      --debugger             start debugger
+      --encoding ENCODE      set the charset encoding (default: ascii)
+      --encodingmode MODE    set the charset encoding mode (default: strict)
+      --traceback            always print a traceback on exception
+      --time                 time how long the command takes
+      --profile              print command execution profile
+      --version              output version information and exit
+   -h --help                 display help and exit
+      --hidden               consider hidden changesets
+      --pager TYPE           when to paginate (boolean, always, auto, or never)
+                             (default: auto)
 
 Test the textwidth config option
 
@@ -3108,6 +3112,9 @@
   <td>--config CONFIG [+]</td>
   <td>set/override config option (use 'section.name=value')</td></tr>
   <tr><td></td>
+  <td>--config-file HGRC [+]</td>
+  <td>load config file to set/override config options</td></tr>
+  <tr><td></td>
   <td>--debug</td>
   <td>enable debugging output</td></tr>
   <tr><td></td>
@@ -3312,6 +3319,9 @@
   <td>--config CONFIG [+]</td>
   <td>set/override config option (use 'section.name=value')</td></tr>
   <tr><td></td>
+  <td>--config-file HGRC [+]</td>
+  <td>load config file to set/override config options</td></tr>
+  <tr><td></td>
   <td>--debug</td>
   <td>enable debugging output</td></tr>
   <tr><td></td>