[PATCH 1 of 1] acl: skip unneeded lines in hg output

Cameron Simpson cs at zip.com.au
Tue May 29 18:14:16 CDT 2012


First time sticking my head above water here. If I'm off the guidelines
please let me know.

Two remarks, one style and one a bug concern:

On 28May2012 10:47, elifarley at gmail.com <elifarley at gmail.com> wrote:
| acl: skip unneeded lines in hg output
[...]
| +  > skiplines() {
| +  > sed -e /^files:/d -e /^bundling:/d -e /^changesets:/d -e /^manifests:/d \
| +  > -e '/^searching for changes/d' \
| +  > -e '/^all remote heads known locally/d' \
| +  > -e '/^invalidating branch cache/d' \

On a purely stylistic note, I prefer to write this kind of thing thus:

  sed -e '
    /^files:/d
    /^bundling:/d
    /^changesets:/d
    /^manifests:/d
    /^searching for changes/d
    /^all remote heads known locally/d
    /^invalidating branch cache/d
    '

because it far easier to read/debug/modify.

But now on to a bug:

|    > do_push()
|    > {
|    >     user=$1
| @@ -15,7 +28,7 @@
|    >     #  LOGNAME=$user hg --cws a --debug push ../b
|    >     # fails with "This variable is read only."
|    >     # Use env to work around this.
| -  >     env LOGNAME=$user hg --cwd a --debug push ../b
| +  >     env LOGNAME=$user hg --cwd a --debug push ../b 2>&1 | skiplines

There are a few problems with this.

Firstly, this throws stderr into the stdout stream. Generally very
undesirable. We don't want error message polluting stdout, and we don't want
error messages vanishing from stderr.

Also, the stripped lines that skiplines() strip should only be present in
stdout anyway.

So why are you using "2>&1" ?

If you really need to filter stderr, a completely separate skiplines()
("skiperrlines()"?) should be used, with its own specialised patterns.

Though also I am against filtering stderr because you may filter
pertinent stuff by accident.

The other thing such a pipeline does is discard the exit status of the
"hg ... push" command you're filtering.

It _is_ possible to filter stdout and/or stderr arbitrarily and also
preserve the correct exit status, but it it more complex. You can see a
script that does this correctly here:

  https://bitbucket.org/cameron_simpson/css/src/tip/bin/filter_fd

which one would invoke:

  env LOGNAME=$user filter_fd 1 'sed -e "$_skiplines_sedf"' hg --cwd a --debug push ../b

having set and exported (regrettably) $_skiplines_sedf earlier instead
of making a shell function, eg:

  _skiplines_sedf='
    /^files:/d
    /^bundling:/d
    /^changesets:/d
    /^manifests:/d
    /^searching for changes/d
    /^all remote heads known locally/d
    /^invalidating branch cache/d
    '
  export _skiplines_sedf

One could embed the export in the env command to reduce the pollution.
One could also make a shell function to wrap filter_fd or its
equivalent.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Don't have awk? Use this simple sh emulation:
    #!/bin/sh
    echo 'Awk bailing out!' >&2
    exit 2
- Tom Horsley <tahorsley at csd.harris.com>


More information about the Mercurial-devel mailing list