[PATCH 5 of 5] chgserver: make _renewui load repo and command line configs

Yuya Nishihara yuya at tcha.org
Thu Feb 25 09:48:02 EST 2016


On Wed, 24 Feb 2016 22:30:16 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1456352811 0
> #      Wed Feb 24 22:26:51 2016 +0000
> # Node ID d8bb763c7fe0628ce293de5f914947b5e9e3dfc3
> # Parent  a987a1eaf022e94dc62eba75e05c6e04b1e03714
> chgserver: make _renewui load repo and command line configs
> 
> Before this patch, there is no way to load repo config in chgserver. This
> patch revised _renewui to let it load repo config and take command line
> flags passed into consideration.
> 
> The _renewui logic is not ideal at present because it's very tricky to know
> what should copy and what should not from the old ui object to the new one.
> This is partially because the current ui and config object design is not
> ideal. In the future, we may want to avoid all ui or config copies.
> 
> diff --git a/hgext/chgserver.py b/hgext/chgserver.py
> --- a/hgext/chgserver.py
> +++ b/hgext/chgserver.py
> @@ -232,17 +232,42 @@
>  
>      return chgui(srcui)
>  
> -def _renewui(srcui):
> +def _renewui(srcui, args=None):
> +    if not args:
> +        args = []
> +
>      newui = srcui.__class__()
>      for a in ['fin', 'fout', 'ferr', 'environ']:
>          setattr(newui, a, getattr(srcui, a))
>      if util.safehasattr(srcui, '_csystem'):
>          newui._csystem = srcui._csystem
> +
> +    # load repo or local config, copied from dispatch.py
> +    cwd = dispatch._earlygetopt(['--cwd'], args)
> +    oldwd = os.getcwd()
> +    if cwd:
> +        os.chdir(cwd[-1])
> +    rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args)
> +    path, newui = dispatch._getlocal(newui, rpath)
> +
> +    # go back to old wd otherwise it will cause error if --cwd is relative
> +    # since chdir will be called again in runcommand -> dispatch
> +    if cwd:
> +        os.chdir(oldwd)

Can you clean up this a little more? It can at least avoid chdir().

> +    # internal config: extensions.chgserver
> +    # copy it. it can only be overrided from command line.
> +    newui.setconfig('extensions', 'chgserver',
> +                    srcui.config('extensions', 'chgserver'))

Nit: configsource is dropped here.


More information about the Mercurial-devel mailing list