Commit Graph

812 Commits

Author SHA1 Message Date
Matt Mackall
3a9838cebc merge with stable 2011-11-15 14:33:06 -06:00
Mads Kiilerich
6485196281 util: don't encode ':' in url paths
':' has no special meaning in paths, so there is no need for encoding it.

Not encoding ':' makes it easier to test on windows.
2011-11-07 03:25:10 +01:00
Matt Mackall
e538620d00 merge with stable 2011-09-27 18:50:18 -05:00
Kevin Gessner
d0a563a1b5 util: fix crash converting an invalid future date to string
Post-2038 timestamps cannot be handled on 32-bit architectures. Clamp
such dates to the maximum 32-bit timestamp.
2011-09-23 09:02:27 -07:00
Mads Kiilerich
35dbb9abb2 http: handle push of bundles > 2 GB again (issue3017)
It was very elegant that httpsendfile implemented __len__ like a string. It was
however also dangerous because that protocol can't handle sizes bigger than 2 GB.
Mercurial tried to work around that, but it turned out to be too easy to
introduce new errors in this area.

With this change __len__ is no longer implemented at all and the code will work
the same way for short and long posts.
2011-09-21 22:52:00 +02:00
Matt Mackall
19be20e2ef url: parse fragments first (issue2997) 2011-09-10 17:49:19 -05:00
FUJIWARA Katsunori
5b5a083f16 i18n: calculate terminal columns by width information of each characters
neither number of 'bytes' in any encoding nor 'characters' is
appropriate to calculate terminal columns for specified string.

this patch modifies MBTextWrapper for:

  - overriding '_wrap_chunks()' to make it use not built-in 'len()'
    but 'encoding.colwidth()' for columns of string

  - fixing '_cutdown()' to make it use 'encoding.colwidth()' instead
    of local, similar but incorrect implementation

this patch also modifies 'encoding.py':

  - dividing 'colwith()' into 2 pieces: one for calculation columns of
    specified UNICODE string, and another for rest part of original
    one. the former is used from MBTextWrapper in 'util.py'.

  - preventing 'colwidth()' from evaluating HGENCODINGAMBIGUOUS
    configuration per each invocation: 'unicodedata.east_asian_width'
    checking is kept intact for reducing startup cost.
2011-08-27 04:56:12 +09:00
Mads Kiilerich
ec483cfecb util: wrap lines with multi-byte characters correctly (issue2943)
This re-introduces the unicode conversion what was lost in e5976ee55f4b 5 years
ago and had the comment:
  To avoid corrupting multi-byte characters in line, we must wrap
  a Unicode string instead of a bytestring.
2011-08-06 23:52:20 +02:00
Patrick Mezard
9aadd2540f http: strip credentials from urllib2 manager URIs (issue2885)
urllib2 password manager does not strip credentials from URIs registered with
add_password() and compare them with stripped URIs in find_password(). Remove
credentials from URIs returned by util.url.authinfo(). It sometimes works when
no port was specified as the URI host is registered too.
2011-08-05 21:05:40 +02:00
Mads Kiilerich
965df356e5 url: really handle urls of the form file:///c:/foo/bar/ correctly
8264e5172141 made sure that paths that seemed to start with a windows drive
letter would not get an extra leading slash.

localpath should thus not try to handle this case by removing a leading slash,
and this special handling is thus removed.

(The localpath handling of this case was wrong anyway, because paths that look
like they start with a windows drive letter can't have a leading slash.)

A quick verification of this is to run 'hg id file:///c:/foo/bar/'.
2011-08-04 02:51:29 +02:00
Benoit Boissinot
573390f2a4 url: store and assume the query part of an url is in escaped form (issue2921) 2011-07-31 21:00:44 +02:00
Simon Heimberg
d6ebf02048 util: fix finding of hgexecutable
The version introduced in 0070c1dc1b72 would for example return thg
(thanks to Mads Kiilerich for pointing to this)
2011-07-23 06:18:18 +02:00
Matt Mackall
757bb24a98 merge with stable 2011-09-10 17:56:42 -05:00
Simon Heimberg
97acb3896d util: improve finding of hgexecutable
check the module __main__ before looking on the default path
2011-07-23 06:18:18 +02:00
Martin Geisler
0bbf634d5b merge with stable 2011-08-30 15:22:10 +02:00
Adrian Buehlmann
f334675c97 util: postpone and reorder parent calculation in makedirs 2011-08-25 11:03:16 +02:00
Greg Ward
bc1dfb1ac9 atomictempfile: make close() consistent with other file-like objects.
The usual contract is that close() makes your writes permanent, so
atomictempfile's use of close() to *discard* writes (and rename() to
keep them) is rather unexpected. Thus, change it so close() makes
things permanent and add a new discard() method to throw them away.
discard() is only used internally, in __del__(), to ensure that writes
are discarded when an atomictempfile object goes out of scope.

