Commit Graph

253 Commits

Author SHA1 Message Date
Adam Simpkins
c92a68e75e util: fix race in makedirs()
Update makedirs() to ignore EEXIST in case someone else has already created the
directory in question.  Previously the ensuredirs() function existed, and was
nearly identical to makedirs() except that it fixed this race.  Unfortunately
ensuredirs() was only used in 3 places, and most code uses the racy makedirs()
function.  This fixes makedirs() to be non-racy, and replaces calls to
ensuredirs() with makedirs().

In particular, mercurial.scmutil.origpath() used the racy makedirs() code,
which could cause failures during "hg update" as it tried to create backup
directories.

This does slightly change the behavior of call sites using ensuredirs():
previously ensuredirs() would throw EEXIST if the path existed but was a
regular file instead of a directory.  It did this by explicitly checking
os.path.isdir() after getting EEXIST.  The makedirs() code did not do this and
swallowed all EEXIST errors.  I kept the makedirs() behavior, since it seemed
preferable to avoid the extra stat call in the common case where this directory
already exists.  If the path does happen to be a file, the caller will almost
certainly fail with an ENOTDIR error shortly afterwards anyway.  I checked
the 3 existing call sites of ensuredirs(), and this seems to be the case for
them.
2016-04-26 15:32:59 -07:00
timeless
85b96c6915 scmutil: use util.queue/util.empty for py3 compat 2016-04-06 20:07:51 +00:00
Gregory Szorc
747bf67026 scmutil: support background closing for write()
Upcoming patches will add background file closer support to
working copy update. This patch adds some plumbing to prepare
for that.
2016-02-20 15:24:12 -08:00
Martin von Zweigbergk
c84bb33a89 match: rename "narrowmatcher" to "subdirmatcher" (API)
I keep mistaking "narrowmatcher" for narrowhg's
narrowmatcher. "subdirmatcher" seems more to the point anyway.
2016-02-05 21:09:32 -08:00
Gregory Szorc
49c61f06be scmutil: support background file closing
Closing files that have been appended to is relatively slow on
Windows/NTFS. This makes several Mercurial operations slower on
Windows.

The workaround to this issue is conceptually simple: use multiple
threads for I/O. Unfortunately, Python doesn't scale well to multiple
threads because of the GIL. And, refactoring our code to use threads
everywhere would be a huge undertaking. So, we decide to tackle this
problem by starting small: establishing a thread pool for closing
files.

This patch establishes a mechanism for closing file handles on separate
threads. The coordinator object is basically a queue of file handles to
operate on and a thread pool consuming from the queue.

When files are opened through the VFS layer, the caller can specify
that delay closing is allowed.

A proxy class for file handles has been added. We must use a proxy
because it isn't possible to modify __class__ on built-in types. This
adds some overhead. But as future patches will show, this overhead
is cancelled out by the benefit of closing file handles on background
threads.
2016-01-14 13:34:59 -08:00
Augie Fackler
54446bb7e0 cleanup: use modern @property/@foo.setter property specification
We can use this now that we're 2.6+, and this is more idiomatic modern
Python.
2016-01-16 10:50:28 -05:00
Bryan O'Sullivan
51b6f1d59f with: use context manager in _markchanges 2016-01-15 13:14:49 -08:00
Gregory Szorc
562be47d7a scmutil: use context managers for file handles
Now that we dropped support for Python 2.4, we are able to use context
managers. Let's replace the try..finally pattern in scmutil.py with
context managers, which close files automatically when the context
manager is exited.

There should be no change in behavior with this patch.

Why convert to context managers if nothing is broken? I'm working on
closing file handles in background threads to improve performance on
Windows. As part of this, I realized there could be some future issues
if the background file closing code isn't designed with context
managers in mind. So, I'd like to switch some code to context managers
so I can design an API that works with context managers.
2016-01-02 15:19:47 -08:00
Siddharth Agarwal
0efe3372e4 origpath: move from cmdutil to scmutil
This is a lower-level function so it doesn't need to be in cmdutil, and putting
it here avoids a bunch of potential import cycle issues.
2016-01-02 03:02:57 -08:00
Matt Mackall
d7ec07e23e merge with stable 2016-01-02 02:13:56 +01:00
Siddharth Agarwal
a6934b01c3 merge: while checking for unknown files don't follow symlinks (issue5027)
Previously, we were using Python's native 'os.path.isfile' method which follows
symlinks. In this case, since we're operating on repo contents, we don't want
to follow symlinks.

