This is an archive of the discontinued Mercurial Phabricator instance.

undo: add --index and redo support to preview
ClosedPublic

Authored by felixmerk on Aug 1 2017, 8:04 PM.
Tags
None
Subscribers

Details

Reviewers
stash
quark
Group Reviewers
Restricted Project
Commits
rFBHGXfc0806ff0c3d: undo: add --index and redo support to preview
Summary

Adds --index handling for --preview. With the added handling, preview also
works for redo. In order to bypass template logic, we simply change the
"undoredo.i" file and reset it afterwards.

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

felixmerk created this revision.Aug 1 2017, 8:04 PM
Herald added a reviewer: Restricted Project. · View Herald TranscriptAug 1 2017, 8:04 PM

Again, see screenshot for what this currently looks like in practice

stash requested changes to this revision.Aug 2 2017, 5:34 AM
stash added a subscriber: stash.

Can you add tests please?

hgext3rd/undo.py
209–212

BTW, why do you need a tr? It's not used

901

Technically it's _undoredopreview(...) :).
So maybe just rename to _preview(...)?

908–915

I'm confused. What part of code will read this fake index, why do we need to overwrite it?

917

Does it make sense to put in in

try:
   ...
finally:
  _logundoredoindex(repo, repo.currenttransaction(), savedindex)

?

This revision now requires changes to proceed.Aug 2 2017, 5:34 AM

Not exactly sure how to test color output in the .t files, but I'll try to come up with some more indirect tests.

hgext3rd/undo.py
209–212

Good catch. This used to be necessary but isn't anymore.

908–915

The template code that shows commits and bookmarks that will disappear as red doesn't really know where we are undoing to. Its much easier to simply change the undoredo index than to pass the index we are undoing to through the template logic.

917

Yes, that would be better

Other than this mess:

hg log -Gr "olddraft(1) + olddraft(0)" -T "{label(sl_label, separate('\n', separate('  ', separate(' ', label('sl.oldbook', '{if(undoneco    mmits, shortest(undonecommits, 6))}'), label('sl.book', '{label('sl.book', '{if(donecommits, shortest(donecommits, 6))}')}')), sl_user, sl_di    ff, separate(' ', label('sl.book', oldbookmarks), label('sl.oldbook', removedbookmarks))), '{sl_desc}', '\n'))}"

Which I added in the previous diff, I'm not sure how to write tests for this. The output is facebook.rc dependent, and running log with a complex template isn't maintainable, nor can it test undo -p with --index.

felixmerk edited edge metadata.Aug 2 2017, 4:38 PM
felixmerk updated this revision to Diff 511.
quark requested changes to this revision.Aug 4 2017, 1:44 PM
quark added a subscriber: quark.

Putting this back to your queue. This will likely be changed with D206's change.

This revision now requires changes to proceed.Aug 4 2017, 1:44 PM
felixmerk edited edge metadata.Aug 7 2017, 3:32 PM
felixmerk updated this revision to Diff 610.
stash accepted this revision.Aug 8 2017, 5:00 AM
stash added inline comments.
hgext3rd/undo.py
377

Not related to this diff, but olddraft doesn't read undolog/redonode, and so hg undo && hg log -r 'draft()' is different from hg log -r 'olddraft(1). Am I right? If yes, then can you please make it clear in the comment?

920–926

This logic about rewriting indices definitely requires a good comment explaining what is going on.
I'd prefer to add a new field to the repo object if there are no other way of passing parameter to the template

929–933

Why are you catching IndexError?

936

No need for return

felixmerk added inline comments.Aug 8 2017, 1:20 PM
hgext3rd/undo.py
377

You are correct. hg undo --absolute && hg log -r 'draft()' would be the same. Generally draft() and olddraft() have also an important nuanced difference in terms of hidden commits. olddraft(0) --hidden is no different from olddraft(0) which isn't the same for draft(). I'll improve the documentation.

929–933

An out of bounds state being blank in preview makes sense. We could also print something out. If we ask preview, "what would happen if I undo here?" the response shouldn't be "index out of bounds for preview", it should be: "index will be out of bounds for undo." A blank repo state represents that clearly enough to the user without making them have to think about what indexes are. "Its a blank state, I don't want to go there" is in my opinion good from a UX side.

quark accepted this revision.Aug 9 2017, 7:29 PM
This revision is now accepted and ready to land.Aug 9 2017, 7:29 PM
felixmerk updated this revision to Diff 721.Aug 9 2017, 7:52 PM
felixmerk edited edge metadata.Aug 9 2017, 7:52 PM
felixmerk requested review of this revision.
felixmerk updated this revision to Diff 739.Aug 10 2017, 1:55 PM
quark accepted this revision.Aug 11 2017, 9:02 PM
This revision is now accepted and ready to land.Aug 11 2017, 9:02 PM
This revision was automatically updated to reflect the committed changes.