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.
Details
- Reviewers
stash quark - Group Reviewers
Restricted Project - Commits
- rFBHGXfc0806ff0c3d: undo: add --index and redo support to preview
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
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(...) :). | |
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) ? |
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.
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. | |
929–933 | Why are you catching IndexError? | |
936 | No need for return |
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. |
BTW, why do you need a tr? It's not used