This is an archive of the discontinued Mercurial Phabricator instance.

undo: basic --preview
ClosedPublic

Authored by felixmerk on Aug 1 2017, 6:46 PM.
Tags
None
Subscribers

Details

Reviewers
stash
quark
Group Reviewers
Restricted Project
Commits
rFBHGX883372ac2468: undo: basic --preview
Summary

Allows for hg undo --preview to see smartlog like preview of what undo will do.
This will be neccesery before a general roll-out so users can see what undo will
do. This first iteration only shows what "hg undo" will do, not redo and not
--index.

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, 6:46 PM
Herald added a reviewer: Restricted Project. · View Herald TranscriptAug 1 2017, 6:46 PM

See screen shot for what it actually looks like.

stash added subscribers: quark, stash.Aug 3 2017, 6:27 AM
stash requested changes to this revision.

So in current implementation hg undo -p prints combined smartlog output of current state and state after undo, right?
I imagined that hg undo --preview would just show only state after undo, but your approach seems better.

As for the tests:
I've added

> [templatealias]
> undopreview = '{if(undonecommits, "Undone")}'
> EOF

to the $HGRCPATH and then ran

  $ hg undo -p 

+  @  Undone
+  |
+  o
+  |
+  o
+  |
+  o
+  |
+  o
+  |
+  | o
+  |/
+  o
+  |
+  o
+  |
+  | o
+  |/
+  o
+  |
+  o
+

So this is basically what you've already done but with actually testing hg undo -p, not hg log.
Using this you can test all of your templates.

hgext3rd/undo.py
446–447

BTW, in https://phab.mercurial-scm.org/D184 @quark suggested to use 'if{revset...}' instead of templates. Have you considered it? I'm not saying this is necessarily better, just want to make sure you've considered this option too.

This revision now requires changes to proceed.Aug 3 2017, 6:27 AM

Thats a creative way to test this. Awesome, thank you!

hgext3rd/undo.py
446–447

That seems like a cool approach. I hadn't considered it, I'll look into what the pros and cons are.

quark requested changes to this revision.EditedAug 3 2017, 3:19 PM

I think undo --preview should not depend on smartlog. So users do not need smartlog enabled to use undo preview.

hg smartlog is basically (although there are some minor differences):

hg log -G -T '{sl}' -r 'ancestor(master, draft())+draft()'

What we need here are:

  • a revset selecting commits to show
  • a template to beautify the output

Thinking about external users, the best practice is to make the above config options (ex. undo.preview.revset, undo.preview.template) and provide a minimal default.

We can define local (only available in undo command) revsets (see 4672db164) like UNDODEL, UNDOADD which contains commits to hide and unhide. A default undo.preview.revset could be UNDODEL + UNDOADD + ancestor(UNDODEL+UNDOADD). Internally we can customize it so it also includes remote/master.

The template could be something like {if(revset("{rev} and UNDODEL"), "-")}{if(revset("{rev} and UNDOADD"), "+")} {node|shortest} {author|emailuser} {desc|firstline} {bookmarks...}. It does not need to have colors. Internally we can customize it to fit the smartlog style.

hgext3rd/undo.py
416

This has issues:

  • repo is mutable so the cache is not guaranteed to be always correct
  • repo object will not be freed because it gets reference by this decorator
905

This is a no-op. You might want repo = repo.filtered('visible'). With the change I proposed, it seems we don't need to change the filter here.

felixmerk edited edge metadata.Aug 7 2017, 3:32 PM
felixmerk updated this revision to Diff 609.
stash added a comment.Aug 8 2017, 4:05 AM

Are you going to address comments about {if(revset("{rev} and UNDODEL"), "-")} ?

tests/test-undo.t
709–712

Don't need it anymore?

734–737

Same here

stash added a comment.Aug 8 2017, 4:51 AM

Are you going to also show working copy changes?

hgext3rd/undo.py
427

With D207 this comment is not correct - it's not necessarily just last command.

446

Same here - not necessarily one repo state ago

{if(revset("{rev} and UNDODEL"), "-")} type stuff is on the facebook.rc side, so there isn't much to address about it here. The revsets/templates to do it exist and I've tested it.

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

It's still the (relative) last command. In 207 we just lie about what the last command is. Which really means I should fix 207.

stash accepted this revision.Aug 9 2017, 10:57 AM
quark accepted this revision.Aug 9 2017, 6:29 PM

Be sure to remove smartlog config before landing.

hgext3rd/undo.py
457

I see this is a global state on filesystem. Per discussion we could make it better - move the global state from filesystem to ui, as demostrated by P57852191. Let's do that in a follow-up.

892

I didn't see the definition of undopreview template. Maybe provide a fallback in the code. That could be a follow up.

This revision is now accepted and ready to land.Aug 9 2017, 6:29 PM
felixmerk updated this revision to Diff 720.Aug 9 2017, 7:52 PM
This revision was automatically updated to reflect the committed changes.