Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/pathutil.py @ 44924:233ee525dcef
grep: reduce the cost of pathauditor checks when grepping working copy
Running `time hg grep zxczxczxczxczxc -l` on mozilla-central:
before:
real 0m20,000s
user 0m15,796s
sys 0m4,189s
after:
real 0m10,903s
user 0m8,964s
sys 0m1,916s
if vfs didn't call pathauditor at all:
real 0m7,781s
user 0m5,968s
sys 0m1,790s
Differential Revision: https://phab.mercurial-scm.org/D8582
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 25 May 2020 17:39:23 -0400 |
parents | 11f284c8c5e4 |
children | 89a2afe31e82 |
comparison
equal
deleted
inserted
replaced
44923:06105aa8bc0e | 44924:233ee525dcef |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import |
2 | 2 |
3 import contextlib | |
3 import errno | 4 import errno |
4 import os | 5 import os |
5 import posixpath | 6 import posixpath |
6 import stat | 7 import stat |
7 | 8 |
145 try: | 146 try: |
146 self(path) | 147 self(path) |
147 return True | 148 return True |
148 except (OSError, error.Abort): | 149 except (OSError, error.Abort): |
149 return False | 150 return False |
151 | |
152 @contextlib.contextmanager | |
153 def cached(self): | |
154 if self._cached: | |
155 yield | |
156 else: | |
157 try: | |
158 self._cached = True | |
159 yield | |
160 finally: | |
161 self.audited.clear() | |
162 self.auditeddir.clear() | |
163 self._cached = False | |
150 | 164 |
151 | 165 |
152 def canonpath(root, cwd, myname, auditor=None): | 166 def canonpath(root, cwd, myname, auditor=None): |
153 '''return the canonical path of myname, given cwd and root | 167 '''return the canonical path of myname, given cwd and root |
154 | 168 |