[PATCH 3 of 3] use the ui streams instead of sys.std* where possible
Idan Kamara
idankk86 at gmail.com
Tue Jun 7 13:55:46 UTC 2011
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1307443149 -10800
# Node ID 0571bf4d576617189d4e9020432cddae0e04aa16
# Parent f1a5454549e8878e05a3486c89e791a704345ca5
use the ui streams instead of sys.std* where possible
diff -r f1a5454549e8 -r 0571bf4d5766 hgext/fetch.py
--- a/hgext/fetch.py Tue Jun 07 13:39:09 2011 +0300
+++ b/hgext/fetch.py Tue Jun 07 13:39:09 2011 +0300
@@ -123,7 +123,7 @@
if not err:
# we don't translate commit messages
- message = (cmdutil.logmessage(opts) or
+ message = (cmdutil.logmessage(ui, opts) or
('Automated merge with %s' %
util.removeauth(other.url())))
editor = cmdutil.commiteditor
diff -r f1a5454549e8 -r 0571bf4d5766 hgext/mq.py
--- a/hgext/mq.py Tue Jun 07 13:39:09 2011 +0300
+++ b/hgext/mq.py Tue Jun 07 13:39:09 2011 +0300
@@ -1831,7 +1831,7 @@
self.checkpatchname(patchname, force)
try:
if filename == '-':
- text = sys.stdin.read()
+ text = self.ui.fin.read()
else:
fp = url.open(self.ui, filename)
text = fp.read()
@@ -2211,7 +2211,7 @@
Returns 0 on successful creation of a new patch.
"""
- msg = cmdutil.logmessage(opts)
+ msg = cmdutil.logmessage(ui, opts)
def getmsg():
return ui.edit(msg, opts.get('user') or ui.username())
q = repo.mq
@@ -2262,7 +2262,7 @@
Returns 0 on success.
"""
q = repo.mq
- message = cmdutil.logmessage(opts)
+ message = cmdutil.logmessage(ui, opts)
if opts.get('edit'):
if not q.applied:
ui.write(_("no patches applied\n"))
@@ -2328,7 +2328,7 @@
raise util.Abort(_('no patches applied'))
q.check_localchanges(repo)
- message = cmdutil.logmessage(opts)
+ message = cmdutil.logmessage(ui, opts)
if opts.get('edit'):
if message:
raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
@@ -2653,7 +2653,7 @@
This command is deprecated, use :hg:`rebase` instead."""
q = repo.mq
- message = cmdutil.logmessage(opts)
+ message = cmdutil.logmessage(ui, opts)
ret = q.save(repo, msg=message)
if ret:
return ret
diff -r f1a5454549e8 -r 0571bf4d5766 hgext/rebase.py
--- a/hgext/rebase.py Tue Jun 07 13:39:09 2011 +0300
+++ b/hgext/rebase.py Tue Jun 07 13:39:09 2011 +0300
@@ -117,7 +117,7 @@
contf = opts.get('continue')
abortf = opts.get('abort')
collapsef = opts.get('collapse', False)
- collapsemsg = cmdutil.logmessage(opts)
+ collapsemsg = cmdutil.logmessage(ui, opts)
extrafn = opts.get('extrafn') # internal, used by e.g. hgsubversion
keepf = opts.get('keep', False)
keepbranchesf = opts.get('keepbranches', False)
diff -r f1a5454549e8 -r 0571bf4d5766 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Tue Jun 07 13:39:09 2011 +0300
+++ b/mercurial/cmdutil.py Tue Jun 07 13:39:09 2011 +0300
@@ -76,7 +76,7 @@
if modified or added or removed or deleted:
raise util.Abort(_("outstanding uncommitted changes"))
-def logmessage(opts):
+def logmessage(ui, opts):
""" get the log message according to -m and -l option """
message = opts.get('message')
logfile = opts.get('logfile')
@@ -87,7 +87,7 @@
if not message and logfile:
try:
if logfile == '-':
- message = sys.stdin.read()
+ message = ui.fin.read()
else:
message = '\n'.join(util.readfile(logfile).splitlines())
except IOError, inst:
@@ -160,8 +160,11 @@
writable = mode not in ('r', 'rb')
if not pat or pat == '-':
- fp = writable and sys.stdout or sys.stdin
- return os.fdopen(os.dup(fp.fileno()), mode)
+ fp = writable and repo.ui.fout or repo.ui.fin
+ if fp in (sys.__stdout__, sys.__stdin__):
+ return os.fdopen(os.dup(fp.fileno()), mode)
+ else:
+ return fp
if hasattr(pat, 'write') and writable:
return pat
if hasattr(pat, 'read') and 'r' in mode:
@@ -1163,7 +1166,7 @@
date = opts.get('date')
if date:
opts['date'] = util.parsedate(date)
- message = logmessage(opts)
+ message = logmessage(ui, opts)
# extract addremove carefully -- this function can be called from a command
# that doesn't support addremove
diff -r f1a5454549e8 -r 0571bf4d5766 mercurial/commands.py
--- a/mercurial/commands.py Tue Jun 07 13:39:09 2011 +0300
+++ b/mercurial/commands.py Tue Jun 07 13:39:09 2011 +0300
@@ -336,7 +336,7 @@
if dest == '-':
if kind == 'files':
raise util.Abort(_('cannot archive plain files to stdout'))
- dest = sys.stdout
+ dest = ui.fout
if not prefix:
prefix = os.path.basename(repo.root) + '-%h'
@@ -1226,7 +1226,7 @@
if text is None:
ui.status(_("reading DAG from stdin\n"))
- text = sys.stdin.read()
+ text = ui.fin.read()
cl = repo.changelog
if len(cl) > 0:
@@ -3069,7 +3069,7 @@
commitid = _('to working directory')
try:
- cmdline_message = cmdutil.logmessage(opts)
+ cmdline_message = cmdutil.logmessage(ui, opts)
if cmdline_message:
# pickup the cmdline msg
message = cmdline_message
@@ -3141,7 +3141,7 @@
if pf == '-':
ui.status(_("applying patch from stdin\n"))
- pf = sys.stdin
+ pf = ui.fin
else:
ui.status(_("applying %s\n") % p)
pf = url.open(ui, pf)
diff -r f1a5454549e8 -r 0571bf4d5766 mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py Tue Jun 07 13:39:09 2011 +0300
+++ b/mercurial/hgweb/server.py Tue Jun 07 13:39:09 2011 +0300
@@ -277,8 +277,8 @@
prefix = '/' + prefix.strip('/')
self.prefix = prefix
- alog = openlog(ui.config('web', 'accesslog', '-'), sys.stdout)
- elog = openlog(ui.config('web', 'errorlog', '-'), sys.stderr)
+ alog = openlog(ui.config('web', 'accesslog', '-'), ui.fout)
+ elog = openlog(ui.config('web', 'errorlog', '-'), ui.ferr)
self.accesslog = alog
self.errorlog = elog
More information about the Mercurial-devel
mailing list