Patchwork D7691: windows: factor the hgrc directory scan into a function

login
register
mail settings
Submitter phabricator
Date Dec. 18, 2019, 3:49 a.m.
Message ID <differential-rev-PHID-DREV-76zwq762b7pacwai2fu4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43947/
State Superseded
Headers show

Comments

phabricator - Dec. 18, 2019, 3:49 a.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7691

AFFECTED FILES
  mercurial/scmwindows.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/scmwindows.py b/mercurial/scmwindows.py
--- a/mercurial/scmwindows.py
+++ b/mercurial/scmwindows.py
@@ -28,12 +28,16 @@ 
     # Use mercurial.ini found in directory with hg.exe
     progrc = os.path.join(os.path.dirname(filename), b'mercurial.ini')
     rcpath.append(progrc)
+
+    def _processdir(progrcd):
+        if os.path.isdir(progrcd):
+            for f, kind in util.listdir(progrcd):
+                if f.endswith(b'.rc'):
+                    rcpath.append(os.path.join(progrcd, f))
+
     # Use hgrc.d found in directory with hg.exe
-    progrcd = os.path.join(os.path.dirname(filename), b'hgrc.d')
-    if os.path.isdir(progrcd):
-        for f, kind in util.listdir(progrcd):
-            if f.endswith(b'.rc'):
-                rcpath.append(os.path.join(progrcd, f))
+    _processdir(os.path.join(os.path.dirname(filename), b'hgrc.d'))
+
     # next look for a system rcpath in the registry
     value = util.lookupreg(
         b'SOFTWARE\\Mercurial', None, winreg.HKEY_LOCAL_MACHINE
@@ -43,10 +47,8 @@ 
         for p in value.split(pycompat.ospathsep):
             if p.lower().endswith(b'mercurial.ini'):
                 rcpath.append(p)
-            elif os.path.isdir(p):
-                for f, kind in util.listdir(p):
-                    if f.endswith(b'.rc'):
-                        rcpath.append(os.path.join(p, f))
+            else:
+                _processdir(p)
     return rcpath