histedit: use ui.fin to read commands from stdin
stdin is wrapped by channeledinput in command-server session.
--- a/hgext/histedit.py Sat Oct 03 14:34:56 2015 +0900
+++ b/hgext/histedit.py Fri Mar 18 17:15:06 2016 -0700
@@ -173,7 +173,6 @@
import errno
import os
-import sys
from mercurial.i18n import _
from mercurial import (
@@ -991,9 +990,9 @@
return goaleditplan
return goalnew
-def _readfile(path):
+def _readfile(ui, path):
if path == '-':
- return sys.stdin.read()
+ return ui.fin.read()
else:
with open(path, 'rb') as f:
return f.read()
@@ -1191,7 +1190,7 @@
node.short(state.topmost))
rules = ruleeditor(repo, ui, state.actions, comment)
else:
- rules = _readfile(rules)
+ rules = _readfile(ui, rules)
actions = parserules(rules, state)
ctxs = [repo[act.node] \
for act in state.actions if act.node]
@@ -1232,7 +1231,7 @@
actions = [pick(state, r) for r in revs]
rules = ruleeditor(repo, ui, actions, comment)
else:
- rules = _readfile(rules)
+ rules = _readfile(ui, rules)
actions = parserules(rules, state)
warnverifyactions(ui, repo, actions, state, ctxs)
--- a/tests/test-commandserver.t Sat Oct 03 14:34:56 2015 +0900
+++ b/tests/test-commandserver.t Fri Mar 18 17:15:06 2016 -0700
@@ -135,6 +135,19 @@
summary: 1
+check that "histedit --commands=-" can read rules from the input channel:
+
+ >>> import cStringIO
+ >>> from hgclient import readchannel, runcommand, check
+ >>> @check
+ ... def serverinput(server):
+ ... readchannel(server)
+ ... rules = 'pick eff892de26ec\n'
+ ... runcommand(server, ['histedit', '0', '--commands=-',
+ ... '--config', 'extensions.histedit='],
+ ... input=cStringIO.StringIO(rules))
+ *** runcommand histedit 0 --commands=- --config extensions.histedit=
+
check that --cwd doesn't persist between requests:
$ mkdir foo