Commit Graph

812 Commits

Author SHA1 Message Date
Siddharth Agarwal
532b96181d util: drop Python 2.4 compat by directly importing md5 and sha1
There's been a fair amount of cruft here over the years, which we can all
just get rid of now.
2015-10-24 15:56:16 -07:00
Sean Farley
f6841c5b51 util: also catch IndexError
This makes life so, so much easier for hgwatchman, which provides a named tuple
but throws an IndexError instead of a TypeError.
2015-10-13 16:05:30 -07:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Yuya Nishihara
5715ebc02c util: use tuple accessor to get accurate st_mtime value (issue4836)
Because st.st_mtime is computed as 'sec + 1e-9 * nsec' and double is too narrow
to represent nanoseconds, int(st.st_mtime) can be 'sec + 1'. Therefore, that
value could be different from the one got by osutils.listdir().

This patch fixes the problem by accessing to raw st_mtime by tuple index.

It catches TypeError to fall back to st.st_mtime because our osutil.stat does
not support tuple index. In dirstate.normal(), 'st' is always a Python stat,
but in dirstate.status(), it can be either a Python stat or an osutil.stat.

Thanks to vgatien-baron@janestreet.com for finding the root cause of this
subtle problem.
2015-10-04 22:35:36 +09:00
Yuya Nishihara
ea5724ad42 util: extract stub function to get mtime with second accuracy
This function is trivial but will need a long comment why it can't use
st.st_mtime. See the next patch for details.
2015-10-04 22:25:29 +09:00
Matt Harbison
bb1dafe069 util: extract stringmatcher() from revset
This is used to match against tags, bookmarks, etc in revsets.  It will be used
in a future patch to do the same tag matching in templater.
2015-08-22 22:52:18 -04:00
Gregory Szorc
fd27bc1367 util.chunkbuffer: avoid extra mutations when reading partial chunks
Previously, a read(N) where N was less than the length of the first
available chunk would mutate the deque instance twice and allocate a new
str from the slice of the existing chunk. Profiling drawed my attention
to these as a potential hot spot during changegroup reading.

This patch makes the code more complicated in order to avoid the
aforementioned 3 operations.

On a pre-generated mozilla-central gzip bundle, this series has the
following impact on `hg unbundle` performance on my MacBook Pro:

before: 358.21 real       317.69 user        38.49 sys
after:  301.57 real       262.69 user        37.11 sys
delta:  -56.64 real       -55.00 user        -1.38 sys
2015-10-05 17:36:32 -07:00
Gregory Szorc
c98628be54 util.chunkbuffer: refactor chunk handling logic
This will make the next patch easier to read. It provides no benefit on
its own.
2015-10-05 16:34:47 -07:00
Gregory Szorc
fdf56bc121 util.chunkbuffer: special case reading everything
The new code results in simpler logic within the while loop. It is also
faster since we avoid performing operations on the queue and buf
collections. However, there shouldn't be any super hot loops for this
since the whole point of chunkbuffer is to avoid reading large amounts
of data at once. This does, however, make it easier to optimize
chunkbuffer in a subsequent patch.
2015-10-05 16:28:12 -07:00
Yuya Nishihara
697917e9d9 util.system: compare fileno to see if it needs stdout redirection
Future patches will reopen stdout to be line-buffered, so sys.stdout may
be different object than sys.__stdout__.
2015-10-03 14:57:24 +09:00
Pierre-Yves David
496ebe3ecb changegroup: use a different compression key for BZ in HG10
For "space saving", bundle1 "strip" the first two bytes of the BZ stream since
they always are 'BZ'. So the current code boostrap the uncompressor with 'BZ'.
This hack is impractical in more generic case so we move it in a dedicated
"decompression".
2015-09-23 11:33:30 -07:00
Siddharth Agarwal
209bbcf824 util: avoid mutable default arguments
I almost introduced a bug around this code by accidentally mutating a default
argument. There's no reason for these to exist.
2015-09-22 16:55:18 -07:00
Pierre-Yves David
47af8d73d3 compression: use 'None' for no-compression
This seems more idiomatic and clearer. We still support both None and 'UN' for
now because no user are migrated.
2015-09-15 17:53:28 -07:00
Pierre-Yves David
f052875fa0 changegroup: move all compressions utilities in util
We'll reuse the compression for other things (next target bundle2), so let's
make it more accessible and organised.
2015-09-15 17:35:32 -07:00
timeless@mozdev.org
5569d89fd9 util: capitalize Python in MBTextWrapper._wrap_chunks comment 2015-09-08 15:32:20 -04:00
Yuya Nishihara
7905f93556 util: extract function that parses timezone string
It will be used to parse a timezone argument passed to a template function.
2015-09-01 19:43:14 +09:00
timeless@mozdev.org
52eae47139 spelling: behaviour -> behavior 2015-08-28 10:53:55 -04:00
Pierre-Yves David
2c879590b7 bufferedinputpipe: remove N^2 computation of buffer length (issue4735)
The assumption that dynamically computing the length of the buffer was N^2, but
negligible because fast was False. So we drop the dynamic computation and
manually keep track of the buffer length.
2015-06-26 11:29:50 -07:00
Pierre-Yves David
4d8c7e6435 bufferedinputpipe: remove an outdate comment
This comment is the remains of a intermediate implementation using

  self._buffer += data

