[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Piping copious output to PAGER automatically.

From: David Wilson <dw_at_botanicus.net>
Date: 2004-09-03 15:46:23 CEST

Hi there,

First and foremost, congratulations on an excellent product. It is rare
to see an open source project so well built.

In #svn today, I suggested the addition of a feature which provoked a
little discussion, and it was suggested I post it here for
consideration.

Basically, in 99% of cases (and probably closer to 100% with
Subversion) when stdout is connected to a terminal device and we are
sending a large amount of output to stdout, there is a very high chance
that we are going to flood the user's terminal.

My basic idea is to test for something like the following or it's APR
equivalent:

    (isatty(fileno(stdout)) && (pager = getenv("PAGER")) && *pager)

If the condition succeeds, then use popen(3) (or the APR equivalent) to
pipe our copious output to the user's preferred PAGER instead of
directly to their screen.

The condition will fail if output is redirected to a file, for example,
with "svn diff > patch", and will also fail if PAGER is unset or
temporarily set to nothing, as in "PAGER= svn diff".

I first came across this function in Rick Faith's dict.org client
program, and have since found it to be a lovely little feature that has
never guessed wrong.

I feel it is rational behaviour since already the svn client behaves
interactively when it prompts for passwords, and since 99% of the time
when svn is connected to a TTY on stdout, it is being run interactively.

It isn't trying to be too smart as the user is asking all his system
programs to use his PAGER already, by voluntarily exporting the
environment variable in the first place.

The user has the choice of two overrides, namely:

    svn diff|cat
    PAGER= svn diff

Both of which will cause the test to fail.

A more conservative but less portable approach would be to query
TIOCGWINSZ first to check if our output is going to be larger than the
user's TTY can display, although I would personally be against this as I
regularly use my pager's stream saving functionality, which wouldn't be
available for small patches and logs.

Affected commands:

    svn cat
    svn blame
    svn diff
    svn help (?)
    svn list (?)
    svn log
    svn status

I am willing to provide a patch for the functionality, which would amount
to about 5 lines of change. It could also be made an optional feature
through ~/.subversion/config.

Thanks for your time,

David.

-- 
"Science is what we understand well enough to explain to a
computer. Art is everything else we do."
    -- Donald Knuth
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Sep 3 15:46:40 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.