[PATCH 3 of 5] histedit: use ui.fin to read commands from stdin
Yuya Nishihara
yuya at tcha.org
Wed Nov 2 08:02:15 EDT 2016
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1458346506 25200
# Fri Mar 18 17:15:06 2016 -0700
# Node ID 6f7e69bc46fc158f2df39f94f6e314fc7a66eca1
# Parent ed456439699b5af90a3a5ae36a8ac82431448c68
# EXP-Topic stdio
histedit: use ui.fin to read commands from stdin
stdin is wrapped by channeledinput in command-server session.
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -173,7 +173,6 @@ from __future__ import absolute_import
import errno
import os
-import sys
from mercurial.i18n import _
from mercurial import (
@@ -991,9 +990,9 @@ def _getgoal(opts):
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 @@ def _edithisteditplan(ui, repo, state, r
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 @@ def _newhistedit(ui, repo, state, revs,
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)
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -135,6 +135,19 @@ typical client does not want echo-back m
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
More information about the Mercurial-devel
mailing list