Commit Graph

798 Commits

Author SHA1 Message Date
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
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Siddharth Agarwal
c9db5b4295 util.fspath: use a dict rather than a linear scan for lookups
Previously, we'd scan through the entire directory listing looking for a
normalized match.  This is O(N) in the number of files in the directory. If we
decide to call util.fspath on each file in it, the overall complexity works out
to O(N^2). This becomes a problem with directories a few thousand files or
larger.

Switch to using a dictionary instead. There is a slightly higher upfront cost
to pay, but for cases like the above this is amortized O(1). Plus there is a
lower constant factor because generator comprehensions are faster than for
loops, so overall it works out to be a very small loss in performance for 1
file, and a huge gain when there's more.

For a large repo with around 200k files in it on a case-insensitive file
system, for a large directory with over 30,000 files in it, the following
command was tested:

ls | shuf -n $COUNT | xargs hg status

This command leads to util.fspath being called on $COUNT files in the
directory.

COUNT  before  after
    1   0.77s  0.78s
  100   1.42s  0.80s
 1000    6.3s  0.96s

I also tested with COUNT=10000, but before took too long so I gave up.
2014-10-24 11:39:39 -07:00
Wagner Bruna
779ceca4ff i18n: add hint to digest mismatch message 2014-10-23 12:35:10 -02:00
Yuya Nishihara
e7ee70da05 util.system: avoid buffering of subprocess output when it is piped
util.system() copies subprocess' output through pipe if output file is not
stdout.  Because a file iterator has internal buffering, output won't be
flushed until enough data is available.  Therefore, it could easily miss
important messages such as "waiting for lock".
2014-08-30 17:38:14 +02:00
Mike Hommey
d2b17ca844 util: add a file handle wrapper class that does hash digest validation
It is going to be used for the remote-changegroup feature in bundle2.
2014-10-16 17:03:21 +09:00
Mike Hommey
6acd9847bf util: add a helper class to compute digests
It is going to be used for the remote-changegroup feature in bundle2.
2014-10-16 17:02:51 +09:00
Mike Hommey
9741dad0cc util: move md5 back next to sha1 and allow to call it without an argument
This effectively backs out changeset 7582042d6cce.

The API change is done so that both util.sha1 and util.md5 can be called the
same way. The function is moved in order to use it for md5 checksumming for
an upcoming bundle2 feature.
2014-09-24 16:00:47 +09:00
Pierre-Yves David
60ead8ca90 util: fix sorteddict.pop
When using `.pop` on such object the list was not cleared of the popped key,
leading to crash.
2014-10-02 12:39:37 -05:00
Mads Kiilerich
e49fb83975 i18n: use datapath for i18n like for templates and help
To avoid circular module dependencies we initialize i18n from util when
datapath is found.
2014-09-28 16:57:47 +02:00
Mads Kiilerich
e9c0145df2 util: introduce datapath for getting the location of supporting data files
templates, help and locale data is normally stored as sub folders in the
directory containing the source of the mercurial module. In a frozen build they
live as sub folders next to 'hg.exe' and 'library.zip'.

These different kind of data were handled in different ways. Unify that by
introducing util.datapath. The value is computed from the environment and is
always used, so we just calculate the value on module load.
2014-09-28 16:57:06 +02:00
Mads Kiilerich
9b9c077bd6 util: move _hgexecutable a few lines, closer to where it is used 2014-09-28 16:57:06 +02:00
Gregory Szorc
db57d5e9d6 platform: implement readpipe()
Reading all available data from a pipe has a platform-dependent
implementation.

This patch establishes platform.readpipe() by copying the
inline implementation in sshpeer.readerr(). The implementations
for POSIX and Windows are currently identical. The POSIX
implementation will be changed in a subsequent patch.
2014-08-15 20:02:18 -07:00
Siddharth Agarwal
2b459094e1 util.re: add an escape method
The escape method in at least one of the modules called 're2' is in C. This
means it is significantly faster than the Python code written in 're'.

An upcoming patch will have benchmarks.
2014-07-15 15:14:45 -07:00
Siddharth Agarwal
dd9e1b721a util.re: move check for re2 into a separate method
We're going to use the same check for another method in an upcoming patch.
2014-07-15 15:01:52 -07:00