There's a behaviour change here, as shown by the second part of the added test.
Consider a symlink 'f' pointing to a file containing 'abc'. If we try and
replace it with a file with contents 'abc', previously we would have let it
though. Now we don't. Although this breaks naive inspection with tools like
'cat' and 'diff', on balance I believe this is the right change.
2015-12-28 22:51:37 -08:00
Gregory Szorc
4602d8f855 scmutil: use absolute_import 2015-12-21 21:23:43 -08:00
Matt Harbison
de09629866 scmutil: abort if an empty revision is given to revpair()
When using 'extdiff --patch' to check the changes in a rebase, 'precursors(x)'
evaluated to an empty set because I forgot the --hidden flag, so the other
revision was used as the replacement for the empty set.  The result was the
patch for the other revision was diffed against itself, and the tool saying
there were no differences.  That's misleading since the expected diff args were
silently changed, so it's better to bail out.

The other uses of scmutil.revpair() are commands.diff and commands.status, and
it doesn't make sense to allow an empty revision there either.  The code here
was suggested by Yuya Nishihara.
2015-10-31 21:45:46 -04:00
Pierre-Yves David
5dc648f5ae format: create new repository as 'generaldelta' by default
Since we have pushed back the performance issue related to general delta behind
another configuration (Still off by default), we can safely create new
repository with general delta support. As client are compatible with it since
Mercurial 1.9 (4.5 years ago) I do no expect any significant compatibility
issues.
2015-11-02 17:33:18 +00: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
Siddharth Agarwal
18a026d1a8 scmutil: add a way for a repo's wlock to be inherited by a subprocess
This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.

In the future, we'll call this for custom merge drivers.
2015-10-05 14:37:59 -07:00
Siddharth Agarwal
2357094a49 scmutil: add a way for a subprocess to be run with an inheritable lock
This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.

In an upcoming patch, we'll add an API for the wlock to be inherited.
2015-10-05 14:34:52 -07:00
Yuya Nishihara
c09856f19f changeset_printer: move _meaningful_parentrevs() to scmutil
It will be used by templatekw.
2015-09-26 12:29:09 +09:00
Matt Mackall
5e1b4ad958 urls: bulk-change primary website URLs 2015-09-30 15:43:49 -05:00
Pierre-Yves David
170f50272a addremove: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs.
2015-09-24 01:04:10 -07:00
Pierre-Yves David
ab85f23ec7 match: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs. We
added support for None in the underlying function in the parent commit.
therefore we do not need to do anything but passing None.
2015-09-24 01:00:43 -07:00
Pierre-Yves David
6b8997438d match: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs.
2015-09-24 01:00:25 -07:00
Pierre-Yves David
e3e8ecef87 match: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs.
2015-09-24 01:00:05 -07:00
Pierre-Yves David
9e29f38f43 match: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs.
2015-09-24 00:59:26 -07:00
Siddharth Agarwal
07b74dc47e scmutil.readonlyvfs: implement join
Required in an upcoming patch.
2015-09-02 22:05:58 -07:00
timeless@mozdev.org
52eae47139 spelling: behaviour -> behavior 2015-08-28 10:53:55 -04:00
Yuya Nishihara
8e8af6e090 revpair: restrict odd-range handling to top-level x:y expression (issue4774)
The odd-range hack was introduced by 9afcfbca1710 for backward compatibility,
but it was too widely applied. I've checked cmdutil.revpair() at 1.6, and
found that ".:", ":0" and ":" are also handled as pairs. So let's enable the
hack only for "x:y", "x:", "y:" and ":".

test-revset.t is updated because "tip^::tip^ or tip^" shouldn't be taken as
an odd range. This patch adds "tip^:tip^" instead.

