[PATCH 1 of 4] dirstate: move file type filtering to its source
Adrian Buehlmann
adrian at cadifra.com
Wed Dec 5 18:26:11 CST 2012
On 2012-11-30 23:20, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano at fb.com>
> # Date 1354313740 28800
> # Node ID 874a5aac379f0798c758797f24abf1f7be9f05d7
> # Parent 2f04000f7c355f505b788880ee7987ca63643cf2
> dirstate: move file type filtering to its source
>
> This prepares us to move to a much faster statfiles implementation on Unix.
>
> diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> --- a/mercurial/dirstate.py
> +++ b/mercurial/dirstate.py
> @@ -697,9 +697,6 @@
> if not skipstep3 and not exact:
> visit = sorted([f for f in dmap if f not in results and matchfn(f)])
> for nf, st in zip(visit, util.statfiles([join(i) for i in visit])):
> - if (not st is None and
> - getkind(st.st_mode) not in (regkind, lnkkind)):
> - st = None
> results[nf] = st
> for s in subrepos:
> del results[s]
> diff --git a/mercurial/posix.py b/mercurial/posix.py
> --- a/mercurial/posix.py
> +++ b/mercurial/posix.py
> @@ -352,12 +352,18 @@
> def setsignalhandler():
> pass
>
> +_wantedkinds = set([stat.S_IFREG, stat.S_IFLNK])
> +
> def statfiles(files):
> - 'Stat each file in files and yield stat or None if file does not exist.'
> + '''Stat each file in files. Yield each stat, or None if a file does not
> + exist or has a type we don't care about.'''
> lstat = os.lstat
> + getkind = stat.S_IFMT
> for nf in files:
> try:
> st = lstat(nf)
> + if getkind(st.st_mode) not in _wantedkinds:
> + st = None
> except OSError, err:
> if err.errno not in (errno.ENOENT, errno.ENOTDIR):
> raise
> diff --git a/mercurial/windows.py b/mercurial/windows.py
> --- a/mercurial/windows.py
> +++ b/mercurial/windows.py
> @@ -7,7 +7,7 @@
>
> from i18n import _
> import osutil, encoding
> -import errno, msvcrt, os, re, sys, _winreg
> +import errno, msvcrt, os, re, stat, sys, _winreg
>
> import win32
> executablepath = win32.executablepath
> @@ -213,10 +213,15 @@
> return executable
> return findexisting(os.path.expanduser(os.path.expandvars(command)))
>
> +_wantedkinds = set([stat.S_IFREG, stat.S_IFLNK])
> +
> def statfiles(files):
> - '''Stat each file in files and yield stat or None if file does not exist.
> + '''Stat each file in files. Yield each stat, or None if a file
> + does not exist or has a type we don't care about.
> +
> Cluster and cache stat per directory to minimize number of OS stat calls.'''
> dircache = {} # dirname -> filename -> status | None if file does not exist
> + getkind = stat.S_IFMT
> for nf in files:
> nf = normcase(nf)
> dir, base = os.path.split(nf)
> @@ -226,7 +231,8 @@
> if cache is None:
> try:
> dmap = dict([(normcase(n), s)
> - for n, k, s in osutil.listdir(dir, True)])
> + for n, k, s in osutil.listdir(dir, True)
> + if getkind(s) in _wantedkinds])
> except OSError, err:
> # handle directory not found in Python version prior to 2.5
> # Python <= 2.4 returns native Windows code 3 in errno
+ ** unknown exception encountered, please report by visiting
+ ** http://mercurial.selenic.com/wiki/BugTracker
+ ** Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
+ ** Mercurial Distributed SCM (version 2.4.1+4-)
+ ** Extensions loaded:
+ Traceback (most recent call last):
+ File "c:/Users/buildbot/w2k8/Windows_2008_R2_hg_tests/build/hg", line 38, in <module>
+ mercurial.dispatch.run()
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 28, in run
+ sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 65, in dispatch
+ return _runcatch(req)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 88, in _runcatch
+ return _dispatch(req)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 741, in _dispatch
+ cmdpats, cmdoptions)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 514, in runcommand
+ ret = _runcommand(ui, options, cmd, d)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 831, in _runcommand
+ return checkargs()
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 802, in checkargs
+ return cmdfunc()
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dispatch.py", line 738, in <lambda>
+ d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\util.py", line 475, in check
+ return func(*args, **kwargs)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\commands.py", line 1344, in commit
+ node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\cmdutil.py", line 1616, in commit
+ scmutil.match(repo[None], pats, opts), opts)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\commands.py", line 1342, in commitfunc
+ match, editor=e, extra=extra)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\localrepo.py", line 57, in wrapper
+ return orig(repo.unfiltered(), *args, **kwargs)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\localrepo.py", line 1299, in commit
+ changes = self.status(match=match, clean=force)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\localrepo.py", line 1617, in status
+ listclean, listunknown)
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dirstate.py", line 757, in status
+ listignored).iteritems():
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\dirstate.py", line 706, in walk
+ for st in util.statfiles([join(i) for i in visit]):
+ File "c:\Users\buildbot\w2k8\Windows_2008_R2_hg_tests\build\mercurial\windows.py", line 235, in statfiles
+ if getkind(s) in _wantedkinds])
+ File "C:\Users\buildbot\w2k8\hackablehg\hg-2.1\hg-python26\lib\stat.py", line 25, in S_IFMT
+ return mode & 0170000
+ TypeError: unsupported operand type(s) for &: 'osutil.stat' and 'int'
+ [1]
More information about the Mercurial-devel
mailing list