Skip to content

Commit 033fe3d

Browse files
Martin Ågrengitster
Martin Ågren
authored andcommitted
git.c: provide setup_auto_pager()
The previous patch introduced a way for builtins to declare that they will take responsibility for handling the `pager.foo`-config item. (See the commit message of that patch for why that could be useful.) Provide setup_auto_pager(), which builtins can call in order to handle `pager.<cmd>`, including possibly starting the pager. Make this function don't do anything if a pager has already been started, as indicated by use_pager or pager_in_use(). Whenever this function is called from a builtin, git.c will already have called commit_pager_choice(). Since commit_pager_choice() treats the special value -1 as "punt" or "not yet decided", it is not a problem that we might end up calling commit_pager_choice() once in git.c and once (or more) in the builtin. Make the new function use -1 in the same way and document it as "punt". Don't add any users of setup_auto_pager just yet, one will follow in a later patch. Suggested-by: Jeff King <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c409824 commit 033fe3d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

builtin.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ struct fmt_merge_msg_opts {
113113
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
114114
struct fmt_merge_msg_opts *);
115115

116+
/**
117+
* If a built-in has DELAY_PAGER_CONFIG set, the built-in should call this early
118+
* when it wishes to respect the `pager.foo`-config. The `cmd` is the name of
119+
* the built-in, e.g., "foo". If a paging-choice has already been setup, this
120+
* does nothing. The default in `def` should be 0 for "pager off", 1 for "pager
121+
* on" or -1 for "punt".
122+
*
123+
* You should most likely use a default of 0 or 1. "Punt" (-1) could be useful
124+
* to be able to fall back to some historical compatibility name.
125+
*/
126+
extern void setup_auto_pager(const char *cmd, int def);
127+
116128
extern int is_builtin(const char *s);
117129

118130
extern int cmd_add(int argc, const char **argv, const char *prefix);

git.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ static void commit_pager_choice(void) {
3333
}
3434
}
3535

36+
void setup_auto_pager(const char *cmd, int def)
37+
{
38+
if (use_pager != -1 || pager_in_use())
39+
return;
40+
use_pager = check_pager_config(cmd);
41+
if (use_pager == -1)
42+
use_pager = def;
43+
commit_pager_choice();
44+
}
45+
3646
static int handle_options(const char ***argv, int *argc, int *envchanged)
3747
{
3848
const char **orig_argv = *argv;

0 commit comments

Comments
 (0)