##// END OF EJS Templates
largefiles: optimize update speed by only updating changed largefiles...
largefiles: optimize update speed by only updating changed largefiles Historically, during 'hg update', every largefile in the working copy was hashed (which is a very expensive operation on big files) and any largefiles that did not have a hash that matched their standin were updated. This patch optimizes 'hg update' by keeping track of what standins have changed between the old and new revisions, and only updating the largefiles that have changed. This saves a lot of time by avoiding the unecessary calculation of a list of sha1 hashes for big files. With this patch, the time 'hg update' takes to complete is a function of how many largefiles need to be updated and what their size is. Performance tests on a repository with about 80 largefiles ranging from a few MB to about 97 MB are shown below. The tests show how long it takes to run 'hg update' with no changes actually being updated. Mercurial 2.1 release: $ time hg update 0 files updated, 0 files merged, 0 files removed, 0 files unresolved getting changed largefiles 0 largefiles updated, 0 removed real 0m10.045s user 0m9.367s sys 0m0.674s With this patch: $ time hg update 0 files updated, 0 files merged, 0 files removed, 0 files unresolved real 0m0.965s user 0m0.845s sys 0m0.115s The same repsoitory, without the largefiles extension enabled: $ time hg update 0 files updated, 0 files merged, 0 files removed, 0 files unresolved real 0m0.799s user 0m0.684s sys 0m0.111s So before the patch, 'hg update' with no changes was approximately 9.25s slower with largefiles enabled. With this patch, it is approximately 0.165s slower.

File last commit:

r15724:9e6a13c2 default
r16120:47ee41fc default
Show More
win32mbcs.py
167 lines | 5.6 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.
'''
import os, sys
from mercurial.i18n import _
from mercurial import util, 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("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, 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 ':/\\':
s += os.sep
return s
def wrapper(func, args, kwds):
# check argument is unicode, then call original
for arg in args:
if isinstance(arg, unicode):
return func(*args, **kwds)
try:
# convert arguments to unicode, call func, then convert back
return encode(func(*decode(args), **decode(kwds)))
except UnicodeError:
raise util.Abort(_("[win32mbcs] filename conversion failed with"
" %s encoding\n") % (_encoding))
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 'path' in kwds:
kwds['path'] = appendsep(kwds['path'])
return func(*args, **kwds)
def wrapname(name, wrapper):
module, name = name.rsplit('.', 1)
module = sys.modules[module]
func = getattr(module, name)
def f(*args, **kwds):
return wrapper(func, args, kwds)
try:
f.__name__ = func.__name__ # fail with python23
except Exception:
pass
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 = '''os.path.join os.path.split os.path.splitext
os.path.normpath os.makedirs
mercurial.util.endswithsep mercurial.util.splitpath mercurial.util.checkcase
mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath
mercurial.util.checkwinfilename mercurial.util.checkosfilename'''
# List of Windows specific functions to be wrapped.
winfuncs = '''os.path.splitunc'''
# codec and alias names of sjis and big5 to be faked.
problematic_encodings = '''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
(sys.platform != 'cygwin')):
ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
return
# determine encoding for filename
global _encoding
_encoding = ui.config('win32mbcs', 'encoding', encoding.encoding)
# fake is only for relevant environment.
if _encoding.lower() in problematic_encodings.split():
for f in funcs.split():
wrapname(f, wrapper)
if os.name == 'nt':
for f in winfuncs.split():
wrapname(f, wrapper)
wrapname("mercurial.osutil.listdir", wrapperforlistdir)
# Check sys.args manually instead of using ui.debug() because
# command line options is not yet applied when
# extensions.loadall() is called.
if '--debug' in sys.argv:
ui.write("[win32mbcs] activated with encoding: %s\n"
% _encoding)