Commit Graph

237 Commits

Author SHA1 Message Date
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
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
Pierre-Yves David
d3e735bffe develwarn: refactor the developer warning logic
The logic is currently duplicated and we plan to make it a bit smarter. So we
move it into a function first to make the update more robust and simple.
2015-04-12 14:24:28 -04:00
FUJIWARA Katsunori
57690add3e vfs: add walk
To eliminate "path prefix" (= "the root of vfs") part from "dirpath"
yielded by "os.walk()" correctly, "path prefix" should have "os.sep"
at the end of own string, but it isn't easy to ensure it, because:

  - examination by "path.endswith(os.sep)" isn't portable

    Some problematic encodings use 0x5c (= "os.sep" on Windows) as the
    tail byte of some multi-byte characters.

  - "os.path.join(path, '')" isn't portable

    With Python 2.7.9, this invocation doesn't add "os.sep" at the end
    of UNC path (see issue4557 for detail).

Python 2.7.9 changed also behavior of "os.path.normpath()" (see *) and
"os.path.splitdrive()" for UNC path.

    vfs root        normpath       splitdrive          os.sep required
    =============== ============== =================== ============
    z:\             z:\            z: + \              no
    z:\foo          z:\foo         z: + \foo           yes
    z:\foo\         z:\foo         z: + \foo           yes

    [before Python 2.7.9]
    \\foo\bar       \\foo\bar      '' + \\foo\bar      yes
    \\foo\bar\      \\foo\bar  (*) '' + \\foo\bar      yes
    \\foo\bar\baz   \\foo\bar\baz  '' + \\foo\bar\baz  yes
    \\foo\bar\baz\  \\foo\bar\baz  '' + \\foo\bar\baz  yes

    [Python 2.7.9]
    \\foo\bar       \\foo\bar      \\foo\bar + ''      yes
    \\foo\bar\      \\foo\bar\ (*) \\foo\bar + \       no
    \\foo\bar\baz   \\foo\bar\baz  \\foo\bar + \baz    yes
    \\foo\bar\baz\  \\foo\bar\baz  \\foo\bar + \baz    yes

If it is ensured that "normpath()"-ed vfs root is passed to
"splitdrive()", adding "os.sep" is required only when "path" part of
"splitdrive()" result isn't "os.sep" itself. This is just what
"pathutil.nameasprefix()" examines.

This patch applies "os.path.normpath()" on "self.join(None)"
explicitly, because it isn't ensured that vfs root is already
normalized: vfs itself is constructed with "realpath=False" (= avoid
normalizing in "vfs.__init__()") in many code paths.

This normalization should be much cheaper than subsequent file I/O for
directory traversal.
2015-04-11 23:00:04 +09:00
Gregory Szorc
5b06fcaa29 repoview: move function for computing filtered hash
An upcoming patch will establish per-filter tags caches. We'll want
to use the same cache validation logic as the branch cache. Prepare
for that by moving the logic for computing a filtered view hash
to somewhere central.
2015-04-01 18:43:29 -07:00
FUJIWARA Katsunori
798e1be41f vfs: add removedirs 2015-04-11 00:47:09 +09:00
FUJIWARA Katsunori
51fdbd9c2a vfs: add rmtree
This duplicates "onerror()" function from "svnsubrepo.remove()" for
equivalence of replacing in subsequent patch.

This "onerror()" function for "shutil.rmtree()" was introduced by
094a056562e7, which avoids failure of removing svn repository on
Windows.
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
Matt Harbison
34c91242f1 vfs: make it possible to pass multiple path elements to join
os.path.join(), localrepo.join() and localrepo.wjoin() allow passing multiple
path elements; vfs.join() should be as convenient.
2015-04-04 17:19:16 -04:00
Yuya Nishihara
2d0b41ce60 scmutil: add function to help handling workingctx in arithmetic operation
It's unfortunate that workingctx revision is None, which doesn't work well in
arithmetic operation or comparison. This function is trivial but will be used
in several places.
2015-03-14 19:38:59 +09:00
Martin von Zweigbergk
ca1a27676b matcher: make e.g. 'relpath:.' lead to fast paths
Several commands take the fast path when match.always() is
true. However, when the user passes "." on the command line, that
results in a matcher for which match.always() == False. Let's make it
so such matchers return True, and have an empty list of .files(). This
makes e.g. "hg log ." as fast as "hg log" and "hg revert ." as fast as
"hg revert --all" (when run from repo root).
2014-11-19 15:56:58 -08:00
Matt Harbison
978de44356 scmutil: replace 'ctx._repo' with 'ctx.repo()' 2015-03-12 23:16:26 -04:00
Jordi Gutiérrez Hermoso
ed917f2095 revrange: don't parse revset aliases as hash prefixes (issue4553)
If a user has a revsetalias defined, it is their explicit wish for
this alias to be parsed as a revset and nothing else. Although the
case of the alias being short enough and only contain the letters a-f
is probably kind of rare, it may still happen.
2015-02-25 18:12:01 -05:00
Yuya Nishihara
25fac1a15b revset: make match function initiate query from full set by default
This change is intended to avoid exposing the implementation detail to
callers. I'm going to extend fullreposet to support "null" revision, so
these mfunc calls will have to use fullreposet() instead of spanset().
2015-02-02 22:21:07 +09:00
Matt Harbison
21ca967140 narrowmatcher: propagate the rel() method
The full path is propagated to the original match object since this is often
used directly for printing a file name to the user.  This is cleaner than
requiring each caller to join the prefix with the file name prior to calling it,
and will lead to not having to pass the prefix around separately.  It is also
consistent with the bad() and abs() methods in terms of the required input.  The
uipath() method now inherits this path building property.

There is no visible change in path style for rel() because it ultimately calls
util.pathto(), which returns an os.sep based path.  (The previous os.path.join()
was violating the documented usage of util.pathto(), that its third parameter be
'/' separated.)  The doctest needed to be normalized to '/' separators to avoid
test differences on Windows, now that a full path is returned for a short
filename.

The test changes are to drop globs that are no longer necessary when printing an
absolute file in a subrepo, as returned from match.uipath().  Previously when
os.path.join() was used to add the prefix, the absolute path to a file in a
subrepo was printed with a mix of '/' and '\'.  The absolute path for a file not
in a subrepo, as returned from match.uipath(), is still purely '/' based.
2014-11-27 10:16:56 -05:00
Pierre-Yves David
8985258968 vfs: add a 'split' method
This method has the same behavior as the 'os.path.split' function, but having
it in vfs will allow handling of tricky encoding situations in the future.

In the same patch, we replace the use of 'os.path.split' in the transaction code.
2014-12-15 13:32:34 -08:00
Pierre-Yves David
329429e77c vfs: add a 'reljoin' function for joining relative paths
The vfs.join method only works for absolute paths. We need something
that works for relative paths too when transforming filenames. Since
os.path.join may misbehave in tricky encoding situations, encapsulate
the new join method in our vfs abstraction. The default implementation
remains os.path.join, but this opens the door to other VFSes doing
something more intelligent based on their needs.

In the same go, we replace the usage of 'os.path.join' in transaction code.
2014-12-15 13:27:46 -08:00
Matt Harbison
a7a84e8adc addremove: support addremove with explicit paths in subrepos
Git and svn subrepos are currently not supported.
2014-11-09 23:46:25 -05:00