Commit Graph

93 Commits

Author SHA1 Message Date
Lukasz Langa
dfda82e492 Upgrade to 18.5b1
Summary: Mostly empty lines removed and added.  A few bugfixes on excessive line splitting.

Reviewed By: quark-zju

Differential Revision: D8199128

fbshipit-source-id: 90c1616061bfd7cfbba0b75f03f89683340374d5
2018-05-30 02:23:58 -07:00
Jun Wu
584656dff3 codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).

Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.

Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.

An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.

As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.

Reviewed By: wez, phillco, simpkins, pkaush, singhsrb

Differential Revision: D8173629

fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-25 22:17:29 -07:00
Mark Thomas
dbf70dc3fd crecord: suspend progress bar when displaying the curses interface
Summary:
Nothing currently displays a progress bar while the curses interface is shown,
but in the future something may be added which does, so ensure the progress bar
is suspended when showing the curses interface.

Reviewed By: ryanmce

Differential Revision: D7417435

fbshipit-source-id: 6b91b17ee5390cbde6e983081a0940051ab865c8
2018-04-13 21:51:38 -07:00
Durham Goode
1f577c8417 hg: remove version check from crecord
Summary:
crecord locked out the amend functionality to older versions of
Mercurial. Since it's packaged in core now, let's always enable it.

Reviewed By: quark-zju

Differential Revision: D6837724

fbshipit-source-id: 2a0dae2e03346734f7d8298e5a073f776849005e
2018-04-13 21:50:59 -07:00
Jun Wu
41d35f0ba7 crecord: fix revert -ir '.^' crash caused by 3649c3f2cd
3649c3f2cd (revert: do not reverse hunks in interactive when REV is not
parent (issue5096)) changed the record "operation" for the text version but
missed the curses version. Without this patch, running
`hg revert -ir '.^' --config ui.interface=curses` would crash with:

  ProgrammingError: unexpected operation: apply

Differential Revision: https://phab.mercurial-scm.org/D1381
2017-11-13 18:22:25 -08: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
Peter Vitt
0725932203 record: make the m key open an editor for the commit message (issue5667)
With the former crecord extension, the user could edit the commit
message while he was de-/selecting hunks. By pressing 'm', an editor
showed up to edit the commit message.

With record being part of mercurial, this feature is not available
anymore. However, the help text still mentions it.

As the infrastructure needed is still present, this feature is quite
easily ported from the crecord extension to mercurial.

It seems there is no test coverage for record ui, so I tested this patch
manually on my local machine.
2017-08-28 13:43:31 +02:00
Filip Filmar
5ff93579e2 crecord: fixes the formatting of the select status in the status line
The status line in the crecord has the "space" status field which has variable
length depending on the length of the status label in the language of choice.
In English, the status labels are "space: deselect" and "space:select".  The
"deselect" label is 2 glyphs longer.  This makes the terminal output jump
around if the terminal width is just right so that the shorter label makes
the status line 1 line long, and the longer label makes it 2 lines long.

This patch formats the selected status into a fixed-width field.  The field
width is the maximum of the lengths of the two possible labels, to account for
differing translations and label lengths.  This should make the label behavior
uniform across localizations.

There does not seem to be a test for crecord, so I verified the change manually
with a local build of 'hg'.
2017-08-13 00:17:13 -07:00
Jun Wu
5e22630fbf patch: rewrite reversehunks (issue5337)
The old reversehunks code accesses "crecord.uihunk._hunk", which is the raw
recordhunk without crecord selection information, therefore "revert -i"
cannot revert individual lines, aka. issue5337.

The patch rewrites related logic to return the right reverse hunk for
revert. Namely,

 1. "fromline" and "toline" are correctly swapped [1]
 2. crecord.uihunk generates a correct reverse hunk [2]

Besides, reversehunks(hunks) will no longer modify its input "hunks", which
is more expected.

[1]: To explain why "fromline" and "toline" need to be swapped, take the
     following example:

  $ cat > a <<EOF
  > 1
  > 2
  > 3
  > 4
  > EOF

  $ cat > b <<EOF
  > 2
  > 3
  > 5
  > EOF

  $ diff a b
  1d0   <---- "1" is "fromline" and "0" is "toline"
  < 1         and they are swapped if diff from the reversed direction
  4c3             |
  < 4             |
  ---             |
  > 5             |
                  |
  $ diff b a      |
  0a1   <---------+
  > 1
  3c4   <---- also "4c3" gets swapped to "3c4"
  < 5
  ---
  > 4

[2]: This is a bit tricky.

For example, given a file which is empty in working parent but has 3 lines
in working copy, and the user selection:

    select hunk to discard
    [x] +1
    [ ] +2
    [x] +3

The user intent is to drop "1" and "3" in working copy but keep "2", so the
reverse patch would be something like:

        -1
         2 (2 is a "context line")
        -3

We cannot just take all selected lines and swap "-" and "+", which will be:

        -1
        -3

That patch won't apply because of "2". So the correct way is to insert "2"
as a "context line" by inserting it first then deleting it:

        -2
        +2

Therefore, the correct revert patch is:

        -1
        -2
        +2
        -3

It could be reordered to look more like a common diff hunk:

        -1
        -2
        -3
        +2

Note: It's possible to return multiple hunks so there won't be lines like
"-2", "+2". But the current implementation is much simpler.

For deletions, like the working parent has "1\n2\n3\n" and it was changed to
empty in working copy:

    select hunk to discard
    [x] -1
    [ ] -2
    [x] -3

The user intent is to drop the deletion of 1 and 3 (in other words, keep
those lines), but still delete "2".

The reverse patch is meant to be applied to working copy which is empty.
So the patch would be:

        +1
        +3

That is to say, there is no need to special handle the unselected "2" like
the above insertion case.
2017-06-20 23:22:38 -07:00
Pierre-Yves David
010d017cdd crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)
Windows do not have a SIGTSTP so we avoid setting the handler if the signal is
unknown.
2017-04-06 11:28:25 +02:00
Pierre-Yves David
5a12bd8592 crecord: ensure we reinstall the SIGTSTP handler
Previous, exceptions would prevent the reinstallation of the
signal.
2017-04-06 11:25:13 +02:00
Pierre-Yves David
6ab2d25fb5 crecord: avoid setting non-existing signal SIGWINCH on windows
Windows do not have a SIGWINCH so we avoid setting the handler if the signal is
unknown.
2017-04-06 11:25:33 +02:00
Pierre-Yves David
75f4f604c1 crecord: ensure we reinstall the SIGWINCH handler
Previous, exception in _main(...) would prevent the reinstallation of the
signal.
2017-03-26 15:06:09 +02:00
Pierre-Yves David
83f005a5e4 crecord: extract most of 'main' into a sub function
There are some setup and cleanup necessary around the main code, that
setup/cleanup code needs multiple adjustments so we extract the core code into
its own function first for clarity.
2017-03-26 15:05:12 +02:00
Jun Wu
6b0a252616 crecord: use ProgrammingError 2017-03-26 17:00:23 -07:00
Simon Farnsworth
3897de8633 crecord: log blocked time waiting for curses input
We want to know when we're blocked waiting for the user - log the time spent
waiting in the curses keyboard handlers
2017-02-15 13:34:06 -08:00
Anton Shestakov
9427025e13 crecord: add an experimental option for space key to move cursor down
I really want to have an option of toggling a selection on a line and also
moving cursor down as a single keystroke. It also kinda makes sense for space
key to do this, because some other curses UIs in the wild do this (e.g. various
file managers, htop). So I got an idea to make a config option that defaults to
False for compatibility, but allows making crecord UI a lot more useful for
people with big hunks.

We add this an experimental option to experiment with this behavior.
2017-01-08 10:08:29 +08:00
Jun Wu
b1b31fa46d crecord: change the verb according to the operation
This will make crecord consistent with record when being used in the revert
situation. It will say "Select hunks to revert / discard" accordingly.

This should make the revert crecord interface less confusing.
2016-11-28 23:38:46 +00:00
Jun Wu
221bb95fba crecord: change help text for the space key dynamically
A follow-up of the previous patch, to make the text simple and clear about
whether it's to "select" or "deselect".
2016-11-28 23:37:29 +00:00
Jun Wu
45c2358700 crecord: rewrite status line text (BC)
Previously, we display fixed text in the 2-line status header. Now we want
to customize some word there to make the "revert" action clear. However, if
we simply replace the verb using '%s' like this:

  "SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; "
  "(space/A) toggle hunk/all; (e)dit hunk;"),
  " (f)old/unfold; (c)onfirm %s; (q)uit; (?) help " % verb
  "| [X]=hunk %s **=folded, toggle [a]mend mode" % verb

It could cause trouble for i18n - some languages may expect things like
"%(verb) confirm", for example.

Therefore, this patch chooses to break the hard-coded 2-line sentences into
"segment"s which could be translated (and replaced) separately.

With the clean-up, I'm also changing the content being displayed, to make it
cleaner and more friendly to (new) users, namely:

  - Replace "SELECT CHUNKS" to "Select hunks to record". Because:
    - To eliminate "hunk" / "chunk" inconsistency.
    - "record" is used in the "text" UI. Do not use "apply", to make it
      consistent.
    - To make it clear you are choosing what to record, not revert, or
      discard etc. This is probably the most important information the user
      should know. So let's put it first.
    - "to record" could be replaced to others depending on the operation.
      The follow-up patches will address them.
  - Move "[x]" and "**" legends first to explain the current interface. New
    users should understand what the legends mean, followed by what they can
    do in the interface.
  - Replace "j/k/up/dn/pgup/pgdn" with "arrow keys". Because:
    - "arrow keys" is more friendly to new users.
    - Mentioning "j/k" first may make emacs users angry. We should stay
      neutral about editors.
    - "pgup/pgdn" actually don't work very well. For example, within a hunk
      of 100-line insertion, "pgdn" just moves one single line.
    - Left/Right arrow keys are useful for movement and discovery of
      "expanding" a block.
  - Replace "fold/unfold" with "collapse/expand", "fold" is well known as
    a different meaning in histedit and evolve.
  - Replace "(space/A) toggle hunk/all" to "space: select". Because:
    - "A: toggle all" is not that useful
    - It's unclear how "hunk" could be "toggled" to a dumb user. Let's
      make it clear it's all about "select".
    - A follow-up will make it use "unselect" when we know the current item
      is selected.
  - Remove "(f)old". Use arrow keys instead.
  - Remove "toggle [a]mend mode". It's just confusing and could be useless.
  - Remove "(e)dit hunk". It's powerful but not friendly to new users.
  - Replace "(q)uit" to "q: abort" to make it clear you will lose changes.

The result looks like the following in a 73-char-width terminal:

  Select hunks to record - [x]=selected **=collapsed  c: confirm  q: abort
  arrow keys: move/expand/collapse  space: select  ?: help

If the terminal is 132-char wide, the text could fit in a single line.
2016-11-28 23:33:02 +00:00
Jun Wu
de6eda0ab8 crecord: make _getstatuslines update numstatuslines
We are going to make the text in the status window dynamically generated,
so its size would be dynamic. Change getstatuslines to update
"numstatuslines" automatically. Fix an issue where "numstatuslines" being 1
makes the chunkpad disappear.
2016-11-23 22:23:15 +00:00
Jun Wu
d59361019f crecord: move status window text calculation to a separate method
We will do some changes there in the next patches. The new method would also
be the "source of truth" of the content of the status window (so if the
status window needs more than 2 lines, it would be calculated from the new
method).

Also, moved "statuswin.refresh" to make the code compact and easier to read.
2016-11-28 23:12:54 +00:00
Jun Wu
955aa56bff crecord: filter text via i18n
There are some text in the user interface that are not filtered by i18n.
This patch adds the missing "_" call. So the text could be translated.
2016-11-23 18:13:11 +00:00
Jun Wu
7363c8226f crecord: add an "operation" field
The field would provide extra information to help us to make the curses UI
text less confusing.
2016-11-23 19:22:36 +00:00
Mads Kiilerich
38cb771268 spelling: fixes of non-dictionary words 2016-10-17 23:16:55 +02:00
Yuya Nishihara
f9eda5312c crecord: use scmutil.termsize() 2016-10-20 23:16:32 +09:00
Nathan Goldbaum
d4f7f32622 crecord: add an event that scrolls the selected line to the top of the screen
Using ctrl-l for this purpose seems to be a fairly widely used practice,
presumably following emacs. This doesn't scroll the selected line all
the way to the top of the window, instead it leaves a 3 line buffer for
context. Use curses.unctrl() to resolve keypressed to '^L' to avoid
hard-coding hexadecimal key codes.
2016-09-20 10:03:50 -05:00
Nathan Goldbaum
4554f03267 crecord: delete commented line 2016-09-14 11:39:47 -05:00
Pierre-Yves David
5bcff70a60 merge with stable 2016-09-14 17:12:39 +02:00
timeless
aa2c0ad5a3 crecord: properly handle files with No newline at eof (issue5268)
Yes, this bug was a single character with the wrong case...
2016-09-02 20:15:37 +00:00
Denis Laxalde
e785df5b6d crecord: drop unused "operation" parameter from filterpatch function 2016-06-07 11:57:11 +02:00
Anton Shestakov
98e687e2c1 crecord: call prevsibling() and nextsibling() directly
The 3 classes for items used in crecord (uiheader, uihunk, uihunkline) all have
prevsibling() and nextsibling() methods. The two methods are used to get the
previous/next item of the same type of the same parent element as the current
one: when `a` is a uihunkline instance, a.nextsibling() returns the next line
in this hunk (or None, if `a` is the last line).

There are also two similar methods: previtem() and nextitem(). When called with
constrainlevel=True (the default) they simply returned the result of
prevsibling()/nextsibling(). Only when called with constrainlevel=False they
did something different: they returned previous/next item regardless of its
type (so if `a` is the last line in a hunk, a.nextitem(constrainlevel=False)
could return the next hunk or the next file -- something that is not a line).