I audited mercurial.*, hgext.*, and ~80 third-party extensions, and
found no one using the existing semantics of close() to discard
writes, so this should be safe.
2011-08-25 20:21:04 -04:00
Mads Kiilerich
f701cb534b util.makedirs: make recursion simpler and more stable (issue2948)
Before, makedirs could call itself recursively with the same path name it was
given, relying on sane file system behavior to terminate the recursion. That
could cause infinite recursion on insane file systems.

Instead we now call mkdir explicitly after having created parent directory
recursively. Exceptions from this mkdir is not swallowed.
2011-08-22 00:42:38 +02:00
Mads Kiilerich
7ebc89bb63 util.makedirs: propagate chmod exceptions
The existing exception handling was intended to handle mkdir errors. Strange
chmod exceptions could thus have strange consequences - or be swallowed.
2011-08-22 00:35:42 +02:00
Mads Kiilerich
eec07d1052 util: wrap lines with multi-byte characters correctly (issue2943)
This re-introduces the unicode conversion what was lost in e5976ee55f4b 5 years
ago and had the comment:
  To avoid corrupting multi-byte characters in line, we must wrap
  a Unicode string instead of a bytestring.
2011-08-06 23:52:20 +02:00
Patrick Mezard
5e4ec42fdf http: explain why the host is passed to urllib2 password manager
The original comment was in url.getauthinfo() and was lost in 1835264d98c1.
2011-08-06 14:10:59 +02:00
Matt Mackall
96e41d94f5 merge with stable 2011-08-05 16:07:51 -05:00
Adrian Buehlmann
50665a9994 util: move copymode into posix.py and windows.py
reducing it to a NOP on Windows.

This eliminates a pointless stat call on Windows and reduces the risk of
interferring with other processes (e.g. AV-scanners, file change watchers).

See also http://mercurial.selenic.com/wiki/UnlinkingFilesOnWindows, item 2d
2011-08-02 13:18:56 +02:00
Adrian Buehlmann
cac3521896 util: factor new function copymode out of mktempcopy 2011-08-02 12:29:48 +02:00
Matt Mackall
e75325116a merge with stable 2011-08-01 10:54:34 -05:00
Matt Mackall
8fc00f653d url: handle urls of the form file:///c:/foo/bar/ correctly 2011-07-22 17:11:35 -05:00
Mads Kiilerich
e8138203dd util: rename the util.localpath that uses url to urllocalpath (issue2875)
util is never imported by any other name than util, so this is mostly just a
simple search and replace from util.localpath to util.urllocalpath (assuming
other uses of util.localpath already has been renamed).
2011-07-01 17:37:09 +02:00
Matt Mackall
8e3367eb55 subrepos: be smarter about what's an absolute path (issue2808) 2011-06-29 16:01:06 -05:00
Matt Mackall
6f9d587fae url: catch UNC paths as yet another Windows special case (issue2808) 2011-06-20 16:45:33 -05:00
Idan Kamara
5e2d608efc dispatch: write shell alias output to ui out descriptor 2011-06-07 13:39:09 +03:00
Idan Kamara
02f21a70dc util: add helper function isatty(fd) to check for tty-ness 2011-06-02 00:43:34 +03:00
Peter Arrenbrecht
af91571a48 util: make str(url) return file:/// for abs paths again
str(url) was recently changed to return only file:/. However, the
canonical way to represent absolute local paths is file:/// [1], which
is also expected by at least hgsubversion.

Relative paths are returned as file:the/relative/path.