This implementation never made it to the repository and we can safely drop the
comment.
2015-06-27 11:51:25 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Pierre-Yves David
6fec33b555 util: add a simple poll utility
We'll use it to detect when a sshpeer have server output to be displayed.

The implementation is super basic because all case support is not the focus of
this series.
2015-05-20 18:00:05 -05:00
Pierre-Yves David
1447d73588 util: introduce a bufferedinputpipe utility
To restore real time server output through ssh, we need to using polling feature
(like select) on the pipes used to communicate with the ssh client. However
we cannot use select alongside python level buffering of these pipe (because we
need to know if the buffer is non-empty before calling select).

However, unbuffered performance are terrible, presumably because the 'readline'
call is issuing 'read(1)' call until it find a '\n'. To work around that we
introduces our own overlay that do buffering by hand, exposing the state of the
buffer to the outside world.

The usage of polling IO will be introduced later in the 'sshpeer' module. All
its logic will be very specific to the way mercurial communicate over ssh and
does not belong to the generic 'util' module.
2015-05-30 23:55:24 -07:00
Pierre-Yves David
e653dac6f9 util: allow to specify buffer size in popen4
We will need unbuffered IO to restore real time output with ssh peer.

Changeset b61b215fcfa8 seems to indicate playing with this value could be
dangerous, but does not indicate why.
2015-05-20 11:29:45 -05:00
Pierre-Yves David
c34d269931 util: drop the 'unpacker' helper
It is not helping anything anymore.
2015-05-18 23:43:36 -05:00
Pierre-Yves David
44c29cf85d MBTextWrapper: drop dedicated __init__ method
It was only there as a compatibility layer with a version of Python which we do
support anymore.
2015-05-18 16:56:04 -05:00
Pierre-Yves David
5af170b397 util: drop the compatibility with Python 2.4 unpacker
Python 2.4 compatibility have packed and sailed.
2015-05-18 16:54:21 -05:00
Augie Fackler
5b25c17d54 util: drop any() and all() polyfills 2015-05-16 14:37:24 -04:00
Martin von Zweigbergk
4127f67694 util: drop alias for collections.deque
Now that util.deque is just an alias for collections.deque, let's just
remove it.
2015-05-16 11:28:04 -07:00
Adrian Buehlmann
db680f7ce8 util: kill Python 2.4 deque.remove hack 2015-05-16 09:03:21 +02:00
Matt Mackall
ef1d6d97be util: use try/except/finally 2015-05-15 09:58:21 -05:00
Siddharth Agarwal
c4e0365d23 util.checkcase: don't abort on broken symlinks
One case where that would happen is while trying to resolve a subrepo, if the
path to the subrepo was actually a broken symlink. This bug was exposed by an
hg-git test.
2015-05-03 12:49:15 -07:00
FUJIWARA Katsunori
d376c990a1 util: add removedirs as platform depending function
According to 6b1369445b7b introducing "windows._removedirs()":

    If a hg repository including working directory is a reparse point
    (directory symlinked or a junction point), then using
    os.removedirs will remove the reparse point erroneously.

"windows._removedirs()" should be used instead of "os.removedirs()" on
Windows.

