##// END OF EJS Templates
pathcopies: give up any optimization based on `introrev`...
pathcopies: give up any optimization based on `introrev` Between 8a0136f69027 and d98fb3f42f33, we sped up the search for the introduction revision during path copies. However, further checking show that finding the introduction revision is still expensive and that we are better off without it. So we simply drop it and only rely on the linkrev optimisation. I ran `perfpathcopies` on 6989 pair of revision in the pypy repository (`hg perfhelper-pathcopies`. The result is massively in favor of dropping this condition. The result of the copy tracing are unchanged. Attempt to use a smaller changes preserving linkrev usage were unsuccessful, it can return wrong result. The following changesets broke test-mv-cp-st-diff.t - if not f.isintroducedafter(limit): + if limit >= 0 and f.linkrev() < limit: return None Here are various numbers (before this changeset/after this changesets) source destination before after saved-time ratio worth cases e66f24650daf 695dfb0f493b 1.062843 1.246369 -0.183526 1.172675 c979853a3b6a 8d60fe293e79 1.036985 1.196414 -0.159429 1.153743 22349fa2fc33 fbb1c9fd86c0 0.879926 1.038682 -0.158756 1.180420 682b98f3e672 a4878080a536 0.909952 1.063801 -0.153849 1.169074 5adabc9b9848 920958a93997 0.993622 1.147452 -0.153830 1.154817 worse 1% dbfbfcf077e9 aea8f2fd3593 1.016595 1.082999 -0.066404 1.065320 worse 5% c95f1ced15f2 7d29d5e39734 0.453694 0.471156 -0.017462 1.038488 worse 10% 3e144ed1d5b7 2aef0e942480 0.035140 0.037535 -0.002395 1.068156 worse 25% 321fc60db035 801748ba582a 0.009267 0.009325 -0.000058 1.006259 median 2088ce763fc2 e6991321d78b 0.000665 0.000651 0.000014 0.978947 best 25% 915631a97de6 385b31354be6 0.040743 0.040363 0.000380 0.990673 best 10% ad495c36a765 19c10384d3e7 0.431658 0.411490 0.020168 0.953278 best 5% d13ae7d283ae 813c99f810ac 1.141404 1.075346 0.066058 0.942126 best 1% 81593cb4a496 99ae11866969 1.833297 0.063823 1.769474 0.034813 best cases c3b14617fbd7 743a0fcaa4eb 1101.811740 2.735970 1099.075770 0.002483 c3b14617fbd7 9ba6ab77fd29 1116.753953 2.800729 1113.953224 0.002508 058b99d6e81f 57e249b7a3ea 1246.128485 3.042762 1243.085723 0.002442 9a8c361aab49 0354a250d371 1253.111894 3.085796 1250.026098 0.002463 442dbbc53c68 3ec1002a818c 1261.786294 3.138607 1258.647687 0.002487 As one can see, the average case is not really impacted. However, the worth case we get after this changeset are much better than the one we had before it. We have 30 pairs where improvements are above 10 minutes. This reflect in the combined time for all pairs before: 26256s after: 1300s (-95%) If we remove these pathological 30 cases, we still see a significant improvements: before: 1631s after: 1245s (-24%)

File last commit:

r43387:8ff1ecfa default
r43469:c16fe77e default
Show More
win32mbcs.py
221 lines | 7.0 KiB | text/x-python | PythonLexer
# win32mbcs.py -- MBCS filename support for Mercurial
#
# Copyright (c) 2008 Shun-ichi Goto <shunichi.goto@gmail.com>
#
# Version: 0.3
# Author: Shun-ichi Goto <shunichi.goto@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
'''allow the use of MBCS paths with problematic encodings
Some MBCS encodings are not good for some path operations (i.e.
splitting path, case conversion, etc.) with its encoded bytes. We call
such a encoding (i.e. shift_jis and big5) as "problematic encoding".
This extension can be used to fix the issue with those encodings by
wrapping some functions to convert to Unicode string before path
operation.
This extension is useful for:
- Japanese Windows users using shift_jis encoding.
- Chinese Windows users using big5 encoding.
- All users who use a repository with one of problematic encodings on
case-insensitive file system.
This extension is not needed for:
- Any user who use only ASCII chars in path.
- Any user who do not use any of problematic encodings.
Note that there are some limitations on using this extension:
- You should use single encoding in one repository.
- If the repository path ends with 0x5c, .hg/hgrc cannot be read.
- win32mbcs is not compatible with fixutf8 extension.
By default, win32mbcs uses encoding.encoding decided by Mercurial.
You can specify the encoding by config option::
[win32mbcs]
encoding = sjis
It is useful for the users who want to commit with UTF-8 log message.
'''
from __future__ import absolute_import
import os
import sys
from mercurial.i18n import _
from mercurial.pycompat import getattr, setattr
from mercurial import (
encoding,
error,
pycompat,
registrar,
)
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
testedwith = b'ships-with-hg-core'
configtable = {}
configitem = registrar.configitem(configtable)
# Encoding.encoding may be updated by --encoding option.
# Use a lambda do delay the resolution.
configitem(
b'win32mbcs', b'encoding', default=lambda: encoding.encoding,
)
_encoding = None # see extsetup
def decode(arg):
if isinstance(arg, str):
uarg = arg.decode(_encoding)
if arg == uarg.encode(_encoding):
return uarg
raise UnicodeError(b"Not local encoding")
elif isinstance(arg, tuple):
return tuple(map(decode, arg))
elif isinstance(arg, list):
return map(decode, arg)
elif isinstance(arg, dict):
for k, v in arg.items():
arg[k] = decode(v)
return arg
def encode(arg):
if isinstance(arg, pycompat.unicode):
return arg.encode(_encoding)
elif isinstance(arg, tuple):
return tuple(map(encode, arg))
elif isinstance(arg, list):
return map(encode, arg)
elif isinstance(arg, dict):
for k, v in arg.items():
arg[k] = encode(v)
return arg
def appendsep(s):
# ensure the path ends with os.sep, appending it if necessary.
try:
us = decode(s)
except UnicodeError:
us = s
if us and us[-1] not in b':/\\':
s += pycompat.ossep
return s
def basewrapper(func, argtype, enc, dec, args, kwds):
# check check already converted, then call original
for arg in args:
if isinstance(arg, argtype):
return func(*args, **kwds)
try:
# convert string arguments, call func, then convert back the
# return value.
return enc(func(*dec(args), **dec(kwds)))
except UnicodeError:
raise error.Abort(
_(b"[win32mbcs] filename conversion failed with %s encoding\n")
% _encoding
)
def wrapper(func, args, kwds):
return basewrapper(func, pycompat.unicode, encode, decode, args, kwds)
def reversewrapper(func, args, kwds):
return basewrapper(func, str, decode, encode, args, kwds)
def wrapperforlistdir(func, args, kwds):
# Ensure 'path' argument ends with os.sep to avoids
# misinterpreting last 0x5c of MBCS 2nd byte as path separator.
if args:
args = list(args)
args[0] = appendsep(args[0])
if b'path' in kwds:
kwds[b'path'] = appendsep(kwds[b'path'])
return func(*args, **kwds)
def wrapname(name, wrapper):
module, name = name.rsplit(b'.', 1)
module = sys.modules[module]
func = getattr(module, name)
def f(*args, **kwds):
return wrapper(func, args, kwds)
f.__name__ = func.__name__
setattr(module, name, f)
# List of functions to be wrapped.
# NOTE: os.path.dirname() and os.path.basename() are safe because
# they use result of os.path.split()
funcs = b'''os.path.join os.path.split os.path.splitext
os.path.normpath os.makedirs mercurial.util.endswithsep
mercurial.util.splitpath mercurial.util.fscasesensitive
mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath
mercurial.util.checkwinfilename mercurial.util.checkosfilename
mercurial.util.split'''
# These functions are required to be called with local encoded string
# because they expects argument is local encoded string and cause
# problem with unicode string.
rfuncs = b'''mercurial.encoding.upper mercurial.encoding.lower
mercurial.util._filenamebytestr'''
# List of Windows specific functions to be wrapped.
winfuncs = b'''os.path.splitunc'''
# codec and alias names of sjis and big5 to be faked.
problematic_encodings = b'''big5 big5-tw csbig5 big5hkscs big5-hkscs
hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis
sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004
shift_jisx0213 shiftjisx0213 sjisx0213 s_jisx0213 950 cp950 ms950 '''
def extsetup(ui):
# TODO: decide use of config section for this extension
if (not os.path.supports_unicode_filenames) and (
pycompat.sysplatform != b'cygwin'
):
ui.warn(_(b"[win32mbcs] cannot activate on this platform.\n"))
return
# determine encoding for filename
global _encoding
_encoding = ui.config(b'win32mbcs', b'encoding')
# fake is only for relevant environment.
if _encoding.lower() in problematic_encodings.split():
for f in funcs.split():
wrapname(f, wrapper)
if pycompat.iswindows:
for f in winfuncs.split():
wrapname(f, wrapper)
wrapname(b"mercurial.util.listdir", wrapperforlistdir)
wrapname(b"mercurial.windows.listdir", wrapperforlistdir)
# wrap functions to be called with local byte string arguments
for f in rfuncs.split():
wrapname(f, reversewrapper)
# Check sys.args manually instead of using ui.debug() because
# command line options is not yet applied when
# extensions.loadall() is called.
if b'--debug' in sys.argv:
ui.writenoi18n(
b"[win32mbcs] activated with encoding: %s\n" % _encoding
)