Commit Graph

373 Commits

Author SHA1 Message Date
Mark Thomas
b1d366cb34 histedit: use new-style progress bars
Reviewed By: quark-zju

Differential Revision: D7329484

fbshipit-source-id: 038b8405a76aba4b4bc540c752beda6f1cfd4a4c
2018-04-13 21:51:33 -07:00
Jun Wu
f1c575a099 flake8: enable F821 check
Summary:
This check is useful and detects real errors (ex. fbconduit).  Unfortunately
`arc lint` will run it with both py2 and py3 so a lot of py2 builtins will
still be warned.

I didn't find a clean way to disable py3 check. So this diff tries to fix them.
For `xrange`, the change was done by a script:

```
import sys
import redbaron

headertypes = {'comment', 'endl', 'from_import', 'import', 'string',
               'assignment', 'atomtrailers'}

xrangefix = '''try:
    xrange(0)
except NameError:
    xrange = range

'''

def isxrange(x):
    try:
        return x[0].value == 'xrange'
    except Exception:
        return False

def main(argv):
    for i, path in enumerate(argv):
        print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
        content = open(path).read()
        try:
            red = redbaron.RedBaron(content)
        except Exception:
            print('  warning: failed to parse')
            continue
        hasxrange = red.find('atomtrailersnode', value=isxrange)
        hasxrangefix = 'xrange = range' in content
        if hasxrangefix or not hasxrange:
            print('  no need to change')
            continue

        # find a place to insert the compatibility  statement
        changed = False
        for node in red:
            if node.type in headertypes:
                continue
            # node.insert_before is an easier API, but it has bugs changing
            # other "finally" and "except" positions. So do the insert
            # manually.
            # # node.insert_before(xrangefix)
            line = node.absolute_bounding_box.top_left.line - 1
            lines = content.splitlines(1)
            content = ''.join(lines[:line]) + xrangefix + ''.join(lines[line:])
            changed = True
            break

        if changed:
            # "content" is faster than "red.dumps()"
            open(path, 'w').write(content)
            print('  updated')

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
```

For other py2 builtins that do not have a py3 equivalent, some `# noqa`
were added as a workaround for now.

Reviewed By: DurhamG

Differential Revision: D6934535

fbshipit-source-id: 546b62830af144bc8b46788d2e0fd00496838939
2018-04-13 21:51:09 -07:00
Jun Wu
2946a1c198 codemod: use single blank line
Summary: This makes test-check-code cleaner.

Reviewed By: ryanmce

Differential Revision: D6937934

fbshipit-source-id: 8f92bc32f75b9792ac67db77bb3a8756b37fa941
2018-04-13 21:51:08 -07:00
Phil Cohen
acc8749802 histedit: add ui.log for action count
Differential Revision: https://phab.mercurial-scm.org/D1751
2018-01-03 05:35:56 -08:00
Augie Fackler
96c1d16249 merge with stable 2017-12-14 16:01:28 -05:00
Boris Feld
18540b6753 histedit: preserve active branch while histediting
The branch information was properly preserved in the changeset, but the
"active" branch of the working copy could be lost (the branch of the base
being used).

Histedit used to behave properly in this regard but the case was not tested
and regressed 4 years ago in c038baa4b6f0.
2017-12-12 18:22:11 +01:00
Yuya Nishihara
9e02f75b4c registrar: host "dynamicdefault" constant by configitem object
This is the common pattern seen in the other registrar classes.
2017-10-21 13:13:20 +09:00
Martin von Zweigbergk
14dfe2a25c memfilectx: make changectx argument mandatory in constructor (API)
committablefilectx has three subclasses: workingfilectx, memfilectx,
and overlayfilectx. committablefilectx takes an optional (change) ctx
instance to its constructor. If it's provided, it's set on the
instance as self._changectx. If not, that property is supposed to be
defined by the class. However, only workingfilectx does that. The
other two will have the property undefined if it's not passed in the
constructor. That seems bad to me. This patch makes the changectx
argument to the memfilectx constructor mandatory because that fixes
the failure I ran into. It seems like we should also fix the
overlayfilectx case.

Differential Revision: https://phab.mercurial-scm.org/D1658
2017-12-11 09:27:40 -08:00
Pulkit Goyal
0b80228ebd histedit: add support to output nodechanges using formatter
The JSON output of nodechanges will help in automation and to improve editor
integrations such as for Nuclide.

Differential Revision: https://phab.mercurial-scm.org/D1348
2017-10-28 19:03:23 +05:30
Pulkit Goyal
efe36fbe83 py3: handle keyword arguments in hgext/histedit.py
Differential Revision: https://phab.mercurial-scm.org/D1318
2017-10-23 00:03:54 +05:30
Saurabh Singh
9332c7664f histedit: remove the nonexistant config 'histeditng'
D942 removed the experimental config 'histeditng'. This is a leftover
which should have been removed in that commit. Therefore, this commit completes
the cleanup.

Test Plan:
Ran all the tests.

Differential Revision: https://phab.mercurial-scm.org/D1123
2017-10-16 12:15:00 -07:00
Saurabh Singh
ffc1ad2f09 histedit: removing the experimental config 'histeditng'
This config has been around for about 2 years now. So, it can be
assumed to be stable. Therefore, I am removing the config. This also makes the
test 'test-histedit-base.t' compatible with chg.

Test Plan:
 - Ran the test 'test-histedit-base.t' with and without '--chg' option.
 - Ran all the other tests without '--chg' option.
 - Checked the output of 'hg help histedit'.

Differential Revision: https://phab.mercurial-scm.org/D942
2017-10-05 21:56:25 +00:00
Boris Feld
e2c066c1d2 configitems: register the 'experimental.histeditng' config 2017-06-30 03:41:23 +02:00
Boris Feld
c5961e53a9 configitems: register the 'experimental.histedit.autoverb' config 2017-06-30 03:41:19 +02:00
Boris Feld
3511ff1228 configitems: register the 'histedit.singletransaction' config 2017-06-30 03:42:40 +02:00
Boris Feld
232028d78c configitems: register the 'histedit.linelen' config 2017-06-30 03:42:39 +02:00
Boris Feld
320e358126 configitems: register the 'histedit.dropmissing' config 2017-06-30 03:42:38 +02:00
Boris Feld
c8792151c9 configitems: register the 'histedit.defaultrev' config 2017-06-30 03:42:37 +02: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
André Klitzing
fb861bea86 histedit: check first changeset for verb "roll" or "fold" (issue5498)
If someone changes "pick" to "roll" or "fold" for the first
changeset in a histedit rule Mercurial could remove a wrong
changeset if the phase is non-public.

roll or fold for the first changeset should be invalid.
2017-08-11 15:20:41 +02:00
Boris Feld
97880179f7 bookmark: use 'applychanges' when updating bookmark in histedit 2017-07-10 17:28:53 +02:00
Martin von Zweigbergk
cce08d0996 histedit: extract InterventionRequired transaction handling to utils
rebase will have similar logic, so let's extract it. Besides, it makes
the histedit code more readable.

We may want to parametrize acceptintervention() by the exception(s)
that should result in transaction close.

Differential Revision: https://phab.mercurial-scm.org/D66
2017-07-12 13:57:03 -07:00
Martin von Zweigbergk
7259b500cc histedit: create transaction outside of try
Just a little refactoring to simplify the next patch.

Differential Revision: https://phab.mercurial-scm.org/D65
2017-07-12 13:17:49 -07:00
Martin von Zweigbergk
018f2d955f histedit: remove transaction from state object
The transaction is only used within a single function, so no need to
store it on the state object.

Differential Revision: https://phab.mercurial-scm.org/D64
2017-07-12 11:18:02 -07:00
Jun Wu
ec32c2f725 histedit: use scmutil.cleanupnodes (BC)
This is marked as BC because the strip backup file name has changed.
2017-07-08 16:50:31 -07:00
Jun Wu
f9577750a4 histedit: unify strip backup files on success (BC)
Previously we wrote two different strip backup files on success. This patch
unifies them. It will make scmutil.cleanupnodes migration more smooth.
2017-07-08 16:50:31 -07:00
Jun Wu
94f02e40d4 histedit: pass multiple nodes to strip (BC)
Previously, histedit.cleanupnode pass root nodes one by one. Since
repair.strip takes multiple nodes and can handle them just fine, pass all
strip roots at once.

This is BC because the number of strip backup files may change from N to 1.
2017-07-08 16:50:31 -07:00
Jun Wu
491b12c96e histedit: remove "name" parameter from cleanupnode functions
The "name" parameter is not used any longer so let's remove it.
2017-07-08 16:50:31 -07:00
Jun Wu
83e4cd62fc histedit: remove "should strip" debug message
The debug message was not used anywhere. Removed it to make
scmutil.cleanupnodes migration easier to reason about.
2017-07-08 16:50:31 -07:00
Jun Wu
4019f12521 histedit: move topmost bookmark movement to a separate function
histedit treats topmost bookmark movement specially. The rest of the
bookmark movement could be handled by scmutil.cleanupnodes. So let's move
the special logic out to make the patch easier to review.
2017-07-08 16:47:25 -07:00
Jun Wu
e9417ea1fc histedit: remove moving bookmarks message on verbose (BC)
This is more consistent with other commands, like "commit -v" won't show
bookmark movement messages.

It will make migrating to scmutil.cleanupnodes easier.
2017-07-08 16:04:21 -07:00
Martin von Zweigbergk
2625447afc bundle: make applybundle() delegate v1 bundles to applybundle1() 2017-06-22 15:00:19 -07:00
Martin von Zweigbergk
eae1a1d9e5 bundle: add a applybundle1() method
This is one step towards removing a bunch of "if isinstance(gen,
unbundle20)" by treating bundle1 and bundle2 more similarly.

The name may sounds ironic for a method in the bundle2 module, but I
didn't think it was worth it yet to create a new 'bundle' module that
depends on the 'bundle2' module. Besides, we'll inline the method
again later.
2017-06-16 10:25:11 -07:00
Martin von Zweigbergk
560e5ce4f1 changegroup: let callers pass in transaction to apply() (API)
I think passing in the transaction makes it a little clearer and more
consistent with bundle2.
2017-06-15 22:46:38 -07:00
Martin von Zweigbergk
627dcaad4c bundle2: use "else" instead of checking condition again 2017-06-16 10:36:43 -07:00
Yuya Nishihara
3e663dde68 registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
2016-01-09 23:07:20 +09:00
Durham Goode
77dcefda06 obsolete: add operation metadata to rebase/amend/histedit obsmarkers
By recording what operation created the obsmarker, we can show very intuitive
messages to the user in various UIs. For instance, log output could have
messages like "Amended as XXX" to show why a commit is old and has an 'x' on it.

     @  ac28e3  durham
    /   First commit
   |
   | o  d4afe7 durham
   | |  Second commit
   | |
   | x  8e9a5d (Amended as ac28e3)  durham
   |/   First commit
   |
2017-05-09 16:29:31 -07:00
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
Siddharth Agarwal
163ca4866c histedit: make check for unresolved conflicts explicit (issue5545)
Previously, we'd rely on the implicit check that `localrepo.commit` did.
The problem is that that check only happened when the working copy was
dirty. With a "clean" working copy but unresolved conflicts we'd get
into a broken state.

To fix that, do what rebase does and check for unresolved conflicts at
the start of histedit --continue.
2017-04-20 17:18:08 -07:00
Pierre-Yves David
26848e81da histedit: backout changeset 33e44341bb82
Before 33e44341bb82, histedit (like rebase) was only creating markers on final
success from the old-rewritten node to the newly created nodes (as of before
33e44341bb82). In case of abort the aborted attempt were stripped to restore the
repository in its state prior to the attempt.

This use of strip was on purpose. Using markers in this case introduces various
issues. The main one is that keeping the partial result of histedit as obsolete
prevents us to recreates the same nodes in a second attempt. The same operation
will lead to an identical results, using an identical node that already exists
in the repository as obsolete.

To conclude, we cannot and should not switch to obsolescence markers creation on
histedit --abort and we backout 33e44341bb82. A test to catch this class of
issue will be introduced in the next changeset.
2017-03-26 15:46:09 +02:00
Pierre-Yves David
28c534388d histedit: backout changeset bcd3d9060a3a
Its parent is about to be backedout so this one needs to be removed too.
2017-03-26 15:34:39 +02:00
Jun Wu
43b73290d8 histedit: inline cleanupnode
Move "cleanupnode" (unsafe strip) into "safecleanupnode" so it's impossible
to call the unsafe function directly.

This helps reduce future programming errors.
2017-03-13 22:30:07 -07:00
Jun Wu
9a92b85a6b histedit: use safecleanupnode in _aborthistedit (issue5500)
Now nobody in histedit calls the unsafe cleanupnode directly.
2017-03-13 22:22:18 -07:00
Jun Wu
a31c040564 histedit: use safecleanupnode in _finishhistedit
This simplifies code a lot.
2017-03-13 22:19:06 -07:00
Jun Wu
6525da3ca6 histedit: add a method to cleanup nodes safely
The new method will decide between:

  - cleanupnode, which calls the unsafe repair.strip
  - create obsmarkers

Ideally, nobody calls "cleanupnode" directly except for "safecleanupnode".
2017-03-13 21:10:45 -07:00
Durham Goode
6373006050 histedit: add histedit.singletransaction config option
This adds an option (which defaults to False) to run entire histedits in a
single transaction. This results in 20-25% faster histedits in large repos where
transaction startup cost is expensive.

I didn't want to enable this by default because it has some unfortunate side
effects. For instance, if a pretxncommit hook throws midway through the
histedit, it will rollback the entire histedit and lose any progress the user
had made. Same if the user aborts editting a commit message. It's still worth
turning this on for large repos, but probably not for normal sized repos.

Long term, once we have inmemory merging, we could do the entire histedit in
memory, without a transaction, then we could selectively rollback just parts of
it in the event of an exception.

Tested it by running the tests with
`--extra-config-opt=histedit.singletransaction=True`. The only failure was
related to the hook rollback issue I mention above.
2017-03-10 15:52:29 -08:00
Durham Goode
3b715e3357 histedit: pop action after the action is completed
We only want to pop the action after the action is completed, since if the
action aborts part way through we want it to remain at the front of the list so
continue/abort will start with it.

Previously we relied on the fact that we only serialized the state file at the
beginning of the action, so the pop wasn't serialized until the next iteration
of the loop. In a future patch we will be adding a large transaction around this
area, which means if we pop the list early it might get serialized if the action
throws a user InterventionRequired error, at which point the action is not in
the list anymore. So let's only pop it once the action is really truly done.
2017-03-10 15:43:31 -08:00
Durham Goode
6cd32520b1 histedit: add transaction support to writing the state file
This will be used in a future diff to enable a single transaction around an
entire histedit.
2017-03-10 15:43:31 -08:00
Jun Wu
d49afd55dd histedit: get rid of ui.backupconfig 2017-03-16 14:36:35 -07:00
Pierre-Yves David
a1d4a95c88 histedit: directly use repo.vfs.join
The 'repo.join' method is about to be deprecated.
2017-03-08 16:51:43 -08:00