[1] http://en.wikipedia.org/wiki/File_URI_scheme
2011-05-12 16:41:56 +02:00
Augie Fackler
7fbddf4d03 util: use safehasattr or getattr instead of hasattr 2011-07-25 16:04:40 -05:00
Augie Fackler
93efe8c08b safehasattr: new function to work around hasattr being broken 2011-07-25 14:59:55 -05:00
Idan Kamara
09359f3d7d posix, windows: introduce cachestat
This class contains a stat result, and possibly other file info to reliably
determine between two points in time whether a file has changed.

Uniquely identifying a file gives us that reliability because we either
atomic rename or append. So one of two will happen: the file 'id' will change,
or the size of the file will change.

posix implements it simply by calling os.stat() and checking if the result
has st_ino.

For now on Windows we always assume the path is uncacheable. This can be
improved on NTFS due to file IDs: http://msdn.microsoft.com/en-us/library/aa363788(v=vs.85).aspx

So we need to find out if a file path is on an NTFS drive, for that we have:

- GetVolumeInformation, which unfortunately only works with a root path (but is available on XP)
- GetVolumeInformationByHandleW, works on a full file path but requires Vista or higher
2011-07-25 15:03:02 +03:00
Adrian Buehlmann
f1218befa0 util: eliminate wildcard imports 2011-07-23 12:29:52 +02:00
Matt Mackall
e7ac311a48 merge with stable 2011-07-22 17:17:23 -05:00
Adrian Buehlmann
2229d01007 util: move windows and posix wildcard imports to begin of file 2011-07-21 11:05:26 +02:00
Adrian Buehlmann
fefd0e5c0a util: move "default" hidewindow to posix.py
There is a hidewindow in win32.py, which we get via windows.py
2011-07-22 10:35:05 +02:00
Adrian Buehlmann
b3b6db23eb util: move "default" lookupreg to posix.py
There is a lookupreg in win32.py, which we get via windows.py
2011-07-22 10:31:56 +02:00
Adrian Buehlmann
f5f99a1f05 util: move "default" unlinkpath to posix.py
we have a unlinkpath in windows.py
2011-07-22 09:55:46 +02:00
Adrian Buehlmann
0da6a5ee7a util: move "default" makedir to posix.py
makedir is already defined in win32.py, which gets imported into util.py
via windows.py if we are running on Windows
2011-07-22 09:53:15 +02:00
Adrian Buehlmann
4163cf2e6f rename util.find_exe to findexe 2011-05-08 20:35:46 +02:00
Adrian Buehlmann
6d0fd501f8 util: rename _windows_reserved_filenames and _windows_reserved_chars 2011-05-07 22:25:20 +02:00
Patrick Mezard
483dc48091 util: make readfile() operate in binary mode
writefile() and appendfile() are already working that way.
2011-05-07 21:12:35 +02:00
Adrian Buehlmann
5573dff691 rename util.os_link to oslink 2011-05-06 15:34:34 +02:00
Adrian Buehlmann
e94d06bb79 rename explain_exit to explainexit 2011-05-06 15:31:09 +02:00
Adrian Buehlmann
554b565228 rename util.lookup_reg to lookupreg 2011-05-06 15:16:22 +02:00
Adrian Buehlmann
77a777c79b rename util.set_hgexecutable to _sethgexecutable 2011-05-06 15:13:46 +02:00
Adrian Buehlmann
90df715d75 rename util.main_is_frozen to mainfrozen 2011-05-06 15:10:29 +02:00
Dan Villiom Podlaski Christiansen
88e742876f util & scmutil: adapt read/write helpers as request by mpm 2011-05-02 10:11:05 +02:00
Mads Kiilerich
d27df0bd40 test: test that backslash is preserved by the url class 2011-05-01 15:49:13 +02:00
Mads Kiilerich
e0a200cbea tests: use raw string for url tests of '\' handling 2011-05-01 15:49:13 +02:00
Matt Mackall
4cd6f6bed2 util: really drop size from readfile 2011-05-01 04:56:24 -05:00
Dan Villiom Podlaski Christiansen
20529399de util: add readfile() & writefile() helper functions
These two functions allow quickly reading or writing a file, without
relying on reference counting to close the file handle afterwards.
2011-05-01 11:46:49 +02:00
Brodie Rao
6d4af78635 util.url: copy urllib.unquote() into util to improve startup times
The ui class uses util.hasscheme() in a couple of places, causing hg
to import urllib even when it doesn't need to. This copies
urllib.unquote() to avoid that import.

