Commit Graph

741 Commits

Author SHA1 Message Date
Adrian Buehlmann
a61eaad778 path_auditor: eliminate local function 'check' in __call__ 2011-04-11 10:06:57 +02:00
Adrian Buehlmann
a5b6c426a2 util: move checkosfilename call from path_auditor to opener
path_auditor is used for checking patterns too, but a pattern is not a valid
filename.

This patch fixes fb1792e89e34, which introduced the bug:

  $ hg log -l3 glob:**.py
  abort: filename contains '*', which is reserved on Windows: mercurial\**.py
2011-04-10 19:31:49 +02:00
Adrian Buehlmann
9b801e586d path_auditor: check filenames for basic platform validity (issue2755)
Example (on Windows):

  $ hg parents
  $ hg manifest tip
  con.xml
  $ hg update
  abort: filename contains 'con', which is reserved on Windows: con.xml

Before this patch, update produced (as explained in issue2755):

  $ hg update
  abort: No usable temporary filename found

I've added the new function checkwinfilename to util.py and not to windows.py,
so that we can later call it when running on posix platforms too, for when we
decide to implement a (configurable) warning message on 'hg add'.

As per this patch, checkwinfilename is currently only used when running
on Windwows.

path_auditor calls checkosfilename, which is a NOP on posix and an alias for
checkwinfilename on Windows.
2011-04-06 18:09:43 +02:00
Matt Mackall
ddc767098f audit: improve nested repo message 2011-04-07 14:43:19 -05:00
Adrian Buehlmann
34d2bab4e0 util: move checklink() to posix.py and return False on Windows
Python added support for Windows 6.0 (Vista) symbolic links in 3.2 [1], but
even these symbolic links aren't what we can expect from a canonical
symbolic link, since creation requires SeCreateSymbolicLinkPrivilege,
which typically only admins have.

So we can safely assume that we don't have symbolic links on Windows.

[1] http://docs.python.org/py3k/library/os.html#os.symlink
2011-04-05 11:55:52 +02:00
Yun Lee
234710b7b8 util: make 'hg log -d --2' abort (issue2734) 2011-04-05 16:55:47 +08:00
Martin Geisler
a5339415db help/dates: use DATE as place-holder in help and abort texts
The use of "{datetime}" was unfortunate since I as a user never knew
if I was expected to do

  hg log -d '>{2011-04-01}'

or

  hg log -d '>2011-04-01'

The word "datetime" is also confusing -- calling it a date it much
simpler.
2011-04-05 10:01:39 +02:00
Adrian Buehlmann
b82d6c0417 util: move checkexec() to posix.py and return False on Windows 2011-04-04 11:41:54 +02:00
Matt Mackall
9da968682d date: fixup breakage from ">" fix 2011-04-04 09:39:22 -05:00
Yun Lee
8e6828ba03 log: abort for -d '>' or -d '<' (issue2749) 2011-04-04 00:23:21 +08:00
Brodie Rao
3a43fa887e url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
This replaces util.drop_scheme() with url.localpath(), using url.url for
parsing instead of doing it on its own. The function is moved from
util to url to avoid an import cycle.

hg.localpath() is removed in favor of using url.localpath(). This
provides more consistent behavior between "hg clone" and other
commands.

To preserve backwards compatibility, URLs like bundle://../foo still
refer to ../foo, not /foo.

If a URL contains a scheme, percent-encoded entities are decoded. When
there's no scheme, all characters are left untouched.

Comparison of old and new behaviors:

URL                      drop_scheme()   hg.localpath()    url.localpath()
===                      =============   ==============    ===============
file://foo/foo           /foo            foo/foo           /foo
file://localhost:80/foo  /foo            localhost:80/foo  /foo
file://localhost:/foo    /foo            localhost:/foo    /foo
file://localhost/foo     /foo            /foo              /foo
file:///foo              /foo            /foo              /foo
file://foo               (empty string)  foo               /
file:/foo                /foo            /foo              /foo
file:foo                 foo             foo               foo
file:foo%23bar           foo%23bar       foo%23bar         foo#bar
foo%23bar                foo%23bar       foo%23bar         foo%23bar
/foo                     /foo            /foo              /foo