Let's simplify this logic and make code call -sibling() methods when only
siblings are needed and -item() methods when any item would do, and then remove
the constrainlevel argument from previtem() and nextitem().
2016-05-06 19:52:21 +08:00
Anton Shestakov
2114fb5a2b crecord: update downarrowshiftevent() docstring, remove todo
The phrasing is mostly taken from uparrowshiftevent().
2016-05-05 19:51:35 +08:00
Anton Shestakov
5e327181ec crecord: remove things that don't happen in functions from their docstrings
Scrolling screen is currently done in a different place. The things that had
been described in the docstrings may still happen, but the functions touched by
this patch don't do any scrolling, they only set self.currentselecteditem and
nothing more.
2016-05-05 19:40:40 +08:00
Anton Shestakov
5e74474fd5 crecord: remove skipfolded keyword argument from patchnode.previtem()
It wasn't used, it wasn't implemented. Probably was a copy-paste bonus from
patchnode.nextitem()
2016-05-05 18:13:25 +08:00
Anton Shestakov
abe8039328 crecord: update a copy-pasted comment in downarrowshiftevent() 2016-05-05 15:19:37 +08:00
Pierre-Yves David
1df58e3451 crecord: drop the version condition for amend
The UI is now shipped in core, amend feature is always available.
2016-05-05 16:38:24 +02:00
Anton Shestakov
2a1482cb0e crecord: add/remove blank lines (coding style) 2016-05-05 11:19:52 +08:00
Jun Wu
7957528e61 crecord: restore SIGWINCH handler before return
Previously, the SIGWINCH handler does not get cleared and if the commit
message editor also needs SIGWINCH handling (like vim), the two SIGWINCH
handlers (the editor's, ours) will have a race. And we may erase the
editor's screen content.

This patch restores SIGWINCH handler to address the above issue.
2016-08-24 11:24:07 +01:00
Pulkit Goyal
d6e3ff1be2 py3: use unicode literals in crecord.py 2016-08-04 00:21:14 +05:30
Pierre-Yves David
8727b619f9 crecord: cleanup the remains of commit confirmation
The confirmation screen is now only used for the 'review' option we simplify
the code and rename the function.
2016-04-14 01:37:29 -07:00
Pierre-Yves David
cfee396b5b crecord: drop the extra confirmation screen
The commit confirmation is not very useful -- it gives no way to view what you
have selected, so you're blindly choosing whether to proceed or not, and it adds
a lot of unnecessary friction to committing. In addition, we now have a working
'review' choice for those who really want to review the final change.

Ryan McElroy initially submitted a config option to make this optional, but we
never saw a V2. However as the freeze is near and curses have never been
officially out of the door, I think it is worth skipping the config and trying
getting it right for this release.
2016-04-14 01:27:18 -07:00
timeless
f77cdcd3b1 pycompat: switch to util.stringio for py3 compat 2016-04-10 20:55:37 +00:00
Jordi Gutiérrez Hermoso
52cc18f78c crecord: re-enable reviewing a patch before comitting it
The "r" option for this feature was copied into Mercurial from
crecord, but the actual implementation never made it into hg until
now. It's a moderately useful feature that allows the user to edit the
patch in a text editor before comitting it for good.

This requires a test, so we must also enable a corresponding testing
'R' option that skips the confirmation dialogue. In addition, we also
need a help text for the editor when reviewing the final patch.

As for why this is a useful feature if we can already edit hunks in an
editor, I would like to offer the following points:

    * editing hunks does not show the entire patch all at once

      ** furthermore, the hunk "tree" in the TUI has no root that could be
         selected for edition

    * it is helpful to be able to see the entire final patch for
      confirmation

      ** within this view, the unselected hunks are hidden, which is
         visusally cleaner

      ** this works as a final review of the complete result, which is
         a bit more difficult to do conceptually via hunk editing

    * this feature was already in crecord, so it was an oversight to
      not bring it to core

    * it works and is consistent with editing hunks
2016-03-20 21:08:17 -04:00
Jordi Gutiérrez Hermoso
6e38da078e crecord: break out the help message for editing hunks
This help message can be useful for other situations, such as for the
review extension. It's also easier to write it at the top-level
indentation with triple-quoted strings instead of inserting comment
characters and newlines programmatically.
2016-03-20 18:24:59 -04:00
Jordi Gutiérrez Hermoso
e86f12d3c1 crecord: refactor hunk edit action to use ui.edit
The previous version of this code did a lot of dancing around a
temporary edit file that ui.edit already handles.
2016-03-20 20:59:05 -04:00
Ryan McElroy
27da9f85d4 crecord: add docblock to handlekeypressed
This information is pretty useful when reading the code.
2016-03-18 11:06:03 -07:00
Ryan McElroy
06ec8dec0a crecord: fix docblock indentation 2016-03-18 11:06:03 -07:00
Ryan McElroy
f48f34f0f0 crecord: clean up empty lines at ends of docblocks 2016-03-18 11:06:03 -07:00
Simon Farnsworth
4f9fc754b3 crecord: use ui.interface to choose curses interface
use ui.interface to select curses mode, instead of experimental.crecord
2016-03-14 15:01:27 +00:00