mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
undo: preview shows command and time output
Makes hg undo -i and hg undo -p output show an "undo to time, before command" message and adds directions (left, right, return, q). Also adds pager check as pager break interactiveui. Testing: run hg undo -p and hg undo -i and see output Differential Revision: https://phab.mercurial-scm.org/D448
This commit is contained in:
parent
c4e13682c5
commit
e45f912211
@ -12,12 +12,19 @@ import sys
|
||||
import termios
|
||||
import tty
|
||||
|
||||
def clearline():
|
||||
from mercurial.i18n import _
|
||||
|
||||
from mercurial import (
|
||||
error,
|
||||
)
|
||||
|
||||
def clearline(n=1):
|
||||
w = sys.stdout
|
||||
# ANSI
|
||||
# ESC[#A : up # lines
|
||||
# ESC[K : clear to end of line
|
||||
w.write('\033[1A\033[K')
|
||||
for i in range(n):
|
||||
w.write('\033[1A\033[K')
|
||||
w.flush()
|
||||
|
||||
# From:
|
||||
@ -107,8 +114,10 @@ class viewframe(object):
|
||||
|
||||
def view(viewobj):
|
||||
done = False
|
||||
if viewobj.ui.pageractive:
|
||||
raise error.Abort(_("interactiveui doesn't work with pager"))
|
||||
s = viewobj.render()
|
||||
print(s)
|
||||
sys.stdout.write(s)
|
||||
while not done:
|
||||
output = getchar(sys.stdin.fileno())
|
||||
if repr(output) == '\'q\'':
|
||||
@ -123,7 +132,6 @@ def view(viewobj):
|
||||
viewobj.rightarrow()
|
||||
if repr(output) == '\'\\x1b[D\'':
|
||||
viewobj.leftarrow()
|
||||
for i in range(len(s.split("\n"))):
|
||||
clearline()
|
||||
clearline(s.count("\n"))
|
||||
s = viewobj.render()
|
||||
print(s)
|
||||
sys.stdout.write(s)
|
||||
|
@ -653,6 +653,10 @@ def undo(ui, repo, *args, **opts):
|
||||
ui = self.ui
|
||||
ui.pushbuffer()
|
||||
_preview(ui, self.repo, self.index)
|
||||
repo.ui.status(_("<-: next "
|
||||
"->: previous "
|
||||
"q: abort "
|
||||
"enter: confirm\n"))
|
||||
return ui.popbuffer()
|
||||
def rightarrow(self):
|
||||
self.index += 1
|
||||
@ -862,8 +866,8 @@ def _undoto(ui, repo, reverseindex, keep=False, branch=None):
|
||||
commandstr = _readnode(repo, "command.i", nodedict["command"])
|
||||
commandlist = commandstr.split("\0")[1:]
|
||||
commandstr = " ".join(commandlist)
|
||||
uimessage = 'undone to %s, before %s\n' % (time, commandstr)
|
||||
repo.ui.status(_(uimessage))
|
||||
uimessage = _('undone to %s, before %s\n') % (time, commandstr)
|
||||
repo.ui.status((uimessage))
|
||||
|
||||
def _computerelative(repo, reverseindex, absolute=False, branch=""):
|
||||
# allows for relative undos using
|
||||
@ -1069,6 +1073,9 @@ def _preview(ui, repo, reverseindex):
|
||||
# None
|
||||
|
||||
# override "UNDOINDEX" as a variable usable in template
|
||||
if not _gapcheck(ui, repo, reverseindex):
|
||||
repo.ui.status(_("WARN: missing history between present and this"
|
||||
" state\n"))
|
||||
overrides = {
|
||||
('templates', 'UNDOINDEX'): str(reverseindex),
|
||||
}
|
||||
@ -1082,6 +1089,17 @@ def _preview(ui, repo, reverseindex):
|
||||
try:
|
||||
with ui.configoverride(overrides):
|
||||
cmdutil.graphlog(ui, repo, None, opts)
|
||||
# informative output
|
||||
nodedict = _readindex(repo, reverseindex)
|
||||
time = _readnode(repo, "date.i", nodedict["date"])
|
||||
time = util.datestr([float(x) for x in time.split(" ")])
|
||||
|
||||
nodedict = _readindex(repo, reverseindex - 1)
|
||||
commandstr = _readnode(repo, "command.i", nodedict["command"])
|
||||
commandlist = commandstr.split("\0")[1:]
|
||||
commandstr = " ".join(commandlist)
|
||||
uimessage = _('undo to %s, before %s\n') % (time, commandstr)
|
||||
repo.ui.status((uimessage))
|
||||
except IndexError:
|
||||
# don't print anything
|
||||
pass
|
||||
|
@ -734,6 +734,7 @@ hg undo --preview test
|
||||
o
|
||||
|
|
||||
~
|
||||
undo to *, before ci -m prev1 (glob)
|
||||
$ hg undo -p -n 2
|
||||
@ Undone
|
||||
|
|
||||
@ -754,6 +755,7 @@ hg undo --preview test
|
||||
o
|
||||
|
|
||||
~
|
||||
undo to *, before undo -b 3532 (glob)
|
||||
|
||||
hg redo tests
|
||||
$ hg log -G -T compact
|
||||
|
Loading…
Reference in New Issue
Block a user