[PATCH 08 of 10] scmutil: use the new faster path split

Matt Mackall mpm at selenic.com
Fri Sep 14 14:57:17 CDT 2012


On Thu, 2012-09-13 at 21:27 -0400, Greg Ward wrote:
> On 13 September 2012, Bryan O'Sullivan said:
> > # HG changeset patch
> > # User Bryan O'Sullivan <bryano at fb.com>
> > # Date 1347562631 25200
> > # Node ID 168fa28b4620b30505e8284bcee5a0cf0d0b6338
> > # Parent  9d1ceb24dc23a965d6df2b14ebca30da59139710
> > scmutil: use the new faster path split
> > 
> > diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> > --- a/mercurial/scmutil.py
> > +++ b/mercurial/scmutil.py
> > @@ -267,7 +267,7 @@
> >              mode += "b" # for that other OS
> >  
> >          nlink = -1
> > -        dirname, basename = os.path.split(f)
> > +        dirname, basename = util.split(f)
> >          # If basename is empty, then the path is malformed because it points
> >          # to a directory. Let the posixfile() call below raise IOError.
> >          if basename and mode not in ('r', 'rb'):
> > @@ -383,7 +383,7 @@
> >                  name = os.path.join(*rel)
> >                  auditor(name)
> >                  return util.pconvert(name)
> > -            dirname, basename = os.path.split(name)
> > +            dirname, basename = util.split(name)
> >              rel.append(basename)
> >              if dirname == name:
> >                  break
> 
> $ hg locate '**.py' | xargs grep 'os\.path\.split'
> 
> finds lots of other call sites. There Should Be Only One Way To Do It.

Actually, there are valid reasons to use os.path.split in some places
and not in others in a cross-platform tool. Unfortunately, there's not a
cut-and-dried rule for where those places are in Mercurial (like there
is for Unicode strings, for instance).

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list