Skip to content

Commit 59b6131

Browse files
pks-tgitster
authored andcommitted
pager: stop using the_repository
Stop using `the_repository` in the "pager" subsystem by passing in a repository when setting up the pager and when configuring it. Adjust callers accordingly by using `the_repository`. While there may be some callers that have a repository available in their context, this trivial conversion allows for easier verification and bubbles up the use of `the_repository` by one level. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f7e647 commit 59b6131

File tree

11 files changed

+27
-28
lines changed

11 files changed

+27
-28
lines changed

add-patch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ static int patch_update_file(struct add_p_state *s,
14641464
if (file_diff->hunk_nr) {
14651465
if (rendered_hunk_index != hunk_index) {
14661466
if (use_pager) {
1467-
setup_pager();
1467+
setup_pager(the_repository);
14681468
sigchain_push(SIGPIPE, SIG_IGN);
14691469
}
14701470
render_hunk(s, hunk, 0, colored, &s->buf);

builtin/am.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ static int do_interactive(struct am_state *state)
17861786
}
17871787
strbuf_release(&msg);
17881788
} else if (*reply == 'v' || *reply == 'V') {
1789-
const char *pager = git_pager(1);
1789+
const char *pager = git_pager(the_repository, 1);
17901790
struct child_process cp = CHILD_PROCESS_INIT;
17911791

17921792
if (!pager)
@@ -2246,7 +2246,7 @@ static int show_patch(struct am_state *state, enum resume_type resume_mode)
22462246
if (len < 0)
22472247
die_errno(_("failed to read '%s'"), patch_path);
22482248

2249-
setup_pager();
2249+
setup_pager(the_repository);
22502250
write_in_full(1, sb.buf, sb.len);
22512251
strbuf_release(&sb);
22522252
return 0;

builtin/blame.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ int cmd_blame(int argc,
12021202
stop_progress(&pi.progress);
12031203

12041204
if (!incremental)
1205-
setup_pager();
1205+
setup_pager(the_repository);
12061206
else
12071207
goto cleanup;
12081208

builtin/grep.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ int cmd_grep(int argc,
10841084
}
10851085

10861086
if (show_in_pager == default_pager)
1087-
show_in_pager = git_pager(1);
1087+
show_in_pager = git_pager(the_repository, 1);
10881088
if (show_in_pager) {
10891089
opt.color = 0;
10901090
opt.name_only = 1;
@@ -1246,7 +1246,7 @@ int cmd_grep(int argc,
12461246
}
12471247

12481248
if (!show_in_pager && !opt.status_only)
1249-
setup_pager();
1249+
setup_pager(the_repository);
12501250

12511251
die_for_incompatible_opt3(!use_index, "--no-index",
12521252
untracked, "--untracked",

builtin/help.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ int cmd_help(int argc,
658658
case HELP_ACTION_ALL:
659659
opt_mode_usage(argc, "--all", help_format);
660660
if (verbose) {
661-
setup_pager();
661+
setup_pager(the_repository);
662662
list_all_cmds_help(show_external_commands,
663663
show_aliases);
664664
return 0;
@@ -692,7 +692,7 @@ int cmd_help(int argc,
692692
return 0;
693693
case HELP_ACTION_CONFIG:
694694
opt_mode_usage(argc, "--config", help_format);
695-
setup_pager();
695+
setup_pager(the_repository);
696696
list_config_help(SHOW_CONFIG_HUMAN);
697697
printf("\n%s\n", _("'git help config' for more information"));
698698
return 0;

builtin/log.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
369369
if (rev->line_level_traverse)
370370
line_log_init(rev, line_cb.prefix, &line_cb.args);
371371

372-
setup_pager();
372+
setup_pager(the_repository);
373373
}
374374

375375
static void cmd_log_init(int argc, const char **argv, const char *prefix,
@@ -2292,7 +2292,7 @@ int cmd_format_patch(int argc,
22922292
rev.commit_format = CMIT_FMT_MBOXRD;
22932293

22942294
if (use_stdout) {
2295-
setup_pager();
2295+
setup_pager(the_repository);
22962296
} else if (!rev.diffopt.close_file) {
22972297
int saved;
22982298

builtin/var.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static char *sequence_editor(int ident_flag UNUSED)
4242

4343
static char *pager(int ident_flag UNUSED)
4444
{
45-
const char *pgm = git_pager(1);
45+
const char *pgm = git_pager(the_repository, 1);
4646

4747
if (!pgm)
4848
pgm = "cat";

diff.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7386,6 +7386,6 @@ void setup_diff_pager(struct diff_options *opt)
73867386
* --exit-code" in hooks and other scripts, we do not do so.
73877387
*/
73887388
if (!opt->flags.exit_with_status &&
7389-
check_pager_config("diff") != 0)
7390-
setup_pager();
7389+
check_pager_config(the_repository, "diff") != 0)
7390+
setup_pager(the_repository);
73917391
}

git.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void commit_pager_choice(void)
125125
setenv("GIT_PAGER", "cat", 1);
126126
break;
127127
case 1:
128-
setup_pager();
128+
setup_pager(the_repository);
129129
break;
130130
default:
131131
break;
@@ -136,7 +136,7 @@ void setup_auto_pager(const char *cmd, int def)
136136
{
137137
if (use_pager != -1 || pager_in_use())
138138
return;
139-
use_pager = check_pager_config(cmd);
139+
use_pager = check_pager_config(the_repository, cmd);
140140
if (use_pager == -1)
141141
use_pager = def;
142142
commit_pager_choice();
@@ -462,7 +462,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
462462
precompose_argv_prefix(argc, argv, NULL);
463463
if (use_pager == -1 && run_setup &&
464464
!(p->option & DELAY_PAGER_CONFIG))
465-
use_pager = check_pager_config(p->cmd);
465+
use_pager = check_pager_config(the_repository, p->cmd);
466466
if (use_pager == -1 && p->option & USE_PAGER)
467467
use_pager = 1;
468468
if (run_setup && startup_info->have_repository)
@@ -750,7 +750,7 @@ static void execv_dashed_external(const char **argv)
750750
int status;
751751

752752
if (use_pager == -1 && !is_builtin(argv[0]))
753-
use_pager = check_pager_config(argv[0]);
753+
use_pager = check_pager_config(the_repository, argv[0]);
754754
commit_pager_choice();
755755

756756
strvec_pushf(&cmd.args, "git-%s", argv[0]);

pager.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "config.h"
53
#include "editor.h"
@@ -84,7 +82,7 @@ static int core_pager_config(const char *var, const char *value,
8482
return 0;
8583
}
8684

87-
const char *git_pager(int stdout_is_tty)
85+
const char *git_pager(struct repository *r, int stdout_is_tty)
8886
{
8987
const char *pager;
9088

@@ -94,7 +92,7 @@ const char *git_pager(int stdout_is_tty)
9492
pager = getenv("GIT_PAGER");
9593
if (!pager) {
9694
if (!pager_program)
97-
read_early_config(the_repository,
95+
read_early_config(r,
9896
core_pager_config, NULL);
9997
pager = pager_program;
10098
}
@@ -143,10 +141,10 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
143141
pager_process->trace2_child_class = "pager";
144142
}
145143

146-
void setup_pager(void)
144+
void setup_pager(struct repository *r)
147145
{
148146
static int once = 0;
149-
const char *pager = git_pager(isatty(1));
147+
const char *pager = git_pager(r, isatty(1));
150148

151149
if (!pager)
152150
return;
@@ -293,15 +291,15 @@ static int pager_command_config(const char *var, const char *value,
293291
}
294292

295293
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
296-
int check_pager_config(const char *cmd)
294+
int check_pager_config(struct repository *r, const char *cmd)
297295
{
298296
struct pager_command_config_data data;
299297

300298
data.cmd = cmd;
301299
data.want = -1;
302300
data.value = NULL;
303301

304-
read_early_config(the_repository, pager_command_config, &data);
302+
read_early_config(r, pager_command_config, &data);
305303

306304
if (data.value)
307305
pager_program = data.value;

pager.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
#define PAGER_H
33

44
struct child_process;
5+
struct repository;
56

6-
const char *git_pager(int stdout_is_tty);
7-
void setup_pager(void);
7+
const char *git_pager(struct repository *r, int stdout_is_tty);
8+
void setup_pager(struct repository *r);
89
void wait_for_pager(void);
910
int pager_in_use(void);
1011
int term_columns(void);
1112
void term_clear_line(void);
1213
int decimal_width(uintmax_t);
13-
int check_pager_config(const char *cmd);
14+
int check_pager_config(struct repository *r, const char *cmd);
1415
void prepare_pager_args(struct child_process *, const char *pager);
1516

1617
extern int pager_use_color;

0 commit comments

Comments
 (0)