This patch adds "removedirs" as platform depending function to replace
"os.removedirs()" invocations for portability and safety
2015-04-11 00:47:09 +09:00
Drew Gottlieb
901ac5e726 util: move dirs() and finddirs() from scmutil to util
An upcoming commit requires that match.py be able to call scmutil.dirs(), but
when match.py imports scmutil, a dependency cycle is created. This commit
avoids the cycle by moving dirs() and its related finddirs() function from
scmutil to util, which match.py already depends on.
2015-04-06 14:36:08 -07:00
Siddharth Agarwal
16d94fc24b util: add normcase spec and fallback
These will be used in upcoming patches to efficiently create a dirstate
foldmap.
2015-04-01 00:38:56 -07:00
Augie Fackler
723d5ae42f util: add progress callback support to copyfiles 2015-03-19 10:24:22 -04:00
Yuya Nishihara
3dbf9536f7 sortdict: have update() accept either dict or iterable of key/value pairs
Future patches will make the templater store a sorted dict in the _hybrid object.
sortdict should be constructed from a sorted list.
2015-02-18 22:53:53 +09:00
André Klitzing
350700ad60 util: accept "now, today, yesterday" for dates even the locale is not english
Hi there!

Fixed date names are helpful for automated systems. So it is possible to
use english date parameter even if the underlying system uses another
locale.

We have here a jenkins with build jobs on different slaves that will do
some operations with "dates" parameter. Some systems uses English locale
and some systems uses German locale. So we needed to configure the job to
uses other date names.

As this is really annoying to keep the systems locale in mind for some
operations I looked into util.py. It would be helpful for automated systems
if the "default English" date names would even usable on other
locales.

I attached a simple patch for this.

Best regards
  André Klitzing
2015-02-24 14:12:13 +01:00
Matt Harbison
721f888f2f transaction: really disable hardlink backups (issue4546) 2015-03-02 10:31:22 -05:00
Matt Mackall
055206a473 transaction: disable hardlink backups (issue4546)
Causing troubles, simplest fix.
2015-03-02 00:12:29 -06:00
Wagner Bruna
41a26dac7c messages: quote "hg help" hints consistently 2015-01-17 22:01:14 -02:00
Pierre-Yves David
71304e633e copyfile: allow optional hardlinking
Some code paths use 'copyfiles' (full tree) for a single file to take advantage
of the best-effort-hard-linking parameter. We add similar parameter and logic
to 'copyfile' (single file) for this purpose.

The single file version have the advantage to overwrite the destination file if
it exists.
2015-01-05 12:39:09 -08:00
Matt Mackall
4accabb1fb unpacker: fix missing arg for py2.4 2015-01-14 16:57:00 -08:00
Matt Mackall
f10752833b unpacker: check the right exception type for 2.4 2015-01-13 16:15:02 -08:00
Matt Mackall
2537cb8fbf util: introduce unpacker
This allows taking advantage of Python 2.5+'s struct.Struct, which
provides a slightly faster unpack due to reusing formats. Sadly,
.unpack_from is significantly slower.
2015-01-10 21:18:31 -06:00
Mads Kiilerich
b420dd92b1 spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Pierre-Yves David
a756e8c469 util: add a 'nogc' decorator to disable the garbage collection
Garbage collection behave pathologically when creating a lot of containers. As
we do that more than once it become sensible to have a decorator for it. See
inline documentation for details.
2014-12-04 05:43:40 -08:00
FUJIWARA Katsunori
f60bafa1b3 vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
This patch uses "False" as default value of "notindexed" argument,
even though "vfs.makedir()" uses "True" for it, because "os.mkdir()"
doesn't set "_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED" attribute to newly
created directories.
2014-11-19 18:35:14 +09:00
Yuya Nishihara
b2ed607f5e util.system: remove unused handling of onerr=ui
In our code, onerr is None or util.Abort.  It smells bad to overload ui and
exception class.
2014-11-08 13:14:19 +09:00
Sean Farley
93b998c77a sortdict: add insert method
Future patches will allow extensions to choose which order a namespace should
output in the log, so we add a way for sortdict to insert to a specific
location.
2014-10-15 12:39:19 -07:00
Sean Farley
8ea5f6192f sortdict: add iteritems method
Future patches will start using sortdict for log operations where order is
important. Adding iteritems removes the headache of having to remember to use
items() if the object is a sortdict.
2014-11-09 13:15:28 -08:00