This patch is written for the default branch because parse() of the stable
branch lacks compatibility hack for "foo+bar" tag. If we want to mitigate the
issue in stable, we can add something like "and '::' in revs[0]".
2015-08-13 16:15:43 +09:00
Pierre-Yves David
c8b7676e04 format: introduce 'format.usegeneraldelta`
This option will make repositories created as general delta by default but will
not make Mercurial aggressively recompute deltas for all incoming bundle.
Instead, the delta contained in the bundle will be used. This will allow us to
start having general delta repositories created everywhere without triggering
massive recomputation costs for all new clients cloning from old servers.
2015-11-02 15:59:12 +00:00
Pierre-Yves David
474dfeda7e scmutil: extract general delta config handling in a function
General delta is currently controlled by a single option, we will introduce a
new one in the next changeset.

We extract the logic in a function while it is simple.
2015-11-02 16:52:34 +00:00
Yuya Nishihara
73b047cec9 revrange: evaluate all revset specs at once
This provides an opportunity for revset to optimize given expressions. For
example, "-r0 -r1 -r2" can be optimized to "_list(0 1 2)".
2015-07-05 12:35:42 +09:00
Yuya Nishihara
8c83cdaaac revrange: drop old-style parser in favor of revset (API)
Now revset can parse nullary ":" operator and existing "foo+bar" tags, we
don't need the old-style parser.

This means scmutil.revsingle(), revpair() and revrange() no longer accept
a binary nodeid. An integer revision is still allowed as it isn't ambiguous.
2015-01-24 22:28:14 +09:00
FUJIWARA Katsunori
9720a2fb81 vfs: add dirname 2015-07-10 00:59:51 +09:00
FUJIWARA Katsunori
d6dd33482c vfs: add basename 2015-07-10 00:59:51 +09:00
Yuya Nishihara
0ce55c7cf2 changeset_printer: use node.wdirrev to calculate meaningful parentrevs
Because we defined the working-directory revision is INT_MAX, it makes sense
that "hg log -r 'wdir()'" displays the "parent:" field. This is the same for
two revisions that are semantically contiguous but the intermediate revisions
are hidden.
2015-07-02 22:03:06 +09: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
Gregory Szorc
3aa1c73868 global: mass rewrite to use modern octal syntax
Python 2.6 introduced a new octal syntax: "0oXXX", replacing "0XXX". The
old syntax is not recognized in Python 3 and will result in a parse
error.

Mass rewrite all instances of the old octal syntax to the new syntax.

This patch was generated by `2to3 -f numliterals -w -n .` and the diff
was selectively recorded to exclude changes to "<N>l" syntax conversion,
which will be handled separately.
2015-06-23 22:30:33 -07:00
Pierre-Yves David
40147b2819 devel-warn: move the develwarn function as a method of the ui object
We are going to use this feature in more and more place. Having to import
scmutil makes it an import cycle hell.
2015-06-19 11:19:45 -07:00
Matt Harbison
39e618db88 scmutil: add an optional parameter to matcher factories for a bad() override
Even though scmutil.matchandpats() is documented to warn about bad files,
several callers silence the warning.
2015-06-05 19:24:32 -04:00
Matt Harbison
9596aa8c5b scmutil: use the optional badfn argument when building a matcher 2015-06-05 19:07:54 -04:00
Matt Harbison
c0ea0f263e addremove: replace match.bad() monkey patching with match.badmatch()
No known issues with the previous code since it restored the original method,
but this is cleaner.
2015-06-04 21:25:07 -04:00
Matt Harbison
d7353508b0 scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Previously, if a subrepo was added in ctx2 and then compared to another without
it (ctx1), the subrepo for ctx2 was returned amongst all of the ctx1 based
subrepos, since no subrepo exists in ctx1 to replace it in the 'subpaths' dict.
The two callers of this, basectx.status() and cmdutil.diffordiffstat(), both
compare the yielded subrepo against ctx2, and thus saw no changes when ctx2's
subrepo was returned.  The tests here previously didn't mention 's/a' for the
'p1()' case.

