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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 17, 2024 at 07:43 UTC
59b6131a677b0b45fb7fd54ba60dbf689b0a1797
11 files changed
+27
-28
add-patch.c
+1
-1
@@ -1464,7 +1464,7 @@ static int patch_update_file(struct add_p_state *s,
1464
if (file_diff->hunk_nr) {
1465
if (rendered_hunk_index != hunk_index) {
1466
if (use_pager) {
1467
- setup_pager();
1467
+ setup_pager(the_repository);
1468
sigchain_push(SIGPIPE, SIG_IGN);
1469
}
1470
render_hunk(s, hunk, 0, colored, &s->buf);
builtin/am.c
+2
-2
@@ -1786,7 +1786,7 @@ static int do_interactive(struct am_state *state)
1786
}
1787
strbuf_release(&msg);
1788
} else if (*reply == 'v' || *reply == 'V') {
1789
- const char *pager = git_pager(1);
1789
+ const char *pager = git_pager(the_repository, 1);
1790
struct child_process cp = CHILD_PROCESS_INIT;
1791
1792
if (!pager)
@@ -2246,7 +2246,7 @@ static int show_patch(struct am_state *state, enum resume_type resume_mode)
2246
if (len < 0)
2247
die_errno(_("failed to read '%s'"), patch_path);
2248
2249
- setup_pager();
2249
+ setup_pager(the_repository);
2250
write_in_full(1, sb.buf, sb.len);
2251
strbuf_release(&sb);
2252
return 0;
builtin/blame.c
+1
-1
@@ -1202,7 +1202,7 @@ parse_done:
1202
stop_progress(&pi.progress);
1203
1204
if (!incremental)
1205
- setup_pager();
1205
+ setup_pager(the_repository);
1206
else
1207
goto cleanup;
1208
builtin/grep.c
+2
-2
@@ -1084,7 +1084,7 @@ int cmd_grep(int argc,
1084
}
1085
1086
if (show_in_pager == default_pager)
1087
- show_in_pager = git_pager(1);
1087
+ show_in_pager = git_pager(the_repository, 1);
1088
if (show_in_pager) {
1089
opt.color = 0;
1090
opt.name_only = 1;
@@ -1246,7 +1246,7 @@ int cmd_grep(int argc,
1246
}
1247
1248
if (!show_in_pager && !opt.status_only)
1249
- setup_pager();
1249
+ setup_pager(the_repository);
1250
1251
die_for_incompatible_opt3(!use_index, "--no-index",
1252
untracked, "--untracked",
builtin/help.c
+2
-2
@@ -658,7 +658,7 @@ int cmd_help(int argc,
658
case HELP_ACTION_ALL:
659
opt_mode_usage(argc, "--all", help_format);
660
if (verbose) {
661
- setup_pager();
661
+ setup_pager(the_repository);
662
list_all_cmds_help(show_external_commands,
663
show_aliases);
664
return 0;
@@ -692,7 +692,7 @@ int cmd_help(int argc,
692
return 0;
693
case HELP_ACTION_CONFIG:
694
opt_mode_usage(argc, "--config", help_format);
695
- setup_pager();
695
+ setup_pager(the_repository);
696
list_config_help(SHOW_CONFIG_HUMAN);
697
printf("\n%s\n", _("'git help config' for more information"));
698
return 0;
builtin/log.c
+2
-2
@@ -369,7 +369,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
369
if (rev->line_level_traverse)
370
line_log_init(rev, line_cb.prefix, &line_cb.args);
371
372
- setup_pager();
372
+ setup_pager(the_repository);
373
}
374
375
static void cmd_log_init(int argc, const char **argv, const char *prefix,
@@ -2292,7 +2292,7 @@ int cmd_format_patch(int argc,
2292
rev.commit_format = CMIT_FMT_MBOXRD;
2293
2294
if (use_stdout) {
2295
- setup_pager();
2295
+ setup_pager(the_repository);
2296
} else if (!rev.diffopt.close_file) {
2297
int saved;
2298
builtin/var.c
+1
-1
@@ -42,7 +42,7 @@ static char *sequence_editor(int ident_flag UNUSED)
42
43
static char *pager(int ident_flag UNUSED)
44
{
45
- const char *pgm = git_pager(1);
45
+ const char *pgm = git_pager(the_repository, 1);
46
47
if (!pgm)
48
pgm = "cat";
diff.c
+2
-2
@@ -7386,6 +7386,6 @@ void setup_diff_pager(struct diff_options *opt)
7386
* --exit-code" in hooks and other scripts, we do not do so.
7387
*/
7388
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);
7391
}
git.c
+4
-4
@@ -125,7 +125,7 @@ static void commit_pager_choice(void)
125
setenv("GIT_PAGER", "cat", 1);
126
break;
127
case 1:
128
- setup_pager();
128
+ setup_pager(the_repository);
129
break;
130
default:
131
break;
@@ -136,7 +136,7 @@ void setup_auto_pager(const char *cmd, int def)
136
{
137
if (use_pager != -1 || pager_in_use())
138
return;
139
- use_pager = check_pager_config(cmd);
139
+ use_pager = check_pager_config(the_repository, cmd);
140
if (use_pager == -1)
141
use_pager = def;
142
commit_pager_choice();
@@ -462,7 +462,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
462
precompose_argv_prefix(argc, argv, NULL);
463
if (use_pager == -1 && run_setup &&
464
!(p->option & DELAY_PAGER_CONFIG))
465
- use_pager = check_pager_config(p->cmd);
465
+ use_pager = check_pager_config(the_repository, p->cmd);
466
if (use_pager == -1 && p->option & USE_PAGER)
467
use_pager = 1;
468
if (run_setup && startup_info->have_repository)
@@ -750,7 +750,7 @@ static void execv_dashed_external(const char **argv)
750
int status;
751
752
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]);
754
commit_pager_choice();
755
756
strvec_pushf(&cmd.args, "git-%s", argv[0]);
pager.c
+6
-8
@@ -1,5 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
2
-
1
#include "git-compat-util.h"
2
#include "config.h"
3
#include "editor.h"
@@ -84,7 +82,7 @@ static int core_pager_config(const char *var, const char *value,
82
return 0;
83
}
84
87
-const char *git_pager(int stdout_is_tty)
85
+const char *git_pager(struct repository *r, int stdout_is_tty)
86
{
87
const char *pager;
88
@@ -94,7 +92,7 @@ const char *git_pager(int stdout_is_tty)
92
pager = getenv("GIT_PAGER");
93
if (!pager) {
94
if (!pager_program)
97
- read_early_config(the_repository,
95
+ read_early_config(r,
96
core_pager_config, NULL);
97
pager = pager_program;
98
}
@@ -143,10 +141,10 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
141
pager_process->trace2_child_class = "pager";
142
}
143
146
-void setup_pager(void)
144
+void setup_pager(struct repository *r)
145
{
146
static int once = 0;
149
- const char *pager = git_pager(isatty(1));
147
+ const char *pager = git_pager(r, isatty(1));
148
149
if (!pager)
150
return;
@@ -293,7 +291,7 @@ static int pager_command_config(const char *var, const char *value,
291
}
292
293
/* 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)
295
{
296
struct pager_command_config_data data;
297
@@ -301,7 +299,7 @@ int check_pager_config(const char *cmd)
299
data.want = -1;
300
data.value = NULL;
301
304
- read_early_config(the_repository, pager_command_config, &data);
302
+ read_early_config(r, pager_command_config, &data);
303
304
if (data.value)
305
pager_program = data.value;
pager.h
+4
-3
@@ -2,15 +2,16 @@
2
#define PAGER_H
3
4
struct child_process;
5
+struct repository;
6
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);
9
void wait_for_pager(void);
10
int pager_in_use(void);
11
int term_columns(void);
12
void term_clear_line(void);
13
int decimal_width(uintmax_t);
13
-int check_pager_config(const char *cmd);
14
+int check_pager_config(struct repository *r, const char *cmd);
15
void prepare_pager_args(struct child_process *, const char *pager);
16
17
extern int pager_use_color;