[PATCH 1 of 3 V2] convert: Add support to common commandline to access stdin of the process

Mads Kiilerich mads at kiilerich.com
Thu Mar 24 10:09:02 CDT 2011


On 03/24/2011 03:48 PM, daniel.atallah at gmail.com wrote:
> # HG changeset patch
> # User Daniel Atallah<daniel.atallah at gmail.com>
> # Date 1300906529 14400
> # Branch stable
> # Node ID 0fb617760b931cd25537e3362af52b2cfbd1a329
> # Parent  913c2c66a555934cab9bcdac3412703256f9cdf2
> convert: Add support to common commandline to access stdin of the process
>
> diff --git a/hgext/convert/common.py b/hgext/convert/common.py
> --- a/hgext/convert/common.py
> +++ b/hgext/convert/common.py
> @@ -233,6 +233,7 @@
>       def __init__(self, ui, command):
>           self.ui = ui
>           self.command = command
> +        self.redirectstdin = True

Is it really a good idea to have this as a state variable? Shouldn't it 
just be a parameter to _dorun and _cmdline?

/Mads

>       def prerun(self):
>           pass
> @@ -257,16 +258,23 @@
>           cmdline = [util.shellquote(arg) for arg in cmdline]
>           if not self.ui.debugflag:
>               cmdline += ['2>', util.nulldev]
> -        cmdline += ['<', util.nulldev]
> +        if self.redirectstdin:
> +            cmdline += ['<', util.nulldev]
>           cmdline = ' '.join(cmdline)
>           return cmdline
>
>       def _run(self, cmd, *args, **kwargs):
> +        return self._dorun(util.popen, cmd, *args, **kwargs)
> +
> +    def _run2(self, cmd, *args, **kwargs):
> +        return self._dorun(util.popen2, cmd, *args, **kwargs)
> +
> +    def _dorun(self, openfunc, cmd, *args, **kwargs):
>           cmdline = self._cmdline(cmd, *args, **kwargs)
>           self.ui.debug('running: %s\n' % (cmdline,))
>           self.prerun()
>           try:
> -            return util.popen(cmdline)
> +            return openfunc(cmdline)
>           finally:
>               self.postrun()



More information about the Mercurial-devel mailing list