Commit Graph

520 Commits

Author SHA1 Message Date
Steve Losh
b2ecd09159 util: add an interpolate() function to for replacing multiple values
util.interpolate can be used to replace multiple items in a string all at once
(and optionally apply a function to the replacement), without worrying about
recursing:

    >>> import util
    >>> s = '$foo, $spam'
    >>> util.interpolate(r'\$', { 'foo': 'bar', 'spam': 'eggs' }, s)
    'bar, eggs'
    >>> util.interpolate(r'\$', { 'foo': 'spam', 'spam': 'foo' }, s)
    'spam, foo'
    >>> util.interpolate(r'\$', { 'foo': 'spam', 'spam': 'foo' }, s, lambda s: s.upper())
    'SPAM, FOO'

The patch also changes filemerge.py to use this new function.
2010-08-18 18:18:26 -04:00
Sol Jerome
c9dfe23c62 util: avoid using hashlib on Python < 2.5 (issue2278)
The following patch allows the use of python2.4 with a standalone
hashlib rather than assuming that python2.5 is in use when hashlib is
imported successfully.
2010-08-17 17:38:19 -05:00
Matt Mackall
c0eb9c1315 Merge with stable 2010-08-06 12:59:13 -05:00
Matt Mackall
10293e99b9 chunkbuffer: use += rather than cStringIO to reduce memory footprint
This significantly refactors the read() loop to use a queue of chunks.
The queue is alternately filled to at least 256k and then emptied by
concatenating onto the output buffer.

For very large read sizes, += uses less memory because it can resize
the target string in place.
2010-08-06 12:18:33 -05:00
Benoit Boissinot
ccef97c636 chunkbuffer: split big strings directly in chunkbuffer 2010-07-25 13:10:57 +02:00
Benoit Boissinot
316c7a862b chunkbuffer: targetsize isn't used outside of read() 2010-07-24 17:23:08 +02:00
Benoit Boissinot
e344473c84 chunkbuffer: use list instead of cStringIO 2010-07-24 15:21:39 +02:00
Benoit Boissinot
8505039010 chunkbuffer: use for/else to detect end of iteration 2010-07-24 15:20:29 +02:00
Renato Cunha
43a9dd63ec util: use fakebuffer as buffer in py3k
There's no buffer type in py3k, util.py has a function, called
fakebuffer, that implements a similar API. This patch implements
fakebuffer as a memoryview wrapper in py3k.
2010-07-14 22:59:57 -03:00
Renato Cunha
937ac7ab4b util: improved the check for the existence of the 'buffer' builtin
2to3 is unable to translate '__builtin__' calls to 'builtins' when
hasattr is used (as in hasattr(__builtin__, buffer)). Translating the
check to the format

try:
    whatever
except NameError
    # define whatever
    __builtin__.whatever = whatever

is a correct way of checking for the name and has the benefit of being
translated by 2to3. This patch implements the same idea for the
aforementioned example.
2010-07-14 22:59:43 -03:00
Maxim Khitrov
1cf52a2e29 http: deliver hook output to client 2010-06-30 18:15:23 -05:00
FUJIWARA Katsunori
9cce255bec replace Python standard textwrap by MBCS sensitive one for i18n text
Mercurial has problem around text wrapping/filling in MBCS encoding
environment, because standard 'textwrap' module of Python can not
treat it correctly. It splits byte sequence for one character into two
lines.

According to unicode specification, "east asian width" classifies
characters into:

   W(ide), N(arrow), F(ull-width), H(alf-width), A(mbiguous)


W/N/F/H can be always recognized as 2/1/2/1 bytes in byte sequence,
but 'A' can not. Size of 'A' depends on language in which it is used.

Unicode specification says:

   If the context(= language) cannot be established reliably they
   should be treated as narrow characters by default

but many of class 'A' characters are full-width, at least, in Japanese
environment.

So, this patch treats class 'A' characters as full-width always for
safety wrapping.

This patch focuses only on MBCS safe-ness, not on writing/printing
rule strict wrapping for each languages

MBCS sensitive textwrap class is originally implemented
by ITO Nobuaki <daydream.trippers@gmail.com>.
2010-06-06 17:20:10 +09:00
Adrian Buehlmann
e782bd53a4 clone: print number of linked/copied files on --debug 2010-05-31 13:47:51 +02:00
Adrian Buehlmann
a5e4e78e6f util.copyfiles: don't try os_link() again if it failed before
If the os_link() call on the first file in the directory fails [1],
we switch mode to using shutil.copy() for all remaining files.

[1] happens for example on Windows for every file when cloning from a UNC
path without specifying --pull.
2010-05-28 17:28:34 +02:00
Yuya Nishihara
7c75e66e92 util: give appropriate default args to atomictempfile()
mode='w+b' is the default of python's TemporaryFile().
2010-05-21 19:54:40 +09:00
Patrick Mezard
d05da88022 Merge with crew-stable 2010-04-26 22:42:46 +02:00
Patrick Mezard
b7c02777e0 util: fix default termwidth() under Windows
sys.stdout.write('-'*80 + '\n')

or

  sys.stdout.write('-'*80 + '\r')

