[PATCH 5 of 5] cmdutil: do not duplicate stdout by makefileobj()

Augie Fackler raf at durin42.com
Fri Dec 18 10:30:15 CST 2015


On Thu, Dec 17, 2015 at 11:09:25PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1450004839 -32400
> #      Sun Dec 13 20:07:19 2015 +0900
> # Node ID a3a19a652fe6c25703a5f09be8192ecc5dda013d
> # Parent  41f488a682b0c9be578244fd4e95ba7ae09f796f
> cmdutil: do not duplicate stdout by makefileobj()

Queued these, thanks

>
> It made output order unpredictable because two separate buffers are flushed
> individually. Let's use a thin wrapper that just sends close() to black hole.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -461,12 +461,7 @@ def makefileobj(repo, pat, node=None, de
>              fp = repo.ui.fout
>          else:
>              fp = repo.ui.fin
> -        if util.safehasattr(fp, 'fileno'):
> -            return os.fdopen(os.dup(fp.fileno()), mode)
> -        else:
> -            # if this fp can't be duped properly, return
> -            # a dummy object that can be closed
> -            return _unclosablefile(fp)
> +        return _unclosablefile(fp)
>      if util.safehasattr(pat, 'write') and writable:
>          return pat
>      if util.safehasattr(pat, 'read') and 'r' in mode:
> diff --git a/tests/test-export.t b/tests/test-export.t
> --- a/tests/test-export.t
> +++ b/tests/test-export.t
> @@ -140,6 +140,7 @@ Exporting revision -2 to a file:
>  No filename should be printed if stdout is specified explicitly:
>
>    $ hg export -v 1 -o -
> +  exporting patch:
>    # HG changeset patch
>    # User test
>    # Date 0 0
> @@ -154,7 +155,6 @@ No filename should be printed if stdout
>    @@ -1,1 +1,2 @@
>     foo-0
>    +foo-1
> -  exporting patch:
>
>  Checking if only alphanumeric characters are used in the file name (%m option):
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list