# HG changeset patch # User Jun Wu <qu...@fb.com> # Date 1489449998 25200 # Mon Mar 13 17:06:38 2017 -0700 # Node ID fa1618118c0603dafd8b7afbeab0e95f3e4307b0 # Parent 102f291807c92864a2231e5e925d6cd64783bb59 # Available At https://bitbucket.org/quark-zju/hg-draft # hg pull https://bitbucket.org/quark-zju/hg-draft -r fa1618118c06 scmutil: add a method to convert environment variables to config items
We will put this "config generated by environment variables" thing in a desired layer - ex. above system configs, below user configs. The method was designed to be reusable if we want more complex layers - like multiple environment-generated configs; or test environment configs using a different environ dict. diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -405,4 +405,18 @@ def osrcpath(): return path +def envconfig(envlist, env=None): + '''[(section, name, value, source)] extracted from environment variables + + envlist is a list of (envname, section, configname) + ''' + if env is None: + env = encoding.environ + result = [] + for envname, section, configname in envlist: + if envname not in env: + continue + result.append((section, configname, env[envname], '$%s' % envname)) + return result + _rcpath = None _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel