Submitter | Yuya Nishihara |
---|---|
Date | Nov. 10, 2016, 2:29 p.m. |
Message ID | <fd6ae865d906db210308.1478788159@mimosa> |
Download | mbox | patch |
Permalink | /patch/17448/ |
State | Accepted |
Headers | show |
Comments
On Thu, Nov 10, 2016 at 11:29:19PM +0900, Yuya Nishihara wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1478612505 -32400 > # Tue Nov 08 22:41:45 2016 +0900 > # Node ID fd6ae865d906db2103088b042c17a4b3e0672aeb > # Parent 0cba9f6a152e2b175e344bae23d0ec76a0ffe59d > hook: lower inflated use of sys.__stdout__ and __stderr__ Queued these, thanks > > They were introduced at 9f76df0edb7d, where sys.stdout could be replaced by > sys.stderr. After that, we've changed the way of stdout redirection by > afccc64eea73, so we no longer need to reference the original __stdout__ and > __stderr__ objects. > > Let's move away from using __std*__ objects so we can simply wrap sys.std* > objects for Python 3 porting. > > diff --git a/mercurial/hook.py b/mercurial/hook.py > --- a/mercurial/hook.py > +++ b/mercurial/hook.py > @@ -209,11 +209,11 @@ def runhooks(ui, repo, name, hooks, thro > for hname, cmd in hooks: > if oldstdout == -1 and _redirect: > try: > - stdoutno = sys.__stdout__.fileno() > - stderrno = sys.__stderr__.fileno() > + stdoutno = sys.stdout.fileno() > + stderrno = sys.stderr.fileno() > # temporarily redirect stdout to stderr, if possible > if stdoutno >= 0 and stderrno >= 0: > - sys.__stdout__.flush() > + sys.stdout.flush() > oldstdout = os.dup(stdoutno) > os.dup2(stderrno, stdoutno) > except (OSError, AttributeError): > @@ -258,7 +258,7 @@ def runhooks(ui, repo, name, hooks, thro > sys.stderr.flush() > finally: > if _redirect and oldstdout >= 0: > - sys.__stdout__.flush() # write hook output to stderr fd > + sys.stdout.flush() # write hook output to stderr fd > os.dup2(oldstdout, stdoutno) > os.close(oldstdout) > > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Patch
diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -209,11 +209,11 @@ def runhooks(ui, repo, name, hooks, thro for hname, cmd in hooks: if oldstdout == -1 and _redirect: try: - stdoutno = sys.__stdout__.fileno() - stderrno = sys.__stderr__.fileno() + stdoutno = sys.stdout.fileno() + stderrno = sys.stderr.fileno() # temporarily redirect stdout to stderr, if possible if stdoutno >= 0 and stderrno >= 0: - sys.__stdout__.flush() + sys.stdout.flush() oldstdout = os.dup(stdoutno) os.dup2(stderrno, stdoutno) except (OSError, AttributeError): @@ -258,7 +258,7 @@ def runhooks(ui, repo, name, hooks, thro sys.stderr.flush() finally: if _redirect and oldstdout >= 0: - sys.__stdout__.flush() # write hook output to stderr fd + sys.stdout.flush() # write hook output to stderr fd os.dup2(oldstdout, stdoutno) os.close(oldstdout)