( )⚙ D51 undo: bare bones undo without tests

This is an archive of the discontinued Mercurial Phabricator instance.

undo: bare bones undo without tests
ClosedPublic

Authored by felixmerk on Jul 11 2017, 5:56 PM.
Tags
None
Subscribers

Details

Reviewers
quark
Group Reviewers
Restricted Project
Commits
rFBHGX11039bbf64f1: undo: bare bones undo without tests
Summary

Adds undo command that changes working copy parent, bookmarks and
visible draft commits to a previous repo state.

Diff Detail

Repository
rFBHGX Facebook Mercurial Extensions
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

quark added a reviewer: Restricted Project.Jul 11 2017, 10:03 PM
quark requested changes to this revision.
quark added a subscriber: quark.
quark added inline comments.
hgext3rd/undo.py
35–38

This is an easy mistake :-p, but:

Importing inhibit will expose its functions. But whether inhibit is enabled or not, whether its uisetup runs or not is not guaranteed. If it's disabled (so its uisetup doesn't run), its API won't work.

The correct way to do is to get the inhibit module from mercurial.extensions.find:

from mercurial import (
    extensions,
)


try:
    inhibit = extensions.find('inhibit')
except KeyError:
    raise error.Abort(_('undo requires inhibit to work properly'))
else:
    inhibit.revive ...
321

nit: remove the space before p.

334

repo is guaranteed not None by Mercurial command handling so this if can be removed.

341

Insert a blank line before this function.

353–360

While commands.bookmark works, it's a high level API for running commands. In extension code, it's better to avoid calling other commands. repo._bookmarks has __setitem__ and __delitem__ (see bookmarks.py) which fit better in this case. Also search for recordchange for how to make transaction aware of the bookmark change.

366

Similar to bookmarks, it's better to use lower level APIs since this is an hg extension. Things might be interesting are:

  • cmdutil.bailifchanged # abort if working copy is not clean
  • merge.update / hg.clean / hg.update / hg.updatetotally # low-level update functions
369–370

Nice use of existing revsets!

374

repo.changectx(r) could be just repo[r]. The latter is more common.

381–387

It is a bit strange that hidecommits only takes a single commit. And ui is not used in revealcommits.

They could be made consistent:

def hidecommits(repo, ctxs):
    ....

def revealcommits(repo, ctxs):
    ....

hidecommits(repo, repo.set(...))
revealcommits(repo, repo.set(...))
This revision now requires changes to proceed.Jul 11 2017, 10:03 PM
stash added a subscriber: stash.Jul 12 2017, 8:46 AM
stash added inline comments.
hgext3rd/undo.py
323

Nit 'at least'

felixmerk edited edge metadata.Jul 13 2017, 12:41 AM
felixmerk updated this revision to Diff 105.
felixmerk updated this revision to Diff 210.Jul 17 2017, 3:09 PM
quark requested changes to this revision.Jul 18 2017, 8:47 PM

Almost there.

hgext3rd/undo.py
353–357

nit: could be simplified repo._bookmarks.clear().

359

nit: could be simplified to if mark:

389–391

nit: need re-indent (press == in vim)

393–394

Since the revision to revive might be hidden, I think you might want unfiltered repo here.

nit: could be slightly simplified to ctxs = repo.unfiltered().set(rev) (ctxs is more common in hg codebase than contexts). scmutil.revrange is to resolve multiple revsets while there is just one single revset here.

This revision now requires changes to proceed.Jul 18 2017, 8:47 PM
felixmerk added inline comments.Jul 19 2017, 5:19 PM
hgext3rd/undo.py
393–394

The repo is unfiltered when this is called

felixmerk edited edge metadata.Jul 19 2017, 5:31 PM
felixmerk updated this revision to Diff 314.
quark accepted this revision.Jul 19 2017, 5:40 PM

I see that's line 340. Might worth a comment on _undoto saying it expects an unfiltered repo.

This revision is now accepted and ready to land.Jul 19 2017, 5:40 PM
felixmerk updated this revision to Diff 322.Jul 19 2017, 8:45 PM
This revision was automatically updated to reflect the committed changes.