undo: fix undo -i

Summary:
D27144492 (48cd15ab14) broke hg undo -i by changing the way integers are formatted
into revsets. This was done to do some rev validation, but undo used the integer
formatting for non-rev cases and this broke undo's usage. Let's just move to
normal python string formatting for undo's case.

The migration to Python 3 also broke hg undo -i by causing the repr() output to
change, which messes up the interactive ui handling. Let's fix that as well, and
drop the repr stuff.

Reviewed By: zzl0

Differential Revision: D39892760

fbshipit-source-id: 96655f743e4187f7345f7f3c6a2fe74fb326335e
This commit is contained in:
Durham Goode 2022-09-28 18:35:42 -07:00 committed by Facebook GitHub Bot
parent 62b29a71df
commit 8fc51a190f
3 changed files with 68 additions and 28 deletions

View File

@ -151,21 +151,21 @@ def view(viewobj):
sys.stdout.write(s)
while not done:
output = getchar(sys.stdin.fileno())
if repr(output) == "'q'":
if output == b"q":
done = True
break
if repr(output) == "'\\r'":
if output == b"\r":
# \r = return
viewobj.enter()
done = True
break
if repr(output) == "'\\x1b[C'":
if output == b"\x1b[C":
viewobj.rightarrow()
if repr(output) == "'\\x1b[D'":
if output == b"\x1b[D":
viewobj.leftarrow()
if repr(output) == "'a'":
if output == b"a":
viewobj.apress()
if repr(output) == "'d'":
if output == b"d":
viewobj.dpress()
linecount = s.count("\n")
s = viewobj.render()

View File

@ -651,7 +651,7 @@ templatefunc = registrar.templatefunc()
def _undonehexnodes(repo, reverseindex):
revstring = revsetlang.formatspec("olddraft(0) - olddraft(%d)", reverseindex)
revstring = "olddraft(0) - olddraft(%d)" % reverseindex
return list(repo.nodes(revstring))
@ -672,7 +672,7 @@ def showundonecommits(context, mapping, args):
def _donehexnodes(repo, reverseindex):
revstring = revsetlang.formatspec("olddraft(%d)", reverseindex)
revstring = "olddraft(%d)" % reverseindex
return list(repo.nodes(revstring))
@ -756,7 +756,7 @@ def oldworkingparenttemplate(context, mapping, args):
)
repo = mapping["ctx"]._repo
ctx = mapping["ctx"]
revstring = revsetlang.formatspec("oldworkingcopyparent(%d)", reverseindex)
revstring = "oldworkingcopyparent(%d)" % reverseindex
nodes = list(repo.nodes(revstring))
if ctx.node() in nodes:
result = ctx.hex()
@ -1077,8 +1077,8 @@ def _undoto(ui, repo, reverseindex, keep=False, branch=None):
dirstate.remove(filename)
# visible changesets
addedrevs = revsetlang.formatspec("olddraft(0) - olddraft(%d)", reverseindex)
removedrevs = revsetlang.formatspec("olddraft(%d) - olddraft(0)", reverseindex)
addedrevs = "olddraft(0) - olddraft(%d)" % reverseindex
removedrevs = "olddraft(%d) - olddraft(0)" % reverseindex
if not branch:
if repo.ui.configbool("experimental", "narrow-heads"):
# Assuming mutation and visibility are used. Restore visibility heads
@ -1090,10 +1090,11 @@ def _undoto(ui, repo, reverseindex, keep=False, branch=None):
revealcommits(repo, removedrevs)
else:
localadds = revsetlang.formatspec(
"(olddraft(0) - olddraft(%d)) and" " _localbranch(%s)", reverseindex, branch
"(olddraft(0) - olddraft(%d)) and _localbranch(%%s)" % reverseindex, branch
)
localremoves = revsetlang.formatspec(
"(olddraft(%d) - olddraft(0)) and" " _localbranch(%s)", reverseindex, branch
"(olddraft(%d) - olddraft(0)) and" " _localbranch(%%s)" % reverseindex,
branch,
)
smarthide(repo, localadds, removedrevs)
smarthide(repo, addedrevs, localremoves, local=True)
@ -1240,13 +1241,9 @@ def _findnextdelta(repo, reverseindex, branch, direction):
# disjunctive union of present and old = changes
# intersection of changes and local = localchanges
localctxchanges = revsetlang.formatspec(
"((olddraft(%d) + olddraft(%d)) -"
"(olddraft(%d) and olddraft(%d)))"
" and _localbranch(%s)",
incrementalindex,
reverseindex,
incrementalindex,
reverseindex,
("((olddraft(%d) + olddraft(%d)) -" % (incrementalindex, reverseindex))
+ ("(olddraft(%d) and olddraft(%d)))" % (incrementalindex, reverseindex))
+ " and _localbranch(%s)",
branch,
)
done = done or repo.revs(localctxchanges)
@ -1375,15 +1372,11 @@ def _preview(ui, repo, reverseindex):
bookdiffs += kv[0]
revstring = revsetlang.formatspec(
"ancestor(olddraft(0), olddraft(%s)) +"
"(draft() & ::((olddraft(0) - olddraft(%s)) + "
"(olddraft(%s) - olddraft(0)) + %ls + '.' + "
"oldworkingcopyparent(%s)))",
reverseindex,
reverseindex,
reverseindex,
("ancestor(olddraft(0), olddraft(%s)) +" % reverseindex)
+ ("(draft() & ::((olddraft(0) - olddraft(%s)) + " % reverseindex)
+ ("(olddraft(%s) - olddraft(0)) + %%ls + '.' + " % reverseindex)
+ ("oldworkingcopyparent(%s)))" % reverseindex),
bookdiffs,
reverseindex,
)
opts["rev"] = [revstring]

View File

@ -0,0 +1,47 @@
#chg-compatible
$ configure modernclient
$ newclientrepo repo
$ enable undo
$ echo >> file
$ hg commit -Aqm "initial commit"
$ echo >> file
$ hg commit -Aqm "initial commit"
$ hg log -r 'olddraft(0)'
commit: 79344ac2ab8b
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: initial commit
commit: f5a897cc70a1
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: initial commit
$ hg log -r 'oldworkingcopyparent(0)'
commit: f5a897cc70a1
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: initial commit
$ hg log -r . -T '{undonecommits(0)}\n'
$ hg log -r . -T '{donecommits(0)}\n'
f5a897cc70a18acf06b00febe9ad748ac761067d
$ hg log -r . -T '{oldworkingcopyparent(0)}\n'
f5a897cc70a18acf06b00febe9ad748ac761067d
$ hg undo --preview
@
o
undo to *, before commit -Aqm initial commit (glob)
$ hg undo
undone to *, before commit -Aqm initial commit (glob)
hint[undo-uncommit-unamend]: undoing commits discards their changes.
to restore the changes to the working copy, run 'hg revert -r f5a897cc70a1 --all'
in the future, you can use 'hg uncommit' instead of 'hg undo' to keep changes
hint[hint-ack]: use 'hg hint --ack undo-uncommit-unamend' to silence these hints