@matheusbsbs / matheus-bagliano / commits / 9bad723369
Fork 0

allow command-specific pagers in pager.<cmd>

A user may want different pager settings or even a different pager for various subcommands (e.g., because they use different less settings for "log" vs "diff", or because they have a pager that interprets only log output but not other commands). This patch extends the pager.<cmd> syntax to support not only boolean to-page-or-not-to-page, but also to specify a pager just for a specific command. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 17, 2010 at 12:04 UTC 9bad7233699e1fcf58e75f1e163499ec24680826
3 files changed +52 -10
Documentation/config.txt
+7 -5
@@ -1521,11 +1521,13 @@ pack.packSizeLimit::
1521 supported.
1522
1523 pager.<cmd>::
1524 - Allows turning on or off pagination of the output of a
1525 - particular git subcommand when writing to a tty. If
1526 - `\--paginate` or `\--no-pager` is specified on the command line,
1527 - it takes precedence over this option. To disable pagination for
1528 - all commands, set `core.pager` or `GIT_PAGER` to `cat`.
1524 + If the value is boolean, turns on or off pagination of the
1525 + output of a particular git subcommand when writing to a tty.
1526 + Otherwise, turns on pagination for the subcommand using the
1527 + pager specified by the value of `pager.<cmd>`. If `\--paginate`
1528 + or `\--no-pager` is specified on the command line, it takes
1529 + precedence over this option. To disable pagination for all
1530 + commands, set `core.pager` or `GIT_PAGER` to `cat`.
1531
1532 pretty.<name>::
1533 Alias for a --pretty= format string, as specified in
git.c
+16 -5
@@ -19,14 +19,22 @@ static struct startup_info git_startup_info;
19 static int use_pager = -1;
20 struct pager_config {
21 const char *cmd;
22 - int val;
22 + int want;
23 + char *value;
24 };
25
26 static int pager_command_config(const char *var, const char *value, void *data)
27 {
28 struct pager_config *c = data;
28 - if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd))
29 - c->val = git_config_bool(var, value);
29 + if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
30 + int b = git_config_maybe_bool(var, value);
31 + if (b >= 0)
32 + c->want = b;
33 + else {
34 + c->want = 1;
35 + c->value = xstrdup(value);
36 + }
37 + }
38 return 0;
39 }
40
@@ -35,9 +43,12 @@ int check_pager_config(const char *cmd)
43 {
44 struct pager_config c;
45 c.cmd = cmd;
38 - c.val = -1;
46 + c.want = -1;
47 + c.value = NULL;
48 git_config(pager_command_config, &c);
40 - return c.val;
49 + if (c.value)
50 + pager_program = c.value;
51 + return c.want;
52 }
53
54 static void commit_pager_choice(void) {
t/t7006-pager.sh
+29
@@ -435,4 +435,33 @@ test_core_pager_subdir expect_success 'git -p shortlog'
435 test_core_pager_subdir expect_success test_must_fail \
436 'git -p apply </dev/null'
437
438 +test_expect_success TTY 'command-specific pager' '
439 + unset PAGER GIT_PAGER;
440 + echo "foo:initial" >expect &&
441 + >actual &&
442 + git config --unset core.pager &&
443 + git config pager.log "sed s/^/foo:/ >actual" &&
444 + test_terminal git log --format=%s -1 &&
445 + test_cmp expect actual
446 +'
447 +
448 +test_expect_success TTY 'command-specific pager overrides core.pager' '
449 + unset PAGER GIT_PAGER;
450 + echo "foo:initial" >expect &&
451 + >actual &&
452 + git config core.pager "exit 1"
453 + git config pager.log "sed s/^/foo:/ >actual" &&
454 + test_terminal git log --format=%s -1 &&
455 + test_cmp expect actual
456 +'
457 +
458 +test_expect_success TTY 'command-specific pager overridden by environment' '
459 + GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER &&
460 + >actual &&
461 + echo "foo:initial" >expect &&
462 + git config pager.log "exit 1" &&
463 + test_terminal git log --format=%s -1 &&
464 + test_cmp expect actual
465 +'
466 +
467 test_done