Commit Graph

622 Commits

Author SHA1 Message Date
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
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