Commit Graph

33860 Commits

Author SHA1 Message Date
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
Phil Cohen
2c5a4f03fb filemerge: add _workingpath
This reduces any reliance on `a`.

Differential Revision: https://phab.mercurial-scm.org/D401
2017-08-31 11:28:59 -07:00
Phil Cohen
7790af6f63 filemerge: move a util copy call to filectx.write
This way a future in-memory-merge context can intercept them.

Differential Revision: https://phab.mercurial-scm.org/D400
2017-08-31 11:28:59 -07:00
Phil Cohen
bea82440f1 filemerge: eliminate most uses of tempfiles
Emphasize that they're unused so we can more easily remove them later.

Differential Revision: https://phab.mercurial-scm.org/D399
2017-08-31 11:28:59 -07:00
Phil Cohen
ed389219ff filemerge: extract _maketemp and _makebackup
These functions will be modified by in-memory merge, so let's extract them first and add some comments.

This also shortens `_filemerge` a bit.

Differential Revision: https://phab.mercurial-scm.org/D388
2017-08-31 11:05:19 -07:00
Yuya Nishihara
9b22314380 encoding: check overflow while calculating size of JSON escape buffer
The minimum input size to exploit is ~682MB (= INT_MAX / len('\\u0000') * 2)
on 32bit system, which isn't easy to achieve using Python str in 2GB process
address space, but probably doable.
2017-08-31 21:56:40 +09:00
Michael Bolin
094c271fff editor: use an unambiguous path suffix for editor files
Changes the API of `ui.edit()` to take an optional `action` argument,
which is used when constructing the suffix of the temp file.
Previously, it was possible to set the suffix by specifying a `suffix` to the
optional `extra` dict that was passed to `ui.edit()`, but the goal is to
drop support for `extra.suffix` and make `action` a required argument.
To this end, `ui.edit()` now yields a `develwarn()` if `action` is not set
or if `extra.suffix` is set.

I updated all calls to `ui.edit()` I could find in `hg-crew` to specify the
appropriate `action`. This means that when creating a commit, instead
of the path to the editor file being something like:

`/tmp/hg-editor-XXXXXX.txt`

it is now something like:

`/tmp/hg-editor-XXXXXX.commit.hg.txt`

Some editors (such as Atom) make it possible to statically define a [TextMate]
grammar for files with a particular suffix. For example, because Git reliably
uses `.git/COMMIT_EDITMSG` and `.git/MERGE_MSG` as the paths for commit-type
messages, it is trivial to define a grammar that is applied when files of
either name are opened in Atom:

https://github.com/atom/language-git/blob/v0.19.1/grammars/git%20commit%20message.cson#L4-L5

Because Hg historically used a generic `.txt` suffix, it was much harder to
disambiguate whether a file was an arbitrary text file as opposed to one
created for the specific purpose of authoring an Hg commit message.

This also makes it easier to add special support for `histedit`, as it has its own
suffix that is distinct from a commit:

`/tmp/hg-histedit-XXXXXX.histedit.hg.txt`

Test Plan:
Added an integration test: `test-editor-filename.t`.

Manually tested: ran `hg ci --amend` for this change and saw that it
used `/tmp/hg-editor-ZZjcz0.commit.hg.txt` as the path instead of
`/tmp/hg-editor-ZZjcz0.txt` as the path.

Verified `make tests` passes.

Differential Revision: https://phab.mercurial-scm.org/D464
2017-08-30 20:25:56 +00:00
Martin von Zweigbergk
54312c2822 revlog: move check for wdir from changelog to revlog
Yuya said he preferred this (to keep them in one place, I think).

Differential Revision: https://phab.mercurial-scm.org/D569
2017-08-30 09:21:31 -07:00
Augie Fackler
58925444d0 revlog: use pycompat.bytestr() to reliably have a %s-able value 2017-08-22 21:21:43 -04:00
Augie Fackler
52fb3124b4 debugcommands: stabilize output of debugbundle by having a custom repr
We handle all dict-like things the same, and don't worry about it
actually being a repr.
2017-08-22 23:11:35 -04:00
Augie Fackler
e45ed2be45 python3: whitelist another 5 passing tests found with the ratchet script 2017-08-22 20:25:08 -04:00
Augie Fackler
48dbe73629 python3: replace sorted(<dict>.iterkeys()) with sorted(<dict>) 2017-08-22 20:06:58 -04:00
Augie Fackler
e2774d9258 python3: wrap all uses of <exception>.strerror with strtolocal
Our string literals are bytes, and we mostly want to %-format a
strerror into a one of those literals, so this fixes a ton of issues.
2017-08-22 20:03:07 -04:00
Jun Wu
bd039f3688 pager: do not start pager if ui has been pushbuffer-ed
The `pushbuffer`, `popbuffer` APIs are intended to capture internal output.
They will prevent `ui.write` from writing to the actual `ui.fout`. So a
pager won't receive the output and do the right thing. In general, it does
not make sense to start a pager if ui is in the "pushbuffer" mode.

Differential Revision: https://phab.mercurial-scm.org/D574
2017-08-30 14:04:55 -07:00
Jun Wu
4cd80fdd9c revset: do not flip "and" arguments when optimizing
Rewrite `flipand(y, x)` to `andsmally(x, y)` so the AST order is unchanged,
which could be more friendly to developers.

Differential Revision: https://phab.mercurial-scm.org/D579
2017-08-30 16:05:12 -07:00
Yuya Nishihara
507a4c9e22 revset: make match function follow given subset if specified (API)
This should be sensible default since mfunc(subset) is roughly equivalent
to 'subset & mfunc'. The order argument is still there so we can specify
'anyorder' if the order doesn't really matter.
2017-08-30 22:51:28 +09:00
Yuya Nishihara
abe6c88072 revset: move order argument to run-time match function
We no longer need the order flag to build a parsed tree.
2017-08-30 22:41:36 +09:00
Yuya Nishihara
389688d31e revset: fix example describing how ordering is determined
It was 'X & !Y' before.
2017-08-30 23:53:30 +09:00