perfstartup time before the URL refactoring (707e4b1e8064):

! wall 0.050692 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

before this change:

! wall 0.064742 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

after this change:

! wall 0.052126 comb 0.000000 user 0.000000 sys 0.000000 (best of 100
2011-04-30 09:43:23 -07:00
Brodie Rao
b7f0d2a103 url: move URL parsing functions into util to improve startup time
The introduction of the new URL parsing code has created a startup
time regression. This is mainly due to the use of url.hasscheme() in
the ui class. It ends up importing many libraries that the url module
requires.

This fix helps marginally, but if we can get rid of the urllib import
in the URL parser all together, startup time will go back to normal.

perfstartup time before the URL refactoring (707e4b1e8064):

! wall 0.050692 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

current startup time (9ad1dce9e7f4):

! wall 0.070685 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

after this change:

! wall 0.064667 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)
2011-04-30 09:43:20 -07:00
Alexander Solovyov
0eb3836642 remove unused imports and variables 2011-04-30 13:59:14 +02:00
Greg Ward
36bf37fc8a atomictempfile: rewrite docstring to clarify rename() vs. close(). 2011-04-24 17:30:50 -04:00
Greg Ward
d95f0484f4 atomictempfile: avoid infinite recursion in __del__().
The problem is that a programmer using atomictempfile directly can
make an innocent everyday mistake -- not enough args to the
constructor -- which escalates badly.  You would expect a simple
TypeError crash in that case, but you actually get an infinite
recursion that is surprisingly difficult to kill: it happens between
__del__() and __getattr__(), and Python does not handle infinite
recursion from __del__() well.

The fix is to not implement __getattr__(), but instead assign instance
attributes for the methods we wish to delegate to the builtin file
type: write() and fileno(). I've audited mercurial.* and hgext.* and
found no users of atomictempfile using methods other than write() and
rename(). I audited third-party extensions and found one (snap)
passing an atomictempfile to util.fstat(), so I also threw in
fileno().

The last time I submitted a similar patch, Matt proposed that we make
atomictempfile a subclass of file instead of wrapping it. Rejected on
grounds of unnecessary complexity: for one thing, it would make the
Windows implementation of posixfile quite a bit more complex. It would
have to become a subclass of file rather than a simple function -- but
since it's written in C, this is non-obvious and non-trivial.
Furthermore, there's nothing wrong with wrapping objects and
delegating methods: it's a well-established pattern that works just
fine in many cases. Subclassing is not the answer to all of life's
problems.
2011-04-24 19:25:10 -04:00
Idan Kamara
762d333ae9 eliminate various naked except clauses 2011-04-23 00:51:25 +03:00
Adrian Buehlmann
bee8559898 move os_rcpath from util to scmutil 2011-04-21 20:54:45 +02:00
Adrian Buehlmann
9a67b02dba move rcpath from util to scmutil 2011-04-21 20:14:29 +02:00
Adrian Buehlmann
267c80394b move walkrepos from util to scmutil 2011-04-21 16:06:19 +02:00
Adrian Buehlmann
756a1d3529 move checkfilename from util to scmutil
checkfilename is specific to Mercurial, since it contains the knowledege
that Mercurial can't track files with \n or \r in the name.
2011-04-21 13:18:52 +02:00
Adrian Buehlmann
307196b733 move path_auditor from util to scmutil 2011-04-20 22:43:31 +02:00
Adrian Buehlmann
f3e8eae526 move canonpath from util to scmutil 2011-04-20 21:41:41 +02:00
Adrian Buehlmann
cf126bb7dd move opener from util to scmutil 2011-04-20 19:54:57 +02:00
Adrian Buehlmann
a3a3063c9b checkwinfilename: use %r in format string 2011-04-16 20:08:43 +02:00
Adrian Buehlmann
bd5adb64fa util: new function checkfilename
checkfilename checks for restrictions on filenames imposed by Mercurial
itself, irrespective of on what platform it is run.
2011-04-15 16:15:30 +02:00
Adrian Buehlmann
c36b2f94e7 opener: use %r in format string for abort 2011-04-15 16:15:28 +02:00
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