[PATCH 07 of 13 V3] scmutil: extract rc.d listing function from rccomponents
Jun Wu
quark at fb.com
Wed Mar 22 13:23:39 EDT 2017
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1490201429 25200
# Wed Mar 22 09:50:29 2017 -0700
# Node ID d604e5baed4ac2f5470860bff89728c282d71e3a
# Parent 44c865487bfd2f081bfb322b1fb1b700d57f7adf
# Available At https://bitbucket.org/quark-zju/hg-draft
# hg pull https://bitbucket.org/quark-zju/hg-draft -r d604e5baed4a
scmutil: extract rc.d listing function from rccomponents
This is suggested by dsop and makes the code cleaner. A side effect is
"normpath" will be called on paths in $HGRCPATH, which seems to be more
correct.
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -452,4 +452,13 @@ def rcpath():
_rccomponents = None
+def _expandrcpath(path):
+ '''path could be a file or a directory. return a list of file paths'''
+ p = util.expandpath(path)
+ join = os.path.join
+ if os.path.isdir(p):
+ return [join(p, f) for f, k in osutil.listdir(p) if f.endswith('.rc')]
+ else:
+ return [p]
+
def rccomponents():
'''return an ordered [(type, obj)] about where to load configs.
@@ -478,11 +487,5 @@ def rccomponents():
if not p:
continue
- p = util.expandpath(p)
- if os.path.isdir(p):
- for f, kind in osutil.listdir(p):
- if f.endswith('.rc'):
- _rccomponents.append(pathize(os.path.join(p, f)))
- else:
- _rccomponents.append(pathize(p))
+ _rccomponents.extend(map(pathize, _expandrcpath(p)))
else:
_rccomponents = map(pathize, defaultrcpath() + systemrcpath())
More information about the Mercurial-devel
mailing list