Mercurial > hg
changeset 15397:f32f71f6c20c stable
merge with i18n
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 01 Nov 2011 12:49:06 -0500 |
parents | 87bb6b7644f6 (diff) afa8e62bebb8 (current diff) |
children | 474279be5add |
files | |
diffstat | 8 files changed, 81 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-code.py Mon Oct 31 11:27:16 2011 -0200 +++ b/contrib/check-code.py Tue Nov 01 12:49:06 2011 -0500 @@ -52,6 +52,7 @@ (r'^diff.*-\w*N', "don't use 'diff -N'"), (r'(^| )wc[^|]*$\n(?!.*\(re\))', "filter wc output"), (r'head -c', "don't use 'head -c', use 'dd'"), + (r'sha1sum', "don't use sha1sum, use $TESTDIR/md5sum.py"), (r'ls.*-\w*R', "don't use 'ls -R', use 'find'"), (r'printf.*\\\d\d\d', "don't use 'printf \NNN', use Python"), (r'printf.*\\x', "don't use printf \\x, use Python"),
--- a/hgext/largefiles/lfutil.py Mon Oct 31 11:27:16 2011 -0200 +++ b/hgext/largefiles/lfutil.py Tue Nov 01 12:49:06 2011 -0500 @@ -13,6 +13,7 @@ import platform import shutil import stat +import tempfile from mercurial import dirstate, httpconnection, match as match_, util, scmutil from mercurial.i18n import _ @@ -438,6 +439,13 @@ return ('largefiles' in repo.requirements and util.any(shortname + '/' in f[0] for f in repo.store.datafiles())) +def mkstemp(repo, prefix): + '''Returns a file descriptor and a filename corresponding to a temporary + file in the repo's largefiles store.''' + path = repo.join(longname) + util.makedirs(path) + return tempfile.mkstemp(prefix=prefix, dir=path) + class storeprotonotcapable(Exception): def __init__(self, storetypes): self.storetypes = storetypes
--- a/hgext/largefiles/proto.py Mon Oct 31 11:27:16 2011 -0200 +++ b/hgext/largefiles/proto.py Tue Nov 01 12:49:06 2011 -0500 @@ -4,7 +4,6 @@ # GNU General Public License version 2 or any later version. import os -import tempfile import urllib2 from mercurial import error, httprepo, util, wireproto @@ -19,23 +18,25 @@ def putlfile(repo, proto, sha): '''Put a largefile into a repository's local store and into the user cache.''' - f = None proto.redirect() + + fd, tmpname = lfutil.mkstemp(repo, prefix='hg-putlfile') + tmpfp = os.fdopen(fd, 'wb+') try: try: - f = tempfile.NamedTemporaryFile(mode='wb+', prefix='hg-putlfile-') - proto.getfile(f) - f.seek(0) - if sha != lfutil.hexsha1(f): + proto.getfile(tmpfp) + tmpfp.seek(0) + if sha != lfutil.hexsha1(tmpfp): return wireproto.pushres(1) - lfutil.copytostoreabsolute(repo, f.name, sha) - except IOError: - repo.ui.warn( - _('error: could not put received data into largefile store')) + tmpfp.close() + lfutil.copytostoreabsolute(repo, tmpname, sha) + except IOError, e: + repo.ui.warn(_('largefiles: failed to put %s (%s) into store: %s') % + (sha, tmpname, e.strerror)) return wireproto.pushres(1) finally: - if f: - f.close() + tmpfp.close() + os.unlink(tmpname) return wireproto.pushres(0)
--- a/mercurial/minirst.py Mon Oct 31 11:27:16 2011 -0200 +++ b/mercurial/minirst.py Tue Nov 01 12:49:06 2011 -0500 @@ -23,9 +23,27 @@ from i18n import _ def replace(text, substs): + ''' + Apply a list of (find, replace) pairs to a text. + + >>> replace("foo bar", [('f', 'F'), ('b', 'B')]) + 'Foo Bar' + >>> encoding.encoding = 'latin1' + >>> replace('\\x81\\\\', [('\\\\', '/')]) + '\\x81/' + >>> encoding.encoding = 'shiftjis' + >>> replace('\\x81\\\\', [('\\\\', '/')]) + '\\x81\\\\' + ''' + + # some character encodings (cp932 for Japanese, at least) use + # ASCII characters other than control/alphabet/digit as a part of + # multi-bytes characters, so direct replacing with such characters + # on strings in local encoding causes invalid byte sequences. + utext = text.decode(encoding.encoding) for f, t in substs: - text = text.replace(f, t) - return text + utext = utext.replace(f, t) + return utext.encode(encoding.encoding) _blockre = re.compile(r"\n(?:\s*\n)+")
--- a/mercurial/util.py Mon Oct 31 11:27:16 2011 -0200 +++ b/mercurial/util.py Tue Nov 01 12:49:06 2011 -0500 @@ -73,14 +73,24 @@ # Python compatibility -def sha1(s): +def sha1(s=''): + ''' + Low-overhead wrapper around Python's SHA support + + >>> f = _fastsha1 + >>> a = sha1() + >>> a = f() + >>> a.hexdigest() + 'da39a3ee5e6b4b0d3255bfef95601890afd80709' + ''' + return _fastsha1(s) _notset = object() def safehasattr(thing, attr): return getattr(thing, attr, _notset) is not _notset -def _fastsha1(s): +def _fastsha1(s=''): # This function will import sha1 from hashlib or sha (whichever is # available) and overwrite itself with it on the first call. # Subsequent calls will go directly to the imported function.
--- a/setup.py Mon Oct 31 11:27:16 2011 -0200 +++ b/setup.py Tue Nov 01 12:49:06 2011 -0500 @@ -133,21 +133,22 @@ version = '' -env = {'HGRCPATH': '', 'LANGUAGE': 'C'} +# Execute hg out of this directory with a custom environment which +# includes the pure Python modules in mercurial/pure. We also take +# care to not use any hgrc files and do no localization. +pypath = ['mercurial', os.path.join('mercurial', 'pure')] +env = {'PYTHONPATH': os.pathsep.join(pypath), + 'HGRCPATH': '', + 'LANGUAGE': 'C'} +if 'LD_LIBRARY_PATH' in os.environ: + env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH'] +if 'SystemRoot' in os.environ: + # Copy SystemRoot into the custom environment for Python 2.6 + # under Windows. Otherwise, the subprocess will fail with + # error 0xc0150004. See: http://bugs.python.org/issue3440 + env['SystemRoot'] = os.environ['SystemRoot'] if os.path.isdir('.hg'): - # Execute hg out of this directory with a custom environment which - # includes the pure Python modules in mercurial/pure. We also take - # care to not use any hgrc files and do no localization. - pypath = ['mercurial', os.path.join('mercurial', 'pure')] - env['PYTHONPATH'] = os.pathsep.join(pypath) - if 'LD_LIBRARY_PATH' in os.environ: - env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH'] - if 'SystemRoot' in os.environ: - # Copy SystemRoot into the custom environment for Python 2.6 - # under Windows. Otherwise, the subprocess will fail with - # error 0xc0150004. See: http://bugs.python.org/issue3440 - env['SystemRoot'] = os.environ['SystemRoot'] cmd = [sys.executable, 'hg', 'id', '-i', '-t'] l = runhg(cmd, env).split() while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
--- a/tests/test-doctest.py Mon Oct 31 11:27:16 2011 -0200 +++ b/tests/test-doctest.py Tue Nov 01 12:49:06 2011 -0500 @@ -4,6 +4,9 @@ del os.environ['TERM'] import doctest +import mercurial.util +doctest.testmod(mercurial.util) + import mercurial.changelog doctest.testmod(mercurial.changelog) @@ -22,9 +25,6 @@ import mercurial.url doctest.testmod(mercurial.url) -import mercurial.util -doctest.testmod(mercurial.util) - import mercurial.encoding doctest.testmod(mercurial.encoding) @@ -36,3 +36,6 @@ import mercurial.revset doctest.testmod(mercurial.revset) + +import mercurial.minirst +doctest.testmod(mercurial.minirst)
--- a/tests/test-lfconvert.t Mon Oct 31 11:27:16 2011 -0200 +++ b/tests/test-lfconvert.t Tue Nov 01 12:49:06 2011 -0500 @@ -48,9 +48,9 @@ normal $ cat sub/normal2 alsonormal - $ sha1sum large sub/maybelarge.dat - 2e000fa7e85759c7f4c254d4d9c33ef481e459a7 large - 34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c sub/maybelarge.dat + $ "$TESTDIR/md5sum.py" large sub/maybelarge.dat + ec87a838931d4d5d2e94a04644788a55 large + 1276481102f218c981e0324180bafd9f sub/maybelarge.dat "lfconvert" adds 'largefiles' to .hg/requires. $ cat .hg/requires @@ -74,8 +74,8 @@ $ echo blah >> normal3 $ echo blah >> sub/normal2 $ echo blah >> sub/maybelarge.dat - $ sha1sum sub/maybelarge.dat - 76236b6a2c6102826c61af4297dd738fb3b1de38 sub/maybelarge.dat + $ "$TESTDIR/md5sum.py" sub/maybelarge.dat + 1dd0b99ff80e19cff409702a1d3f5e15 sub/maybelarge.dat $ hg commit -A -m"add normal3, modify sub/*" adding normal3 created new head @@ -151,8 +151,8 @@ $ cat stuff/normal2 alsonormal blah - $ sha1sum stuff/maybelarge.dat - 76236b6a2c6102826c61af4297dd738fb3b1de38 stuff/maybelarge.dat + $ "$TESTDIR/md5sum.py" stuff/maybelarge.dat + 1dd0b99ff80e19cff409702a1d3f5e15 stuff/maybelarge.dat $ cat .hglf/stuff/maybelarge.dat 76236b6a2c6102826c61af4297dd738fb3b1de38 $ cd ..