This appears to have been a known issue, because some diffordiffstat() comments
mention that the subpath disappeared, and "the best we can do is ignore it".  I
originally ran into the issue with some custom convert code to flatten a tree of
subrepos causing hg.putcommit() to abort, but this new behavior seems like the
correct status and diff behavior regardless.  (The abort in convert isn't
something users will see, because convert doesn't currently support subrepos in
the official repo.)
2015-06-03 14:21:15 -04:00
Yuya Nishihara
d0b6a92234 revrange: build spanset from x:y range
This slightly improves the performance in the optimal case:

% hg log -R mozilla-central -r0:tip -l1 --time
(before)
time: real 0.050 secs (user 0.040+0.000 sys 0.010+0.000)
(after)
time: real 0.020 secs (user 0.000+0.000 sys 0.010+0.000)
2015-05-24 18:30:27 +09:00
Yuya Nishihara
6bf5f80705 revrange: build balanced tree of addsets from revisions (issue4565)
This reduces the stack depth from O(n) to O(log(n)). Therefore, repeated
-rREV options will never exceed the Python stack limit.

Currently it depends on private revset._combinesets() function. But at some
point, we'll be able to drop the old-style parser, and revrange() can be
completely rewritten without using _combinesets():

  trees = [parse(s) for s in revs]
  optimize(('or',) + trees)  # combine trees and optimize at once
  ...

Blockers that prevent eliminating old-style parser:

 - nullary ":" operator
 - revrange(repo, [intrev, ...]), can be mapped to 'rev(%d)' ?
 - revrange(repo, [binnode, ...]), should be banned ?
2015-05-24 18:11:33 +09:00
Yuya Nishihara
b37964ca55 revrange: clean up meaningless reconstruction of sets
They just exist for deduplication that was removed by the previous patch.
2015-05-24 17:59:55 +09:00
Yuya Nishihara
8807625c4d revrange: drop unnecessary deduplication of revisions
Because "l" is a smartset, duplicated entries are omitted by addsets.
2015-05-24 17:53:22 +09:00
Matt Harbison
9311abf92a match: resolve filesets in subrepos for commands given the '-S' argument
This will work for any command that creates its matcher via scmutil.match(), but
only the files command is tested here (both workingctx and basectx based tests).
The previous behavior was to completely ignore the files in the subrepo, even
though -S was given.

My first attempt was to teach context.walk() to optionally recurse, but once
that was in place and the complete file list was built up, the predicate test
would fail with 'path in nested repo' when a file in a subrepo was accessed
through the parent context.

There are two slightly surprising behaviors with this functionality.  First, any
path provided inside the fileset isn't narrowed when it is passed to the
subrepo.  I dont see any clean way to do that in the matcher.  Fortunately, the
'subrepo()' fileset is the only one to take a path.

The second surprise is that status predicates are resolved against the subrepo,
not the parent like 'hg status -S' is.  I don't see any way to fix that either,
given the path auditor error mentioned above.
2015-05-16 00:36:35 -04:00
Drew Gottlieb
ffaf3d5a36 requires: move requires file writing func from localrepo to scmutil
The logic to read a requires file resides in scmutil, so it's only logical that
the logic to write the file should be there too.

And now I've typed logic too many times it no longer looks like a word.
Logically.
2015-04-13 18:11:47 -04:00
Pierre-Yves David
3e542e8c99 devel-warn: add a prefix to all messages ("devel-warn: ")
We want to make the origin and importance of the message clear to developers.
2015-04-15 01:18:09 -04:00
Pierre-Yves David
23f376ba5d develwarn: include call site in the simple message version
Just displaying the warning makes it quite hard to recognise the guilty code
quickly and using --traceback for all calls is not very convenient. So we
include the call site with all simple message to help developer to recognise
errors sources.
2015-04-12 14:27:42 -04:00
Pierre-Yves David
ac5bf7b3e8 develwarn: handle the end of line inside the function itself
The traceback version should not have a end of line at all. The non-traceback
version will requires the same things soon.
2015-04-12 14:26:11 -04:00