Windows-related paths on Windows:

URL                      drop_scheme()   hg.localpath()    url.localpath()
===                      =============   ==============    ===============
file:///C:/foo           C:/C:/foo       /C:/foo           C:/foo
file:///D:/foo           C:/D:/foo       /D:/foo           D:/foo
file://C:/foo            C:/foo          C:/foo            C:/foo
file://D:/foo            C:/foo          D:/foo            D:/foo
file:////foo/bar         //foo/bar       //foo/bar         //foo/bar
//foo/bar                //foo/bar       //foo/bar         //foo/bar
\\foo\bar                //foo/bar       //foo/bar         \\foo\bar

Windows-related paths on other platforms:

file:///C:/foo           C:/C:/foo       /C:/foo           C:/foo
file:///D:/foo           C:/D:/foo       /D:/foo           D:/foo
file://C:/foo            C:/foo          C:/foo            C:/foo
file://D:/foo            C:/foo          D:/foo            D:/foo
file:////foo/bar         //foo/bar       //foo/bar         //foo/bar
//foo/bar                //foo/bar       //foo/bar         //foo/bar
\\foo\bar                //foo/bar       //foo/bar         \\foo\bar

For more information about file:// URL handling, see:
http://www-archive.mozilla.org/quality/networking/testing/filetests.html

Related issues:

- issue1153: File URIs aren't handled correctly in windows

  This patch should preserve the fix implemented in
  5c92d05b064e. However, it goes a step further and "promotes"
  Windows-style drive letters from being interpreted as host names to
  being part of the path.