do not work on Windows as they do on unix. On a 80 columns Windows console, the
extra CR or LF are interpreted as if belonging to the next line, so the first
command displays 2 lines (only one on unix) and the second one leave the line
visible and move back to the following line. To avoid this, we sacrifice one
column under Windows.
2010-04-26 22:30:40 +02:00
Benoit Boissinot
18b2a0f2b6 merge with stable 2010-04-14 09:09:43 +02:00
Benoit Boissinot
1bad57968f checklink: use an explicit prefix for the temporary file 2010-04-14 08:48:26 +02:00
Benoit Boissinot
4e16e2221b merge with stable 2010-04-13 22:10:24 +02:00
Benoit Boissinot
293ba231eb checkexec: use an explicit prefix for the temporary file 2010-04-13 21:54:59 +02:00
Matt Mackall
c9d0f4131a Merge with stable 2010-03-30 13:09:25 -05:00
Ronny Pfannschmidt
45a62d091b util: fake the builtin buffer if it's missing (jython) 2010-03-23 11:36:19 +01:00
Augie Fackler
9105fced5e util.termwidth: check stderr first as it's least likely to be redirected 2010-03-15 14:53:34 -05:00
Steve Losh
0c8f350f3b util: use the built-in any() and all() methods if they are available 2010-02-16 09:31:35 -05:00
Steve Losh
6e5e6283eb util: add any() and all() functions for Python 2.4 compatibility
This patch adds these two very useful functions to the mercurial.util module,
because they are not present in Python 2.4.
2010-02-12 19:59:09 -05:00
Augie Fackler
59918314ce util: fix trailing whitespace found by check-code 2010-02-08 08:18:49 -06:00
Patrick Mezard
4b42e59a7a util: make spawndetached() handle subprocess early terminations
The file-based synchronization introduced by 670de588e29e hangs when the child
process fails before terminating the handshake, which the previous pipe-based
version handled correctly. To fix this, the parent polling loop was fixed to
detect premature terminations of the child process.
2010-02-06 16:50:00 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Matt Mackall
cd3ef170f7 Merge with stable 2010-01-19 22:45:09 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Patrick Mezard
052695b2e4 cmdutil: hide child window created by win32 spawndetached()
Hiding the child process window is not strictly necessary but it avoids opening
an empty shell window when running hg serve as well as a task in the task bar.
The window is hidden after the process is already started causing a single
flicker.
2010-01-10 18:13:34 +01:00
Patrick Mezard
48eee05938 Find right hg command for detached process
On Windows, Mercurial can be run from the python script of from a frozen
executable. In the first case, we have to call the python interpreter since the
script is not executable. Frozen executable can be called directly.

Fix 3/3 for issue421
2010-01-06 21:11:58 +01:00
Sune Foldager
0d1feca701 handle file URIs correctly, according to RFC 2396 (issue1153)
The new code aims to implement the RFC correctly for file URIs.
Previously they were handled incorrectly in several ways, which
could cause problem on Windows in particular.
2009-12-03 11:06:55 +01:00
Dirkjan Ochtman
c81462828e util: sort paths in walkrepos() (fixes test failures in test-hgwebdir) 2009-11-06 22:54:51 +01:00
Dirkjan Ochtman
12c5890a70 kill trailing whitespace 2009-11-05 10:44:36 +01:00
Nicolas Dumazet
3f248fed39 util: use sys.argv[0] if $HG is unset and 'hg' is not in PATH
This is necessary when the executable name is not 'hg'. For example,
if your system-wide mercurial is name 'hgs', sys.argv[0] is more
accurate than 'hg'.
2009-09-21 19:21:32 +02:00
Alexander Solovyov
32999e4659 make path expanding more consistent
This expands ~user and $FOO constructs in ui.ignore files, [defaults],
[paths], extension paths, and HGRCPATH files.
2009-10-19 22:19:28 +03:00
Matt Mackall
20668220a1 Merge with -stable 2009-10-08 00:59:46 -05:00
Matt Mackall
daf9754427 Merge with -crew-stable 2009-10-07 23:25:41 -05:00
Adrian Buehlmann
db3cee7306 util: move rename into posix.py and windows.py 2009-10-07 20:32:07 +02:00
Adrian Buehlmann
d2944ad3db util: state docstring of rename more precisely 2009-10-07 20:16:43 +02:00
Adrian Buehlmann
692aa6b826 util.rename: do not abort if os.unlink fails (issue1840) 2009-10-06 10:45:23 +02:00
Steve Borho
7ec5773565 Merge with crew-stable 2009-10-06 16:08:38 -05:00
Matt Mackall
721ca9098c Fix for issue1848 2009-10-03 15:57:48 -05:00
Mads Kiilerich
097282895a util.system: Use subprocess instead of os.system
subprocess allows the environment and working directory to be specified
directly, so the hacks for making temporary changes while forking is no longer
necessary.

This also fixes failures on solaris where the temporary changes can't be undone
because there is no unsetenv.
2009-09-20 22:19:18 +02:00
Matt Mackall
3e6199cea0 Merge with -stable 2009-09-30 21:42:51 -05:00
Martin Geisler
3e05f2c2a8 ui: guard against UnicodeDecodeErrors in ui.wrap 2009-09-29 01:08:18 +02:00
Martin Geisler
72cc7c5356 util: do not corrupt multi-byte characters in wrap 2009-09-27 01:44:46 +02:00
Martin Geisler
42c594dc7e Merge with crew-stable 2009-09-27 09:38:53 +02:00