Commit Graph

18630 Commits

Author SHA1 Message Date
Augie Fackler
11355eb015 dispatch: convert exception payload to bytes more carefully
We were previously depending on str() doing something reasonable here,
and we can't depend on the objects in question supporting __bytes__,
so we work around the lack of direct bytes formatting.
2017-05-28 15:47:00 -04:00
Augie Fackler
027f2454e7 help: convert flag default to bytes portably
We were relying on %s using repr on (for example) integer values. Work
around that for Python 3 while preserving all the prior magic.
2017-05-28 15:49:29 -04:00
Yuya Nishihara
f287cab367 cmdutil: use isstdiofilename() where appropriate 2017-06-01 23:08:23 +09:00
Yuya Nishihara
e2d98b5aa2 py3: simply use b'%d\n' to format pid in server.py
Spotted by Martin, thanks.
2017-06-01 23:05:29 +09:00
Yuya Nishihara
8840d7ead5 py3: implement __bytes__() on most of our exception classes
We store bytes in exc.args, which should be translated to a byte string
without encode/decode dance.

IOError subclasses are unchanged for now. We'll need to decide how our
IOErrors should be caught.
2017-06-01 22:43:24 +09:00
Yuya Nishihara
9e4fbd65c4 py3: convert __doc__ back to bytes in help.py
pycompat.getdoc() is pretty simple, but we wouldn't want to write handling
of None inline.
2017-06-01 22:24:15 +09:00
Pulkit Goyal
e95681a9cb py3: ensure that we don't concat bytes and str and the end result is bytes
Here obj.__module__ and obj.__name__ are str. Either we can convert them to
bytes or use an r'' and convert back to bytes when concat is done. I preferred
the later one since we are encoding only once here.
2017-06-01 01:41:34 +05:30
Pulkit Goyal
9d6a7aa555 py3: make sure we return strings from __str__ and __repr__
On Python 3:

>>> class abc:
...     def __repr__(self):
...             return b'abc'
...
>>> abc()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __repr__ returned non-string (type bytes)

>>> class abc:
...     def __str__(self):
...             return b'abc'
...
>>> str(abc())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __str__ returned non-string (type bytes)

So the __str__ and __repr__ must return strings.
2017-06-01 00:00:10 +05:30
Pulkit Goyal
4e870f314a py3: replace None with -1 to sort an integer array
In Python 2:

>>> ls = [4, 2, None]
>>> sorted(ls)
[None, 2, 4]

In Python 3:

>>> ls = [4, 2, None]
>>> sorted(ls)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < int()

Therefore we replaced None with -1, and the safe part is that, None and -1 are
only the keys which are used for sorting so we don't need to convert the -1's
back to None.
2017-05-31 23:48:52 +05:30
Pulkit Goyal
31c2497e4b py3: pass str in os.sysconf()
os.sysconf() doesn't accepts bytes on Python 3. Adding r'' will make
sure b'' is not added here.
2017-05-31 23:42:58 +05:30
Sean Farley
e94da1f6fd context: move dirty() to committablectx
This is a pedantic move. It should be an error if dirty() is called on a
read-only context. Based on Mads Kiilerix's and my work at the sprint.
2017-05-11 13:59:48 -07:00
Sean Farley
4eadbcd953 committablectx: extra is already normalized by committablectx.__init__
Avoid doing the same work again. Based on work done by Mads Kiilerix.
2017-05-11 13:51:10 -07:00
Siddharth Agarwal
9202c22f7c match: introduce nevermatcher for when no ignore files are present
c01965ab5195 introduced a deterministic `__repr__` for ignores. However, it
didn't account for when ignore was `util.never`. This broke fsmonitor's ignore
change detection -- with an empty hgignore, it would kick in all the time.

Introduce `nevermatcher` and switch to it. This neatly parallels
`alwaysmatcher`.
2017-06-01 00:40:52 -07:00
Pierre-Yves David
0b43826a5f obsolete: raise richer exception on unknown version
We raise a more precise subclass of Abort with details about the faulty
version.  This will be used to detect this case  and display some information
in debugbundle.
2017-05-25 16:50:23 +02:00
Martin von Zweigbergk
e8402531b3 hidden: remove unnecessary guard condition
The "if visible" guard is now pretty pointless, because the function
call it guards will do almost no work anyway when there are no visible
revisions.

We can also stop wrapping "visible" in a set since it just needs to be
an iterable now.
2017-05-30 13:16:32 -07:00
Martin von Zweigbergk
cf924ce951 hidden: subtract pinned revs from hidden earlier
The pinned revs are simply revisions that should not be hidden even if
hideablerevs() says that should. Let's make that clear by simply
setting "hidden = hideablerevs() - pinnedrevs()" early on.
2017-05-30 10:27:20 -07:00
Martin von Zweigbergk
92723c6001 hidden: make _revealancestors() reveal ancestors exclusively
I think this seems more expected. It also prepares for the next
commit.
2017-05-27 23:05:10 -07:00
Martin von Zweigbergk
b246ec6657 hidden: remove _consistencyblockers()
Roughly speaking, we currently do this to reveal hidden ancestors of
visible revisions:

 1. Iterate over all visible non-public revisions and see if they have
    hidden parents

 2. For each revision found in step (1) walk the chain of hidden
    commits and reveal it

We can simplify that by skipping step (1) and doing step (2) from all
visible non-public revisions instead.

This doesn't seem to have much impact on "perfvolatilesets".

Before:
! obsolete
! wall 0.004616 comb 0.000000 user 0.000000 sys 0.000000 (best of 570)
! visible
! wall 0.008235 comb 0.010000 user 0.010000 sys 0.000000 (best of 326)

After:
! obsolete
! wall 0.004727 comb 0.010000 user 0.010000 sys 0.000000 (best of 543)
! visible
! wall 0.008371 comb 0.000000 user 0.000000 sys 0.000000 (best of 324)
2017-05-27 22:55:19 -07:00
Martin von Zweigbergk
6d496b7350 hidden: pass revs to iterate into _consistencyblockers()
Instead of passing the domain into _consistencyblockers() and having
the function calculate the set of revisions to iterate over, let the
caller do it. This is just a minor refactoring to make future changes
simpler.
2017-05-27 22:43:37 -07:00
Martin von Zweigbergk
df6061b050 hidden: remove unnecessary 'domain' parameter from _revealancestors()
The function will stop searching as soon as it runs into a non-hidden
revision, so there is no need to restrict by the domain (of mutable
revisions) as well.

This doesn't seem to have much impact on "perfvolatilesets".

Before:
! obsolete
! wall 0.004903 comb 0.000000 user 0.000000 sys 0.000000 (best of 535)
! visible
! wall 0.008913 comb 0.010000 user 0.010000 sys 0.000000 (best of 300)

After:
! obsolete
! wall 0.004616 comb 0.000000 user 0.000000 sys 0.000000 (best of 570)
! visible
! wall 0.008235 comb 0.010000 user 0.010000 sys 0.000000 (best of 326)
2017-05-27 22:10:20 -07:00
Martin von Zweigbergk
985e29a449 hidden: change _domainancestors() to _revealancestors()
This change makes the function actually reveal the ancestors by
removing them from the hidden set. This prepares for further
simplification.

Note that the function will now only reveal contiguous chains of
hidden revisions, but that's fine because we always pass it an
immediate child of any revision that should be revealed (or the
revision itself).

This doesn't seem to have much impact on "perfvolatilesets".

Before:
! obsolete
! wall 0.004672 comb 0.010000 user 0.010000 sys 0.000000 (best of 590)
! visible
! wall 0.008936 comb 0.010000 user 0.010000 sys 0.000000 (best of 322)

After:
! obsolete
! wall 0.004903 comb 0.000000 user 0.000000 sys 0.000000 (best of 535)
! visible
! wall 0.008913 comb 0.010000 user 0.010000 sys 0.000000 (best of 300)
2017-05-27 21:17:06 -07:00
Martin von Zweigbergk
782a1185dc hidden: rename "revealedrevs" to "pinnedrevs" (API)
E.g. tags and bookmarks can reveal revisions that would otherwise be
hidden. A revision can also be revealed because one if its descendants
is visible. Let's use the term "pinned" for the former case
(bookmarks etc.).
2017-05-27 21:08:51 -07:00
Martin von Zweigbergk
5572c33d0e hidden: drop obsolete comment about cacheability
The cache was recently dropped, so I believe the comment is now obsolete.
2017-05-27 21:02:17 -07:00
Yuya Nishihara
eff4d5e967 cat: add formatter support
This is an example showing how formatter can handle the --output option.
git subrepo isn't supported for now.
2017-05-25 21:53:44 +09:00
Yuya Nishihara
4980841c12 cat: use with statement to close output file 2017-05-27 17:58:36 +09:00
Yuya Nishihara
de43565bcb cat: stop using makefileobj()
Prepares for porting to the formatter API. We won't be able to utilize the
abstraction provided by makefilename() because formatter must be instantiated
per file.
2017-05-25 21:43:09 +09:00
Yuya Nishihara
d310821175 formatter: add nullformatter
This can be used as a placeholder variable.
2017-05-27 17:44:26 +09:00
Yuya Nishihara
cccb0536a1 formatter: add helper to create a formatter optionally backed by file
To make things simple, openformatter() and maybereopen() have no support
for a plain object API. Callers must use the "with" statement.

Unlike cmdutil.makefileobj(), append mode ('ab') isn't supported by these
functions. This is because JSON output can't be simply concatenated. Perhaps
cmdutil.export() will have to build a {filename: [revs...]} map first and
write revs per file.
2017-05-27 17:40:18 +09:00
Yuya Nishihara
7c796bc384 formatter: add option to redirect output to file object
Commands like 'export' have --output=OUTFILESPEC option, so we need a way
to write formatter output optionally to a file.
2015-01-18 18:04:44 +09:00
Yuya Nishihara
877b7b1d1a help: pass commands module by argument
This removes import cycle.
2017-05-21 16:57:32 +09:00
Stanislau Hlebik
8513dd5f4b copies: introduce getdstfctx
Previously `c2` may had an incorrect linkrev because getsrcfctx set wrong
_descendantrev. getsrcfctx() sets descendant rev equals to srcctx.rev() (see
_makegetfctx()), but for `c2` descendant rev should be dstctx. While we were
lucky it didn't broke copytracing it made it significantly slower in some
cases. Besides it broke some external extensions, for example remotefilelog.
2017-05-29 06:06:13 -07:00
Stanislau Hlebik
52f5b22254 copies: rename getfctx to getsrcfctx
In the next patch we'll use getdstfctx. Let's rename getfctx to getsrcfctx in
this patch.
2017-05-29 05:58:08 -07:00
Stanislau Hlebik
789df611a1 copies: remove msrc and mdst parameters
This function already has lots of parameters. And we can get manifests from
contexts. So let's get msrc and mdst parameters from srcctx and dstctx.
2017-05-29 05:57:25 -07:00
Stanislau Hlebik
d7b30bb1f8 copies: add dstctx parameter
Add parameter with destination context
2017-05-29 05:57:03 -07:00
Stanislau Hlebik
92e5d5f67c copies: rename ctx to srcctx
In the next diff we'll pass new dstctx parameter. Let's rename ctx to srcctx in
this patch.
2017-05-29 05:56:17 -07:00
Stanislau Hlebik
aa25365b25 copies: rename m2 to mdst
Small refactoring to rename m2 to more clearer mdst.
2017-05-29 05:52:15 -07:00
Stanislau Hlebik
219c6a051d copies: rename m1 to msrc
Small refactoring that renames `m1` parameter name to a more clearer name
`msrc`.
2017-05-29 05:52:15 -07:00
Gregory Szorc
90a75c9c65 transaction: delete callbacks after use
Before this change, localrepository instances that performed multiple
transactions would leak transaction objects. This could occur when
running `hg convert`. When running `hg convert`, the leak would be
~90 MB per 10,000 changesets as measured with the Mercurial repo itself.

The leak I tracked down involved the "validate" closure from
localrepository.transaction(). It appeared to be keeping a
reference to the original transaction via __closure__. __del__
semantics and a circular reference involving the repo object
may have also come into play.

Attempting to refactor the "validate" closure proved to be
difficult because the "tr" reference in that closure may
reference an object that isn't created until transaction.__init__
is called. And the "validate" closure is passed as an argument to
transaction.__init__. Plus there is a giant warning comment in
"validate" about how hacky it is. I did not want to venture into
the dragon den.

Anyway, we've had problems with transactions causing leaks before.
The solution then (8b23c334b97f) is the same as the solution in this
patch: drop references to callbacks after they are called. This
not only breaks cycles in core Mercurial but can help break cycles
in extensions that accidentally introduce them.

While I only tracked down a leak due to self.validator, since this is
the 2nd time I've tracked down leaks due to transaction callbacks I
figure enough is enough and we should prevent the class of leak from
occurring regardless of the variable. That's why all callback variables
are now nuked.
2017-05-26 13:27:21 -07:00
Martin von Zweigbergk
a00e1e8b0a match: remove special-casing of always-matching patterns in patternmatcher
This moves the optimization for patterns that match everything to the
caller, so we can remove it from patternmatcher.

Note that we need to teach alwaysmatcher to use relative paths now in
cases like "hg files .." from inside mercurial/, because while it
still matches everything, paths should be printed relative to the
working directory.
2017-05-19 13:16:15 -07:00
Martin von Zweigbergk
40160c59ed match: move normalize() call out of matcher constructors
By passing in the result of the normalize() call, we prepare for
moving the special handling of patterns that always match out of the
patternmatcher.

It also lets us remove many of the arguments from the matcher, because
they were passed only the the normalize function (we could have
removed the arguments by binding them to the function instead of
moving the normalize() call out).
2017-05-19 12:47:45 -07:00
Martin von Zweigbergk
cc35e8cc47 match: drop support for empty pattern list in patternmatcher
Since the caller now deals with empty pattern lists, we can drop that
support in the patternmatcher. It now gets the more logical behavior
of matching nothing when no patterns are given (although there is no
in-core caller that will pass no patterns).
2017-05-19 11:58:16 -07:00
Martin von Zweigbergk
b0d04b4dc4 match: optimize visitdir() for when no explicit files are listed
In patternmatcher, we used to say that all directories should be
visited if no explicit files were listed, because the case of empty
_files usually implied that no patterns were given (which in turns
meant that everything should match). However, this made e.g. "hg files
-r .  rootfilesin:."  slower than necessary, because that also ended
up with an empty list in _files. Now that patternmatcher does not
handle includes, the only remaining case where its _files/_fileset
fields will be empty is when it's matching everything. We can
therefore treat the always-case specially and stop treating the empty
_files case specially. This makes the case mentioned above faster on
treemanifest repos.
2017-05-20 23:49:14 -07:00
Martin von Zweigbergk
57f17ff9f2 match: handle everything-matching using new alwaysmatcher
Having a special matcher that always matches seems to make more sense
than making one of the other matchers handle the case. For now, we
just use this new matcher when no patterns were provided.
2017-05-19 11:50:01 -07:00
Martin von Zweigbergk
e63330c2d2 match: add __repr__ for subdirmatcher
Should at least be useful for debugging. Would matter for correctness
too if fsmonitor or Facebook's sparse extension worked with subrepos
(which I don't know if they do).
2017-05-26 13:08:30 -07:00
Augie Fackler
47e0320f8b cleanup: rename all iteritems methods to items and add iteritems alias
Due to a quirk of our module importer setup on Python 3, all calls and
definitions of methods named iteritems() get rewritten at import
time. Unfortunately, this means there's not a good portable way to
access these methods from non-module-loader'ed code like our unit
tests. This change fixes that, which also unblocks test-manifest.py
from passing under Python 3.

We don't presently define any itervalues methods, or we'd need to give
those similar treatment.
2017-05-29 00:00:02 -04:00
Augie Fackler
4e659930fc help: work around textwrap.dedent() only working on strings 2017-05-28 15:51:07 -04:00
Augie Fackler
ac1808c4a0 server: write out pid using bytes IO instead of str IO 2017-05-28 15:43:06 -04:00
Augie Fackler
dad740cf16 help: convert dict to strkwargs 2017-05-28 13:28:41 -04:00
Augie Fackler
2f5077fef1 util: use sysstr.join instead of bytes.join in textwrap wrapper 2017-05-28 13:42:16 -04:00
Yuya Nishihara
477ffb0437 match: define exactmatcher.matchfn statically
This should eliminate the reference cycle, self.matchfn -> self.exact -> self.
2017-05-28 23:54:31 +09:00