- issue2154: Cannot escape '#' in Mercurial URLs (#1172 in THG)

  The fragment is still interpreted as a revision or a branch, even in
  paths to bundles. However, when file: is used, percent-encoded
  entities are decoded, so file:test%23bundle.hg can refer to
  test#bundle.hg ond isk.
2011-03-30 20:03:05 -07:00
Adrian Buehlmann
92624f7391 set NOT_CONTENT_INDEXED on .hg dir (issue2694)
when running on Windows
2011-03-28 15:54:22 +02:00
Idan Kamara
2f140a443a util: dates cannot consist entirely of whitespace (issue2732) 2011-03-27 23:48:58 +02:00
Dan Villiom Podlaski Christiansen
9dfabab3ba util: add Mac-specific check whether we're in a GUI session (issue2553)
The previous test assumed that 'os.name' was "mac" on Mac OS X. This
is not the case; 'mac' was classic Mac OS, whereas Mac OS X has 'os.name'
be 'posix'.

Please note that this change will break Mercurial on hypothetical
non-Mac OS X deployments of Darwin.

Credit to Brodie Rao for thinking of CGSessionCopyCurrentDictionary()
and Kevin Bullock for testing.
2011-03-23 09:43:34 +01:00
Mads Kiilerich
e4660104cf util: flush stdout before calling external processes
stdout could have content in its buffer while a subprocess ran and emitted
output.

Flushing stdout ensures that output now comes in the right order.
2011-02-18 03:35:01 +01:00
Dan Villiom Podlaski Christiansen
ec590d5cd4 explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
2010-12-24 15:23:01 +01:00
Roman Sokolov
7a0b42e376 dispatch: support for $ escaping in shell-alias definition
Sigils in shell-alias can be escaped by doubling them.
2011-02-11 03:32:40 +03:00
Adrian Buehlmann
77ab03f101 port win32.py to using the Python ctypes library
The pywin32 package is no longer needed.

ctypes is now required for running Mercurial on Windows.

ctypes is included in Python since version 2.5. For Python 2.4, ctypes is
available as an extra installer package for Windows.

Moved spawndetached() from windows.py to win32.py and fixed it, using
ctypes as well. spawndetached was defunct with Python 2.6.6 because Python
removed their undocumented subprocess.CreateProcess. This fixes
'hg serve -d' on Windows.
2011-02-14 11:12:26 +01:00
Adrian Buehlmann
573f584562 opener: use posixfile to hold file open when calling nlinks()
Mercurial's posixfile is less intrusive on Windows than Python's open
2011-02-02 13:51:22 +01:00
Matt Mackall
fa4133e7aa util: delay loading of textwrap 2011-01-28 17:02:29 -06:00
Matt Mackall
38d53c9ddd merge with stable 2011-01-27 17:22:37 -06:00
Adrian Buehlmann
f645c6e6fb opener: force copy on 'a'ppend if nlinks() returns 0 (issue1922)
If pywin32 is not installed, 'os.lstat(pathname).st_nlink' is used for
nlinks(), which is always zero for all files on Windows.

To make sure we break up hardlinks if pywin32 is missing, we force
nlink = 2 if nlinks() returns < 1.

(this completely fixes issue1922)
2011-01-26 19:14:30 +01:00
Adrian Buehlmann
6fa6b746ad opener: use util.unlink (issue2524) 2011-01-11 14:10:16 +01:00
Adrian Buehlmann
236663ff4c opener: check exception for ENOENT 2011-01-11 14:10:16 +01:00
Adrian Buehlmann
721e368ac1 rename util.unlink to unlinkpath 2011-01-02 19:34:41 +01:00
Matt Mackall
49ec3df937 merge with stable 2011-01-01 18:42:04 -06:00
Yuya Nishihara
7e36de64c5 util: fix ellipsis() not to break multi-byte sequence (issue2564)
It tries to convert localstr to unicode before truncating.
Because we cannot assume that the given text is encoded in local encoding,
it falls back to raw string in case of unicode error.
2010-12-25 21:59:00 +09:00
Matt Mackall
6b199f1d8d date: fix matching of underspecified date ranges
(backport of 7bca0f2718ab to stable)
2010-12-29 14:19:31 -06:00
Matt Mackall
8946a77df1 date: fix matching of underspecified date ranges
In a date like 10:30, there are two underspecified ends: the specific
end (seconds) and the broad end (day, month, year). When matching
"10:30", we need to allow the specific end to go from 0 to 59 seconds,
while the broad end is assumed to be today's date.

Similar handling applies for a date range like "Mar 1": year is fixed
to today, any time matches.
2010-12-29 14:04:47 -06:00
Matt Mackall
ceea1a202f merge with stable 2010-12-28 13:31:30 -06:00
Adrian Buehlmann
942d5fa3d6 checknlink: use two testfiles (issue2543)
Preventing file loss repository corruption (e.g. vanished changelog.i) when
Mercurial pushes to repositories on Windows shares served by Samba.

This is a workaround for Samba bug 7863, which is present in current latest
stable Samba 3.5.6 and various prior versions down to 3.0.26a (the oldest one
I tested).

Of course this should be fixed in Samba, but there probably aren't that many
other applications who use hardlinks that extensively and keep files open like
Mercurial, so the pressure to fix this on Samba is probably not that high. And
even if the Samba project should be able to fix their bug within a month or
two, it will take quite some time until users upgrade their Samba installs.
2010-12-13 22:38:06 +01:00
Steve Borho
8562094eb1 util: concentrate quoting knowledge to windows.py quotecommand()
This fixes all callers of util.quotecommand() and place special knowledge
of the bugfix in 2.7.1 in a single platform specific place.
2010-12-22 13:25:00 -06:00
Steve Borho
1493f6fe1b util: work around behavior change in Python 2.7.1 2010-12-13 11:51:01 -06:00
David Soria Parra
e107057815 avoid .split() in for loops and use tuples instead
split can be more readable for longer lists like the list in
dirstate.invalidate. As dirstate.invalidate is used in wlock() and therefoe
used heavily, I think it's worth avoiding a split there too.
2010-12-02 03:43:06 +01:00
Jim Hague
e572ae4bd8 opener: forbid paths ending with directory separator (issue2507)
If Linux is asked to open a filename with a trailing directory separator,
e.g. "foo/", the open fails with EISDIR. On AIX, the open succeeds, opening
file "foo". This causes test-mq-qnew to fail on AIX.

Fix by adding 'ends with directory separator' to the conditions checked
by the path auditor. Change test to expect auditor fail message.
2010-12-17 12:05:45 +00:00
Steve Borho
cd3b55bab4 merge with stable 2010-12-23 13:23:20 -06:00
Adrian Buehlmann
31d1e36f3f makedirs: abort if parent == name (issue2531)
catches unknown drive letters on Windows
2010-12-01 21:15:31 +01:00
Adrian Buehlmann
848dac9692 makedate: abort on negative timestamps (issue2513)
catches weird clock settings
2010-11-24 19:31:43 +01:00
Adrian Buehlmann
9817658bbd parsedate: abort on negative dates (issue2513)
catches "hg commit -d '-7654321 3600'" (example)
2010-11-24 19:31:43 +01:00
Nicolas Dumazet
0885c6dc3f util: do not recurse in makedirs if name is '' (issue2528) 2010-11-30 17:48:12 +09:00
Adrian Buehlmann
a5a62b9b6f util.datestr: do not crash on revisions with negative timestamp (issue2513)
Python's time.gmtime(lt) fails on Windows, producing a traceback with

  ValueError: (22, 'Invalid argument')

if lt < -43200.

We get a local time boundary value of -43200 if we take "the epoch"

   Thu Jan 01 00:00:00 1970 = time.gmtime(0)

from timezone 'UTC+0' into timezone 'UTC-12'. All other timezones will have
larger local time values for that point in time.

Aborting with a traceback on 'hg log' for revisions with a timestamp value
< -43200 is clearly not acceptable.

Returning "invalid timestamp" or similar as string representation is not an
option either, since that may crash other tools which parse the output of
'hg log'.

Instead, we teach util.datestr() to return the epoch in timezone UTC+0 on
*all platforms*, represented by the string

  Thu Jan 01 00:00:00 1970 +0000

if the timestamp's unix time value is negative.

(based on a patch originally proposed by Benjamin Pollack)
2010-11-23 13:11:40 +01:00
Adrian Buehlmann
c0bc968f19 checknlink: return False if .hgtmp file preexists (issue2517)
If os_link fails on Windows, errno is always errno.EINVAL,
so we can't really say if the testlink could not be created
because (a) the FS doesn't support hardlinks or (b) there
is a leaked .hgtmp file lying around from a previous crashed
run.

So let's err on the safe side, keep the code simple and assume
we can't detect hardlinks in both cases.
2010-11-23 22:53:47 +01:00
Adrian Buehlmann
b1824b07a4 opener: check hardlink count reporting (issue1866)
The Linux CIFS kernel driver (even in 2.6.36) suffers from a hardlink
count blindness bug (lstat() returning 1 in st_nlink when it is expected
to return >1), which causes repository corruption if Mercurial running
on Linux pushes or commits to a hardlinked repository stored on a Windows
share, if that share is mounted using the CIFS driver.

This patch works around issue1866 and improves the workaround done in
65e082ae3076 to fix issue761, by teaching the opener to lazily execute a
runtime check (new function checknlink) to see if the hardlink count
reported by nlinks() can be trusted.

Since nlinks() is also known to return varying count values (1 or >1)
depending on whether the file is open or not and depending on what client
and server software combination is being used for accessing and serving
the Windows share, we deliberately open the file before calling nlinks() in
order to have a stable precondition. Trying to depend on the precondition
"file closed" would be fragile, as the file could have been opened very
easily somewhere else in the program.
2010-11-07 18:21:29 +01:00
Adrian Buehlmann
57283f18cb util: refactor opener
- Don't call atomictempfile or nlinks() if the path is malformed
  (no basename). Let posixfile() raise IOError directly.
- atomictempfile already breaks up hardlinks, no need to poke
  at the file with nlinks() if atomictemp.
- No need to copy the file contents to break hardlinks for 'w'rite
  modes (w, wb, w+, w+b). Unlinking and recreating the file is faster.
2010-11-04 09:04:37 +01:00
Martin Geisler
23c9a547e5 opener: do not create "foo" directory when writing to "foo/"
The directories were not cleaned up when the subsequent open failed
and this would confuse things like qnew.
2010-10-29 12:50:08 +02:00
Steve Borho
dde38080ab Merge with stable 2010-12-13 12:19:26 -06:00
Adrian Buehlmann
15eb1de134 opener: always reset flags on 'w'rite
only the patcher needs to preserve flags on write
2010-12-10 15:14:05 +01:00
Brodie Rao
1d9f172d6c record: move copystat() hack out of util.copyfile() and into record
226847bf9cab updated copyfile to also copy over atimes and
mtimes. That behavior is specifically to trick editors into thinking
files that hg record has modified haven't changed. We don't really
care about preserving times in the general case.
2010-12-07 20:03:05 +11:00
Dan Villiom Podlaski Christiansen
1c69d6eb9a util: make atomicfiles closable 2010-12-07 16:03:42 +01:00
Matt Mackall
15ad3a76d6 merge with stable 2010-12-01 18:47:40 -06:00
Nicolas Dumazet
7e56ad61ee merge with stable 2010-12-01 11:02:12 +09:00
Steve Borho
f938c786bf Merge with stable 2010-11-24 13:43:40 -06:00
Martin Geisler
6a3d9310ab code style: prefer 'is' and 'is not' tests with singletons 2010-11-22 18:15:58 +01:00
Nicolas Dumazet
1701ac1b51 util: clarify purpose of MBTextWrapper class
It's easy to get confused and scared of an Unicode monster when
skimming through this code: document that this is really just
about column-counting.
2010-11-09 13:43:35 +09:00
Matt Mackall
a3ff3a53e2 util: make wrap() require a width argument
This keeps hgweb's help engine from poking at file descriptors that
don't exist.
2010-10-10 18:02:52 -05:00
Augie Fackler
42c8b2cf07 termwidth: move to ui.ui from util 2010-10-10 10:06:36 -05:00
Patrick Mezard
9765952244 util: remove needbinary(), no longer used for external patching 2010-10-09 15:13:08 -05:00
Matt Mackall
51b3b09c8f backout most of 26e0b9a8ce0d 2010-09-24 12:46:54 -05:00
Brodie Rao
7362459729 cleanup: use x in (a, b) instead of x == a or x == b 2010-09-23 00:02:31 -05:00
Patrick Mezard
614db673f4 Merge with stable 2010-09-20 22:29:13 +02:00
Patrick Mezard
979ccf4590 Use lexists() instead of exists() where appropriate 2010-09-20 21:46:56 +02:00
Nicolas Dumazet
90787c08f9 util: get rid of extra trailing whitespace in parsedate abort message 2010-08-30 13:29:44 +09:00
Augie Fackler
d89ff49a61 parsebool: accept always as true and never as false 2010-08-30 10:28:25 -05:00
Augie Fackler
cb7412977d parsebool: create new function and use it for config parsing 2010-08-28 21:50:35 -05:00
Augie Fackler
a4e145ed4e util: clean up trailing whitespace 2010-08-28 21:49:53 -05:00
Martin Geisler
bad6437907 path_auditor: delegate checking of nested repos to a callback 2010-08-29 23:56:19 +02:00
Martin Geisler
3a252b7f3e util: use 'auditor' as consistent name for path auditors 2010-08-29 23:56:19 +02:00
Martin Geisler
4f7d586f86 util: add optional path auditor argument to canonpath
The canonpath function will default to creating its own path auditor,
but in some cases it will be useful to use a specialized auditor,
e.g., one that wont abort if a path lies within a subrepository.
2010-08-29 23:56:19 +02:00
Brodie Rao
d1905b7d87 mail/hgweb: support service names for ports (issue2350)
This adds util.getport(port) which tries to parse port as an int, and
failing that, looks it up using socket.getservbyname(). Thus, the
following will work:

    [smtp]
    port = submission

    [web]
    port = http

This does not apply to ports in URLs used in clone, pull, etc.
2010-08-28 12:31:07 -04:00
Sol Jerome
859b297e3f 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
Martin Geisler
bfea979db3 util: remove lexists, Python 2.4 introduced os.path.lexists 2010-08-25 16:23:32 +02:00
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
Martin Geisler
298efc8d54 util, minirst: do not crash with COLUMNS=0 2009-09-03 21:07:06 +02:00
Carey Evans
28b2e6acc5 util: Fix date format for 12-hour time. 2009-08-21 21:52:57 +12:00
Simon Heimberg
ffdea59f2d util: quicker fspath, do not lower names when the length is different 2009-07-29 14:21:18 +02:00
Nicolas Dumazet
6adbb3c99f util: canonpath: simplify logic
if root == os.sep, then endswithsep(root) is True as well: one test is enough
2009-08-22 15:47:03 +02:00
Patrick Mezard
a1609c7698 Merge with crew-stable 2009-08-23 13:03:10 +02:00
Matt Mackall
e3dc8aa6db fix memory usage of revlog caches by limiting cache size [issue1639] 2009-07-09 17:10:07 -05:00
Martin Geisler
2f4412b3b9 util: remove unused bufsize argument
Removed it correctly this time: the subprocess default is 0, not -1
and so we must pass -1 explicitly. Added a comment to that effect.
2009-07-09 11:59:18 +02:00
Bryan O'Sullivan
6ba3698e94 Merge backed out change 2009-07-08 17:03:16 -07:00
Bryan O'Sullivan
b467399b6f Backed out changeset 6a565336bae3: it caused a 5x performance regression on OS X 2009-07-08 17:01:18 -07:00
Martin Geisler
607267cbbc util: wrap at termwidth-2 by default 2009-07-16 23:25:25 +02:00
Simon Heimberg
4ba52122d6 util: use propertycache in opener instead of __getattr__ 2009-07-10 17:54:04 +02:00
Matt Mackall
eb6cba34d7 Merge with stable 2009-07-09 19:49:02 -05:00
Martin Geisler
a94a165c74 merge with crew-stable 2009-07-09 11:59:56 +02:00
Bryan O'Sullivan
c5ab2a3c14 Merge OS X performance regression fix 2009-07-08 17:03:50 -07:00
Alejandro Santos
3183e52503 compat: use // for integer division 2009-07-05 11:00:44 +02:00
Martin Geisler
a9670d9567 util: remove unused bufsize argument in popen[23] 2009-05-09 17:34:11 +02:00
Martin Geisler
e8bc5f4f01 util: remove ignored mode argument in popen[23] 2009-05-09 17:32:57 +02:00
Martin Geisler
1454ed1684 commands: wrap short descriptions in 'hg help'
The code for wrapping a single line of text with a hanging indent was
duplicated in commands and help -- it's now moved to a new function
called wrap in util.

The function defaults to a line width is 78 chars, and this un-wraps
some command line flag descriptions, hence the test output changes.
2009-06-24 19:15:58 +02:00
Benoit Boissinot
62eea686e0 atomictempfile: fix exception in __del__ if mktempcopy fails (self._fp is None)
Make what is going on more obvious by explicitely getting the 'closed'
attribute from _fp, instead of from the gettatr proxy.
2009-06-13 13:14:02 +02:00
Benoit Boissinot
125a85ec87 use new style classes 2009-06-10 15:10:21 +02:00
Martin Geisler
d8ad0f17b4 util: simplify range expression
The n index variable was unused. Every iteration would pop one element
off of parts, so the for loop can be replaced with a while loop.
2009-05-26 22:37:26 +02:00
Matt Mackall
a30eb02911 cmdutils: Take over glob expansion duties from util 2009-05-24 16:38:29 -05:00
Matt Mackall
f1f37a33cf match: move util match functions over 2009-05-24 02:56:14 -05:00
Matt Mackall
2658db5c8c util: privatize globre 2009-05-24 02:56:14 -05:00
Matt Mackall
b287cf72fe match: refactor patkind
add patkind(pat) to match
change external users
change util.patkind to _patsplit
2009-05-24 02:56:14 -05:00
Matt Mackall
532c58d931 match: change all users of util.matcher to match.match 2009-05-24 02:56:14 -05:00
Patrick Mezard
324692dc75 subrepo: force en_US.UTF-8 locale when calling svn
Parser only knows about en_US output. Forcing the encoding to UTF-8 might not
be the best thing to do since the caller may receive some of the subversion
output, but at least it should prevent conversion errors from svn client.
2010-01-02 16:42:00 +01:00
Patrick Mezard
a0b47f1b48 subrepo: normalize svn output line-endings 2010-01-02 16:03:25 +01:00
Martin Geisler
5b0900d7be util: use "is" for True/False/None comparisons 2009-05-20 10:50:23 +02:00
Simon Heimberg
e859b5a899 util: use set instead of dict 2009-05-19 09:57:06 +02:00
Bryan O'Sullivan
496cd5e84c util: make atomictempfile saner if mktempcopy fails 2009-05-14 14:12:32 -07:00
Peter Arrenbrecht
a75765cf7f drop unused imports 2009-05-14 15:35:46 +02:00
Bryan O'Sullivan
ff0948b137 util.termwidth: a file-like object may legitimately lack a fileno() method
Spotted in the wild when running a hook while pushing over HTTPS.
2009-05-11 11:53:27 -07:00
Bryan O'Sullivan
64e91f0ca1 atomictempfile: delegate to posixfile instead of inheriting from it 2009-03-26 13:12:11 -07:00
Simon Heimberg
09ac1e6c92 separate import lines from mercurial and general python modules 2009-04-28 17:40:46 +02:00
Simon Heimberg
f29f0db784 util: overwrite sha1 and _fastsha1 2009-05-08 09:59:15 +02:00
Martin Geisler
97b9a7a062 util: simplify pipefilter and avoid subprocess race
The subprocess module is not thread safe. Spawning a thread to read
the output leads to exceptions like this when Mercurial exits:

  Exception exceptions.TypeError: TypeError("'NoneType' object is not
  callable",) in <bound method Popen.__del__ of <subprocess.Popen
  object at 0x9ed0dcc>> ignored

The bug is already reported in the Python bug tracker:

  http://bugs.python.org/issue1731717
2009-05-07 01:33:44 +02:00
Matt Mackall
01454e7a1b util: kill unused Popen3 2009-05-04 14:22:33 -05:00
Martin Geisler
8fdb40802d util: stop overwriting sha1, overwrite _fastsha1 instead
Some modules (like revlog) would import util.sha1 as _sha1. This
defeats the purpose of having util.sha1 overwrite itself with a faster
version -- revlog would end up always calling the slow version. By
always delegating to util._fastsha1 we avoid this at the cost of an
extra (but unconditional) indirection.
2009-05-04 22:14:52 +02:00
Martin Geisler
6533e94352 util: remove md5
This hash function is broken and should not be used by new code. It is
currently only used by keepalive.
2009-05-04 21:30:39 +02:00
Sune Foldager
b19fc2c469 util: remove warnings when importing md5 and sha 2009-05-04 20:29:05 +02:00
Martin Geisler
21ba2e96f6 util: initialize md5 and sha1 without using extra global variables
This lets the functions skip the "if _sha1 is None" test on each call.
2009-05-03 00:03:35 +02:00
Martin Geisler
11190d5aaa util: always use subprocess 2009-05-02 23:05:35 +02:00
Patrick Mezard
695b5f0d5f Fix missing import from 4bea569e9933 merge 2009-04-30 08:38:20 +02:00
Patrick Mezard
0cdb05f6a7 Merge with crew-stable 2009-04-29 23:56:20 +02:00
Sune Foldager
2f3ee06863 util.rename: use temporary file name for rename-targets on windows
Use a temporary file name as target for a forced rename on Windows. The
target file name is not opened at any time; just renamed into and then
unlinked. Using a temporary instead of a static name is necessary since
otherwise a hg crash can leave the file lying around, blocking future
attempts at renaming.
2009-04-29 09:30:28 +02:00
Martin Geisler
2c8901a1b9 turn some comments back into module docstrings 2009-04-26 01:24:49 +02:00
Martin Geisler
8e4bc1e9ad put license and copyright info into comment blocks 2009-04-26 01:13:08 +02:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Matt Mackall
2f9b02c62d replace util.sort with sorted built-in
This is marginally faster for small and moderately-sized lists
2009-04-26 16:50:44 -05:00
Matt Mackall
9ec97bdefe util: take propertycache from context.py 2009-04-26 16:50:44 -05:00
Matt Mackall
8a63c10958 util: kill configparser wrapper 2009-04-26 16:50:43 -05:00
Martin Geisler
44aa7e92d1 util: use built-in set instead of util.unique 2009-04-22 00:56:06 +02:00
Martin Geisler
1deb417a82 util: use built-in set and frozenset
This drops Python 2.3 compatibility.
2009-04-22 00:55:32 +02:00
Martin Geisler
cc72b62ca4 util: return boolean result directly in util.binary 2009-04-22 17:14:58 +02:00
Dirkjan Ochtman
fe39d83f68 cleanup: remove all trailing whitespace 2009-03-23 13:11:11 +01:00
Matt Mackall
5871cdf2c8 audit: be even pickier (issue1450) 2009-03-04 17:02:16 -06:00
Sune Foldager
3fb25f365e util: don't overwrite os-specific functions with general ones 2009-04-04 18:12:43 +02:00
Justin Peng
d4938a90ee Correct a bug on date formats with '>' or '<' accompanied by space characters. 2009-04-01 09:11:00 -07:00
Matt Mackall
642f4d7151 move encoding bits from util to encoding
In addition to cleaning up util, this gets rid of some circular dependencies.
2009-04-03 14:51:48 -05:00
Matt Mackall
2cddde0437 move util.Abort to error.py 2009-04-03 13:20:52 -05:00
Steve Borho
67420334f3 windows: hoist expand_glob() back into util.py
The windows version of expand_glob() requires patkind(). To
avoid a circular dependency, move function back into util.py.
2009-03-26 22:07:01 -05:00
Matt Mackall
0952760f82 util: split out posix, windows, and win32 modules 2009-03-26 13:54:44 -05:00
Alexander Solovyov
475ce753d3 templater: ability to display diffstat for log-like commands 2009-03-23 10:41:42 +01:00
Peter Arrenbrecht
19591b6a8c cleanup: drop unused assignments 2009-03-23 13:13:06 +01:00
Matt Mackall
7c27807553 audit: check for casefolding of .hg (issue1450) 2009-02-16 17:37:23 -06:00
Matt Mackall
f547c37df5 rename: simplify forced renaming
This should help work around virus scanner issues with rename on Windows.
2009-02-16 17:37:23 -06:00
Will Maier
fbbafcd5d7 Use shutil.copystat in copyfile(). 2009-02-09 07:55:42 -06:00
Mads Kiilerich
d775f5aa2a Make util.find_exe alway returns existing file, fixing issue1459
It seems like the old behaviour with different handling for commands with and
without path was intended, but I think this behaviour of util.find_exe is
better:
* Always returns existing file
* or None if command not found - no default
* Windows: Returned file thus always ends with extension from PATHEXT

This fixes http://www.selenic.com/mercurial/bts/issue1459. The change might
fix other unintended behaviour too.
2009-01-25 21:20:13 +01:00
Matt Mackall
6a6762635c simplify colwidth a bit 2009-01-23 14:51:09 -06:00
Shun-ichi GOTO
fccc1f5345 Also find correct column width of wide characters.
Use unicodedata.east_asian_width() to determine wide/full width
characters if available. Otherwise, return character count as before.
2009-01-21 20:29:47 +09:00
Matt Mackall
104a85dee5 error: move SignatureError 2009-01-12 13:51:43 -06:00
Matt Mackall
7f3bf9b19d error: move SignalInterrupt
now derived from KeyboardInterrupt to simplify catches
2009-01-12 11:48:05 -06:00
Matt Mackall
534da54d07 error: move UnexpectedOutput (now ResponseError) 2009-01-12 11:28:28 -06:00
Matt Mackall
356502607f refactor version code
- simplify version detection code
- move detection code into setup.py
- move version reading function into util.py
- drop version.py code

This makes hg more closely follow its own recommendation of how to deal with
versioning your builds: use hg id in your build script.
2009-01-10 18:02:38 -06:00
Matt Mackall
a25d874c56 Merge with -stable 2008-12-31 18:00:35 -06:00
Matt Mackall
71a02e35c5 audit: reject paths with .hg (issue 1450)
Spotted by Peter Arrenbrecht
2008-12-31 16:27:20 -06:00
Alexander Solovyov
c1774bb6c3 python implementation of diffstat
Implemented as two functions: diffstat, which yields lines of text,
formatted as a usual diffstat output, and diffstatdata, which is called
inside diffstat to do real performing and yield file names with
appropriate data (numbers of added and removed lines).
2008-12-25 10:48:24 +02:00
Dirkjan Ochtman
265b2d6c5c merge with crew-stable 2008-12-19 18:49:02 +01:00