##// END OF EJS Templates
match: add `filepath:` pattern to match an exact filepath relative to the root...
match: add `filepath:` pattern to match an exact filepath relative to the root It's useful in certain automated workflows to make sure we recurse in directories whose name conflicts with files in other revisions. In addition it makes it possible to avoid building a potentially costly regex, improving performance when the set of files to match explicitly is large. The benchmark below are run in the following configuration : # data-env-vars.name = mozilla-central-2018-08-01-zstd-sparse-revlog # benchmark.name = files # benchmark.variants.rev = tip # benchmark.variants.files = all-list-filepath-sorted # bin-env-vars.hg.flavor = no-rust It also includes timings using the re2 engine (through the `google-re2` module) to show how much can be saved by just using a better regexp engine. Pattern time (seconds) time using re2 ----------------------------------------------------------- just "." 0.4 0.4 list of "filepath:…" 1.3 1.3 list of "path:…" 25.7 3.9 list of patterns 29.7 10.4 As you can see, Without re2, using "filepath:" instead of "path:" is a huge win. With re2, it is still about three times faster to not have to build the regex.

File last commit:

r50703:7a414342 default
r51588:1c31b343 default
Show More
scmposix.py
103 lines | 2.7 KiB | text/x-python | PythonLexer
Yuya Nishihara
scmutil: narrow ImportError handling in termwidth()...
r30311 import array
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 import errno
import fcntl
Gregory Szorc
scmposix: use absolute_import
r27483 import os
import sys
Matt Harbison
typing: add type hints to the platform specific scm modules...
r50703 from typing import (
List,
Tuple,
)
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from .pycompat import getattr
Gregory Szorc
scmposix: use absolute_import
r27483 from . import (
Pulkit Goyal
py3: make scmposix.userrcpath() return bytes...
r30276 encoding,
Pulkit Goyal
py3: use pycompat.sysargv in scmposix.systemrcpath()...
r30467 pycompat,
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 util,
Gregory Szorc
scmposix: use absolute_import
r27483 )
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690
Matt Harbison
typing: add type hints to the platform specific scm modules...
r50703 if pycompat.TYPE_CHECKING:
from . import ui as uimod
Yuya Nishihara
pager: use less as a fallback on Unix...
r32078 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by
# $MORE variable, but there's no compatible option with Linux 'more'. Given
# OS X is widely used and most modern Unix systems would have 'less', setting
# 'less' as the default seems reasonable.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fallbackpager = b'less'
Yuya Nishihara
pager: use less as a fallback on Unix...
r32078
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345
Matt Harbison
typing: add type hints to the platform specific scm modules...
r50703 def _rcfiles(path: bytes) -> List[bytes]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rcs = [os.path.join(path, b'hgrc')]
rcdir = os.path.join(path, b'hgrc.d')
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 try:
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 rcs.extend(
[
os.path.join(rcdir, f)
Martin von Zweigbergk
config: read system hgrc in lexicographical order...
r46428 for f, kind in sorted(util.listdir(rcdir))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if f.endswith(b".rc")
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 ]
)
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 except OSError:
pass
return rcs
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345
Matt Harbison
typing: add type hints to the platform specific scm modules...
r50703 def systemrcpath() -> List[bytes]:
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 path = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if pycompat.sysplatform == b'plan9':
root = b'lib/mercurial'
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 root = b'etc/mercurial'
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 # old mod_python does not set sys.argv
if len(getattr(sys, 'argv', [])) > 0:
Pulkit Goyal
py3: use pycompat.sysargv in scmposix.systemrcpath()...
r30467 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if p != b'/':
Mads Kiilerich
config: don't read the same config file twice...
r22583 path.extend(_rcfiles(os.path.join(p, root)))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 path.extend(_rcfiles(b'/' + root))
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 return path
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345
Matt Harbison
typing: add type hints to the platform specific scm modules...
r50703 def userrcpath() -> List[bytes]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if pycompat.sysplatform == b'plan9':
return [encoding.environ[b'home'] + b'/lib/hgrc']
Jun Wu
codemod: use pycompat.isdarwin...
r34648 elif pycompat.isdarwin:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return [os.path.expanduser(b'~/.hgrc')]
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 confighome = encoding.environ.get(b'XDG_CONFIG_HOME')
David Demelier
hg: allow usage of XDG_CONFIG_HOME/hg/hgrc...
r30941 if confighome is None or not os.path.isabs(confighome):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 confighome = os.path.expanduser(b'~/.config')
David Demelier
hg: allow usage of XDG_CONFIG_HOME/hg/hgrc...
r30941
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 return [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 os.path.expanduser(b'~/.hgrc'),
os.path.join(confighome, b'hg', b'hgrc'),
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 ]
Yuya Nishihara
scmutil: move util.termwidth()...
r30309
Matt Harbison
typing: add type hints to the platform specific scm modules...
r50703 def termsize(ui: "uimod.ui") -> Tuple[int, int]:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 try:
import termios
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345
Yuya Nishihara
scmutil: narrow ImportError handling in termwidth()...
r30311 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
except (AttributeError, ImportError):
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 return 80, 24
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312
for dev in (ui.ferr, ui.fout, ui.fin):
try:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 try:
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 fd = dev.fileno()
except AttributeError:
continue
if not os.isatty(fd):
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 arri = fcntl.ioctl(fd, TIOCGWINSZ, b'\0' * 8)
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 height, width = array.array('h', arri)[:2]
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 if width > 0 and height > 0:
return width, height
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 except ValueError:
pass
except IOError as e:
Matt Harbison
scmposix: don't subscript IOError...
r50699 if e.errno == errno.EINVAL:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 pass
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 else:
raise
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 return 80, 24