Re: the pager
- From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
- Date
- Aug 29, 2013, 15:55 UTC
- Message-ID
- <vpqsixsv6dq.fsf@anie.imag.fr>
- In-Reply-To
- <201308291541.r7TFfuJr023110@freeze.ariadne.com>
worley@alum.mit.edu (Dale R. Worley) writes:
Show 19 quoted lines
> const char *git_pager(int stdout_is_tty)
> {
> const char *pager;
>
> if (!stdout_is_tty)
> return NULL;
>
> pager = getenv("GIT_PAGER");
> if (!pager) {
> if (!pager_program)
> git_config(git_default_config, NULL);
> pager = pager_program;
> }
> if (!pager)
> pager = getenv("PAGER");
> if (!pager)
> pager = DEFAULT_PAGER;
> else if (!*pager || !strcmp(pager, "cat"))
> pager = NULL;I guess the "else" could and should be dropped. If you do so (and possibly insert a blank line between the DEFAULT_PAGER case and the "pager = NULL" case), you get a nice pattern
if (!pager) try_something(); if (!pager) try_next_option(); ...
> Commenting your code is what you learn first in programming.
Not commenting too much is the second thing you learn ;-).
I agree that a comment like this would help, though:
--- a/cache.h +++ b/cache.h @@ -1266,7 +1266,7 @@ static inline ssize_t write_str_in_full(int fd, const char *str) /* pager.c */ extern void setup_pager(void); -extern const char *pager_program; +extern const char *pager_program; /* value read from git_config() */ extern int pager_in_use(void); extern int pager_use_color; extern int term_columns(void);
-- Matthieu Moy http://www-verimag.imag.fr/~moy/