Re: [PATCH 07 of 13 V3] scmutil: extract rc.d listing function from rccomponents
> On Mar 22, 2017, at 12:23, Jun Wu wrote: > > # HG changeset patch > # User Jun Wu > # 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] Nit: this `else:` line is unnecessary -- remove it and unindent the `return [p]`. Also: it looks to me like you could reuse this in defaultrcpath() as well? pacem in terris / мир / शान्ति / سَلاَم / 平和 Kevin R. Bullock ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 07 of 13 V3] scmutil: extract rc.d listing function from rccomponents
Excerpts from Martin von Zweigbergk's message of 2017-03-22 22:32:53 -0700: > On Wed, Mar 22, 2017 at 10:23 AM, Jun Wu wrote: > > # HG changeset patch > > # User Jun Wu > > # 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. > > Is that last part still true? It looks like pathize() is called on all > paths even in the preimage, and I believe pathize() calls normpath(). > I'm thinking that maybe the commit message is outdated. Good catch. Sorry, I didn't realize the code change changes the behavior. > > > > 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()) > > ___ > > Mercurial-devel mailing list > > Mercurial-devel@mercurial-scm.org > > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 07 of 13 V3] scmutil: extract rc.d listing function from rccomponents
On Wed, Mar 22, 2017 at 10:23 AM, Jun Wu wrote: > # HG changeset patch > # User Jun Wu > # 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. Is that last part still true? It looks like pathize() is called on all paths even in the preimage, and I believe pathize() calls normpath(). I'm thinking that maybe the commit message is outdated. > > 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()) > ___ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
[PATCH 07 of 13 V3] scmutil: extract rc.d listing function from rccomponents
# HG changeset patch # User Jun Wu # 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()) ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel