Commit Graph

33827 Commits

Author SHA1 Message Date
Jun Wu
5533f78606 checknlink: rename file object from 'fd' to 'fp'
Make it clear that `fp` (`file` object) is different from `fd` (low-level
file descriptor number).

Differential Revision: https://phab.mercurial-scm.org/D642
2017-09-06 12:56:19 -07:00
Martin von Zweigbergk
cb8b36b8aa cleanup: rename "matchfn" to "match" where obviously a matcher
We usually call matchers either "match" or "m" and reserve "matchfn"
for functions.

Differential Revision: https://phab.mercurial-scm.org/D641
2017-09-05 15:06:45 -07:00
Martin von Zweigbergk
78fb62643c check-code: fix incorrect capitalization in camelcase regex
This was found internally at Google as part of a monorepo-wide
cleanup.

Differential Revision: https://phab.mercurial-scm.org/D637
2017-09-06 08:22:54 -07:00
Martin von Zweigbergk
e34765d999 amend: use context manager for config override
Differential Revision: https://phab.mercurial-scm.org/D639
2017-09-06 10:41:13 -07:00
Martin von Zweigbergk
f238d550cd amend: delete dead assignment to "newid"
Differential Revision: https://phab.mercurial-scm.org/D638
2017-09-06 10:42:02 -07:00
Jun Wu
b6ac2e259f checknlink: use a random temp file name for checking
Previously, if `.hg/store/00manifest.d.hgtmp1` exists, hg will copy the
entire `00manifest.d` every time when appending new manifest revisions.
That could happen if Mercurial or the machine crashed when `.hgtmp1` was
just created but not deleted yet.

This patch changes the fixed name to a random generated name. To be
consistent with D468, `~` suffix was used.

Differential Revision: https://phab.mercurial-scm.org/D611
2017-09-01 17:09:53 -07:00
Pulkit Goyal
b8929368f2 copytrace: move the default copytracing algorithm in a new function
We are going to introduce a new fast heuristic based copytracing algorithm, so
lets make mergecopies the function which decides which algorithm to go with and
then calls the related function.

While I was here, I add a line in test-copy-move-merge.t saying its a test
related to the full copytracing algorithm.

Differential Revision: https://phab.mercurial-scm.org/D622
2017-09-03 02:34:01 +05:30
Pulkit Goyal
59fe14130c copytrace: replace experimental.disablecopytrace config with copytrace (BC)
This patch replaces experimental.disablecopytrace with experimental.copytrace.
Since the words does not means the same, the default value is also changed. Now
experimental.copytrace defaults to 'on'. The new value is not boolean value as
we will be now having two different algorithms (current one and heuristics one
to be imported from fbext) so we need this to be have more options than
booleans.

The old config option is not kept is completely replaced as that was under
experimental and we don't gurantee BC to experimental things.

.. bc::

   The config option for copytrace `experimental.disablecopytrace` is now
   replaced with `experimental.copytrace` which defaults to `on`. If you need to
   turn off copytracing, add `[experimental] copytrace = off` to your config.

Differential Revision: https://phab.mercurial-scm.org/D621
2017-09-03 01:52:19 +05:30
Phil Cohen
6320e90d1b filemerge: use fctx.write() in the internal:dump tool, instead of copy
This is slower but allows this tool to work with the "deferred writes"
milestone of in-memory merge.

The performance hit is not too noticiable since this only used for the :dump
merge tool during a conflict.

Differential Revision: https://phab.mercurial-scm.org/D617
2017-09-05 12:04:02 -07:00
Martin von Zweigbergk
7bcdc77ac9 largefiles: remove unused assignments from wrapfunction()
The return values from wrapfunction() were never used here. Using the
value is also a little tricky and wrappedfunction() should be
preferred, so let's just delete the assignments.

There's also a bunch of return values from wrapcommand() being
assigned to a variable here, but at least that value can be (and is
used after some of the assignments).

Differential Revision: https://phab.mercurial-scm.org/D618
2017-08-31 22:39:10 -07:00
the31k
27daecb480 branches: correctly show inactive multiheaded branches
Issue being fixed here: `hg branches` incorrectly renders inactive multiheaded
branches as active if they have closed heads.

Example:

```
$ hg log --template '{rev}:{node|short} "{desc}" ({branch}) [parents: {parents}]\n'
4:2e2fa7af8357 "merge" (default) [parents: 0:c94e548c8c7d 3:7be622ae5832 ]
3:7be622ae5832 "2" (somebranch) [parents: 1:81c1d9458987 ]
2:be82cf30409c "close" (somebranch) [parents: ]
1:81c1d9458987 "1" (somebranch) [parents: ]
0:c94e548c8c7d "initial" (default) [parents: ]

$ hg branches
default                        4:2e2fa7af8357
somebranch                     3:7be622ae5832
```

Branch `somebranch` have two heads, the 1st one being closed (rev 2) and
the other one being merged into default (rev 3). This branch should be shown as
inactive one.

This happens because we intersect branch heads with repo heads to check branch
activity. In this case intersection in a set with one node (rev 2). This head
is closed but the branch is marked as active nevertheless.

Fix is to check branch activity by intersecting only open heads set.

Fixed output:

```
$ hg branches
default                        4:2e2fa7af8357
somebranch                     3:7be622ae5832 (inactive)
```

Relevant tests for multihead branches added to test-branches suite.

Implentation note about adding `iteropen` method:

At first I have tried to modify `iterbranches` is such a way that it would
filter out closed heads itself. For example it could have `closed=False`
parameter. But in this case we would have to filter closed tips as well.
Reasoning in terms of `hg branches` we actually are not allowed to do this.

Also, we need to do heads filtering only if tip is not closed itself. But if it
is - we are ok to skip filtering, because branch is already known to be inactive.

So we can't implement heads filtering in `iterbranches` in elegant way, because
we will end up with something like `closed_heads=False` or even
`closed_heads_is_tip_is_open`. Finally I decided to move this logic to the
`branches` function, adding `iteropen` helper method.

Differential Revision: https://phab.mercurial-scm.org/D583
2017-08-31 18:24:08 +03:00
Yuya Nishihara
f0fc1531a4 parser: stabilize output of prettyformat() by using byte-safe repr()
The format of leaf nodes is slightly changed so they look more similar to
internal nodes.
2017-09-03 21:17:25 +09:00
Yuya Nishihara
2142d803e8 py3: fix repr(util.url) to return system string
This is required on Python 3.
2017-09-03 17:51:23 +09:00
Yuya Nishihara
84faf498bc py3: use bytes[n:n + 1] to get bytes in templater._parsetemplate() 2017-09-03 17:37:17 +09:00
Yuya Nishihara
c05be6158c py3: fix type of attribute name in smartset.py 2017-09-03 17:14:53 +09:00
Yuya Nishihara
6567bed4cb py3: fix mixed bytes/unicode in revsetlang._aliassyminitletters 2017-09-03 17:03:23 +09:00
Yuya Nishihara
a406b0a270 py3: fix type of regex literals in subrepo.py 2017-09-03 15:01:23 +09:00
Yuya Nishihara
70990906a5 py3: replace bytes[n] with bytes[n:n + 1] in patch.py where needed 2017-09-03 16:19:20 +09:00
Yuya Nishihara
02f6cbfc54 py3: fix type of regex literals in patch.py 2017-09-03 16:12:15 +09:00
Jun Wu
eaaeecf0d5 revset: optimize "draft() & ::x" pattern
The `draft() & ::x` type query could be common for selecting one or more
draft feature branches being worked on.

Before this patch, `::x` may travel through the changelog DAG for a long
distance until it gets a smaller revision number than `min(draft())`. It
could be very slow on long changelog with distant (in terms of revision
numbers) drafts.

This patch adds a fast path for this situation, and will stop traveling the
changelog DAG once `::x` hits a non-draft revision.

The fast path also works for `secret()` and `not public()`.

To measure the performance difference, I used drawdag to create a repo that
emulates distant drafts:

          DRAFT4
           |
          DRAFT3 # draft
          /
  PUBLIC9999 # public
      |
  PUBLIC9998
      |
      .   DRAFT2
      .    |
      .   DRAFT1 # draft
      |   /
  PUBLIC0001 # public

And measured the performance using the repo:

  (BEFORE)
  $ hg perfrevset 'draft() & ::(DRAFT2+DRAFT4)'
  ! wall 0.017132 comb 0.010000 user 0.010000 sys 0.000000 (best of 156)
  $ hg perfrevset 'draft() & ::(all())'
  ! wall 0.024221 comb 0.030000 user 0.030000 sys 0.000000 (best of 113)
  (AFTER)
  $ hg perfrevset 'draft() & ::(DRAFT2+DRAFT4)'
  ! wall 0.000243 comb 0.000000 user 0.000000 sys 0.000000 (best of 9303)
  $ hg perfrevset 'draft() & ::(all())'
  ! wall 0.004319 comb 0.000000 user 0.000000 sys 0.000000 (best of 655)

Differential Revision: https://phab.mercurial-scm.org/D441
2017-08-28 14:49:00 -07:00
Jun Wu
8909822786 phabricator: add a config to use curl for communication
Not sure why, but I got `phabsend` hang on work network pretty frequently.
The traceback indicates it hangs at `_sslobj.do_handshake()`:

  File "mercurial/sslutil.py", line 404, in wrapsocket
    sslsocket = sslcontext.wrap_socket(sock, server_hostname=serverhostname)
  File "/usr/lib/python2.7/ssl.py", line 363, in wrap_socket
    _context=self)
  File "/usr/lib/python2.7/ssl.py", line 611, in __init__
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 840, in do_handshake
    self._sslobj.do_handshake()

I had tried adding `timeout` in various places but they seem not effective.
It seems easier to just allow shelling out to `curl` with retry and timeout
flags.

This could also be helpful for people with an older Python installed without
modern security (SNI).

Differential Revision: https://phab.mercurial-scm.org/D605
2017-09-01 12:13:17 -07:00
Jun Wu
70db4ce38e phabricator: standardize colors
Previously, the `--confirm` text could have colors but the main `phabsend`
does not. This patch adjusts the main command so it also has colors.
A default color table was added so the colors are visible by default.

Differential Revision: https://phab.mercurial-scm.org/D515
2017-08-24 18:00:23 -07:00
Kyle Lippincott
8cf1a22c40 wireproto: do not abort after successful lookup
As far as I can tell, this interface originally used 'return' here, so the
"fallthrough" to self._abort made sense. When it was switched to 'yield' this
didn't make sense, but doesn't impact most uses because the 'plain' wrapper in
peer.py's 'batchable' decorator only attempts to yield two items (args and
value).

When using iterbatch, however, it attempts to verify that the @batchable
generators only emit 2 results, by expecting a StopIteration when attempting to
access a third.

Differential Revision: https://phab.mercurial-scm.org/D608
2017-09-01 14:00:13 -07:00
Jun Wu
ada59ccd75 check-code: forbid "\S" in egrep regular expression
BSD `egrep` does not like it. So let's forbid it.

Differential Revision: https://phab.mercurial-scm.org/D610
2017-09-01 16:44:30 -07:00
Jun Wu
e4fdb2e534 check-code: forbid using bash in shebang
Some platforms (ex. FreeBSD) do not have `bash` by default. Therefore it
should not be used in test scripts.

Differential Revision: https://phab.mercurial-scm.org/D609
2017-09-01 15:47:32 -07:00
Saurabh Singh
e92757d9ec amend: add tests for amending only some files from commit to be amended
We do not have robust enough tests for scenarios where only some files in a
changeset are amended. This presents an interesting scenario because the
working copy could have modified versions of the remaining files in the
pre-amend changeset. Therefore, I have added some tests to ensure that amend
behaves as expected in these scenarios.

Test Plan:
Ensured that the test "test-commit-amend.t" passes.

Differential Revision: https://phab.mercurial-scm.org/D596
2017-09-01 12:34:34 -07:00
Yuya Nishihara
b2ddf3cabe test-editor-filename: fix portability of fake editor command
- /bin/bash doesn't exist on FreeBSD
 - edit is executed by cmd.exe on Windows
2017-09-02 21:49:45 +09:00
Saurabh Singh
d84d216df1 amend: moving first assignment of newid closer to its use
newid was needlessly further away from where its intended to be used
leading to bad readability. This commit moves it to address the same. The end
goal is to remove the redundant commit in the amend code path and this commit
takes care of cleaning up some unrelated code before that change.

Test Plan:
ran the test suite

Differential Revision: https://phab.mercurial-scm.org/D597
2017-09-01 12:34:36 -07:00
Saurabh Singh
27a654fdd5 amend: rectify comment
Comment was ambiguous as there can be two parents of a changeset in mercurial.
This commit fixes the comment to clarify that the first parent is being
considered.

Test Plan:
ran the test suite

Differential Revision: https://phab.mercurial-scm.org/D595
2017-08-31 18:35:39 -07:00
Saurabh Singh
2e3d37be51 amend: removing redundant if condition
There is needless checking for the new commit hash not being equal to
the old commit hash. This condition will always be true at this point in the
code path and thus, can be removed safely. This commit removes the redundant
condition.

Test Plan:
ran the test suite.

Differential Revision: https://phab.mercurial-scm.org/D594
2017-09-01 15:08:54 -07:00
Michael Bolin
16648b82d6 editor: file created for diff action should have .diff suffix
This is a follow-up to https://phab.mercurial-scm.org/D464 (02b917f3e672) that
introduced the new file extension behavior. It erroneously changed `.diff` to
`.diff.hg.txt`.

Test Plan:
Verified `make tests` passes, particularly `test-editor-filename.t`.

Differential Revision: https://phab.mercurial-scm.org/D607
2017-09-01 20:28:26 +00:00
Jun Wu
286e29a1f9 test-amend: match output using conditional test case name
D466 (c5eb1c6ddc0a) allows output to be conditionally matched by test name.
This patch changes test-amend.t to use that feature, instead of duplicating
`hg amend` command or use `-q` to silence its output.

Differential Revision: https://phab.mercurial-scm.org/D601
2017-09-01 11:13:55 -07:00
Gregory Szorc
7db45deab1 util: use set for reserved Windows filenames
Previously, we were performing membership testing against a
list. Change it to a set for a minor perf win. While we're at it,
explode the assignment in place so less work is needed at module
import time.

Differential Revision: https://phab.mercurial-scm.org/D600
2017-08-31 19:40:15 -07:00
Phil Cohen
28052d0586 context: add arbitraryfilectx, which can represent files outside the workdir
Move it from contrib/simplemerge so it can be re-used in the future.

Differential Revision: https://phab.mercurial-scm.org/D604
2017-09-01 11:52:20 -07:00
Phil Cohen
62cb8c7754 simplemerge: remove unused filtereddata parameter
Differential Revision: https://phab.mercurial-scm.org/D603
2017-09-01 10:35:43 -07:00
Phil Cohen
5b0c47fbe3 simplemerge: remove unused repo parameter
This is now no longer used or needed thanks to the `decodeddata()` context
function.

Differential Revision: https://phab.mercurial-scm.org/D602
2017-09-01 10:35:43 -07:00
Christophe de Vienne
87902af734 extensions: prohibit unicode defaults
If the default value of an option is a unicode string (something
than happen easily when using a 'from __future__ import unicode_literals'),
any value passed on the command line will be ignored because the fancyopts
module only checks for byte strings and not unicode strings.

Changing fancyopts behavior is easy but would make assumptions on how
the python3 port should be done, which is outside the scope of this patch.

The chosen approach is to stop an extension from being loaded when a unicode
default value is detected, with a hint for the developer.
2017-08-29 18:24:51 +02:00
Yuya Nishihara
6d9809531d revsetlang: remove unused functions
Superseded by the _match() function.
2017-08-19 22:04:03 +09:00
Yuya Nishihara
48edce65ce revsetlang: match tree by helper function on optimize
This should make optimize() more readable and less error-prone, but it doubles
the parsing cost.

  (original)
  $ python -m timeit -n10000 -s 'from mercurial import revsetlang as L' \
  'L.optimize(L.analyze(L.parse("ancestors(x) and not ancestors(y)")))'
  10000 loops, best of 3: 79.3 usec per loop

  (this patch)
  $ python -m timeit -n10000 -s 'from mercurial import revsetlang as L' \
  'L._treecache.clear(); \
   L.optimize(L.analyze(L.parse("ancestors(x) and not ancestors(y)")))'
  10000 loops, best of 3: 201 usec per loop
2016-02-17 21:40:59 +09:00
Yuya Nishihara
27c162ca6b parser: add helper function to test if pattern matches parsed tree
This function will be used as follows:

  match('ancestors(_) and not ancestors(_)', x)

See the next patch for details.
2016-02-17 21:31:09 +09:00
Yuya Nishihara
63d5f35621 revsetlang: build optimized tree by helper function
This should make optimize() more readable, but it doubles the parsing cost.

  (original)
  $ python -m timeit -n10000 -s 'from mercurial import revsetlang as L' \
  'L.optimize(L.analyze(L.parse("::tip")))'
  10000 loops, best of 3: 18.1 usec per loop

  (this patch)
  $ python -m timeit -n10000 -s 'from mercurial import revsetlang as L' \
  'L._treecache.clear(); L.optimize(L.analyze(L.parse("::tip")))'
  10000 loops, best of 3: 48.4 usec per loop

30usec isn't dominant compared to the revset evaluation, but that is a cost.
That's why a parsed tree is cached, which can benefit in hgweb or chg server.
2016-02-17 21:38:25 +09:00
Yuya Nishihara
ee31d80d0f parser: add helper function that constructs parsed tree from template
This function will be used as follows:

  build('only(_, _)', x, y)

See the next patch for details.
2016-02-17 21:30:04 +09:00
Pulkit Goyal
5caf86603b patch: take messages out of the function so that extensions can add entries
Extensions will want to have interactive thing for more operations or
particulary want to show more verbs. So this patch takes out the message thing
from the function so that extensions can add verbs to this. The curses one is
also not in any function so extensions can add more actions and verbs there.

Differential Revision: https://phab.mercurial-scm.org/D567
2017-08-30 18:19:14 +05:30
Jun Wu
0886c75e25 run-tests: allow bisecting a different repo
Add `--bisect-repo` flag which accepts a different repo to bisect.

3rd party extensions may reuse `run-tests.py` from core to run tests. Test
failure could be caused by either a core hg change or the 3rd party
extension code itself. Having a way to specify which repo to bisect is
useful.

Differential Revision: https://phab.mercurial-scm.org/D578
2017-08-02 21:24:29 -07:00
Jun Wu
0f38c6c170 run-tests: extract prefix of bisect commands to a variable
This does not change any logic.

Differential Revision: https://phab.mercurial-scm.org/D577
2017-08-02 21:01:38 -07:00
Jun Wu
5b27abd5aa run-tests: pass --with-hg to run-tests.py command used by bisect
This makes `run-tests.py -l test-run-tests.t` 23 seconds faster on my
laptop. Inside the test, `$ rt --known-good-rev=0 test-bisect.t` took 24.9
seconds before, and 1.2 seconds after.

Differential Revision: https://phab.mercurial-scm.org/D576
2017-08-02 21:01:38 -07:00
Jun Wu
56e365cc2f import-checker: allow relative import a module being checked
This would make the checker more friendly for 3rd-party code. For example,

In remotefilelog/x.py, it may have:

    from . import shallowutils

That could trigger "relative import of stdlib module" if
"remotefilelog" was installed in the system. If the module being checked
conflicts with the system module, it makes sense to not treat that module as
system module. This patch makes it so.

Differential Revision: https://phab.mercurial-scm.org/D552
2017-08-28 13:43:25 -07:00
Phil Cohen
630437a97b merge: move some of the logic in batchget() to workingfilectx
We will use this logic in two places with in-memory merge.

Differential Revision: https://phab.mercurial-scm.org/D444
2017-08-31 11:28:59 -07:00
Phil Cohen
f42b3c5264 filemerge: add _restorebackup
Differential Revision: https://phab.mercurial-scm.org/D404
2017-08-31 11:28:59 -07:00
Phil Cohen
347cf25043 filemerge: reduce creation of tempfiles until needed
This restricts the creation of temporary files to just `_xmerge`, when we call
an external tool.

Differential Revision: https://phab.mercurial-scm.org/D403
2017-08-31 11:28:59 -07:00