Commit Graph

670 Commits

Author SHA1 Message Date
FUJIWARA Katsunori
055136813d icasefs: avoid normcase()-ing in util.fspath() for efficiency
'dirstate._normalize()', the only caller of 'util.fspath()', has
already normcase()-ed path before invocation of it.

normcase()-ed root can be cached on dirstate side, too.

so, this patch changes 'util.fspath()' API specification to avoid
normcase()-ing in it.
2011-12-16 21:09:40 +09:00
FUJIWARA Katsunori
c71595845e icasefs: use util.normcase() instead of lower() or os.path.normcase in fspath
this also avoids lower()-ing on each path components by reuse the path
normcase()-ed at beginning of function.
2011-12-16 21:09:40 +09:00
FUJIWARA Katsunori
f9ca02bd18 icasefs: consider as case sensitive if there is no counterevidence, for safety
for safety, this patch prevents case-less name from misleading into
case insensitivity, even though such names should not be used.
2011-12-16 21:09:40 +09:00
Patrick Mezard
3a0effcd7b util: fix url.__str__() for windows file URLs
Before:

  >>> str(url('file:///c:/tmp/foo/bar'))
  'file:c%3C/tmp/foo/bar'

After:

  >>> str(url('file:///c:/tmp/foo/bar'))
  'file:///c%3C/tmp/foo/bar'

The previous behaviour had no effect on mercurial itself (clone command for
instance) because we fortunately called .localpath() on the parsed URL.
hgsubversion was not so lucky and cloning a local subversion repository on
Windows no longer worked on the default branch (it works on stable because
2b62605189dc defeats the hasdriveletter() test in url class).

I do not know if the %3C is correct or not but svn accepts file:// URLs
containing it. Mads fixed it in 2b62605189dc, so we can always backport should
the need arise.
2011-12-04 18:22:25 +01:00
Dmitry Panov
6649925e57 makedate: wrong timezone offset if DST rules changed this year (issue2511)
Python's time module sets timezone and altzone based on UTC offsets of
two dates: first and middle day of the current year. This approach
doesn't work on a year when DST rules change.

For example Russia abandoned winter time this year, so the correct UTC
offset should be +4 now, but time.timezone returns 3 hours difference
because that's what it was on 01.01.2011.

Related python issue: http://bugs.python.org/issue1647654
2011-11-13 00:29:26 +00:00
Mads Kiilerich
5d7000644a url: handle file://localhost/c:/foo "correctly"
The path was parsed correctly, but localpath prepended an extra '/' (as in
'/c:/foo') because it assumed it was an absolute unix path.
2011-11-16 00:10:56 +01:00
Matt Mackall
3eab62750e dirstate: fix case-folding identity for traditional Unix
We used to use os.path.normcase which was a no-op, which was unhelpful
for cases like VFAT on Linux.
2011-11-15 14:25:11 -06:00
Matt Mackall
9580de9b45 util: add a doctest for empty sha() calls 2011-10-31 15:41:39 -05:00
Matt Mackall
bbf72a4e6e util: allow sha1() with no args
Normally this works because we replace util.sha1 with hashlib.sha1
after first use, but if the first user doesn't provide an arg, it
breaks.
2011-10-31 14:22:11 -05:00
Matt Mackall
226e1ff7c0 util: don't complain about '..' in path components not working on Windows 2011-10-24 16:57:14 -05: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