1
0
mirror of https://github.com/git/git.git synced 2025-02-06 10:03:06 +00:00

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>
This commit is contained in:
Patrick Steinhardt 2024-12-17 07:43:49 +01:00 committed by Junio C Hamano
parent 1f7e6478dc
commit 59b6131a67
11 changed files with 27 additions and 28 deletions

View File

@ -1464,7 +1464,7 @@ static int patch_update_file(struct add_p_state *s,
if (file_diff->hunk_nr) {
if (rendered_hunk_index != hunk_index) {
if (use_pager) {
setup_pager();
setup_pager(the_repository);
sigchain_push(SIGPIPE, SIG_IGN);
}
render_hunk(s, hunk, 0, colored, &s->buf);

View File

@ -1786,7 +1786,7 @@ static int do_interactive(struct am_state *state)
}
strbuf_release(&msg);
} else if (*reply == 'v' || *reply == 'V') {
const char *pager = git_pager(1);
const char *pager = git_pager(the_repository, 1);
struct child_process cp = CHILD_PROCESS_INIT;
if (!pager)
@ -2246,7 +2246,7 @@ static int show_patch(struct am_state *state, enum resume_type resume_mode)
if (len < 0)
die_errno(_("failed to read '%s'"), patch_path);
setup_pager();
setup_pager(the_repository);
write_in_full(1, sb.buf, sb.len);
strbuf_release(&sb);
return 0;

View File

@ -1202,7 +1202,7 @@ parse_done:
stop_progress(&pi.progress);
if (!incremental)
setup_pager();
setup_pager(the_repository);
else
goto cleanup;

View File

@ -1084,7 +1084,7 @@ int cmd_grep(int argc,
}
if (show_in_pager == default_pager)
show_in_pager = git_pager(1);
show_in_pager = git_pager(the_repository, 1);
if (show_in_pager) {
opt.color = 0;
opt.name_only = 1;
@ -1246,7 +1246,7 @@ int cmd_grep(int argc,
}
if (!show_in_pager && !opt.status_only)
setup_pager();
setup_pager(the_repository);
die_for_incompatible_opt3(!use_index, "--no-index",
untracked, "--untracked",

View File

@ -658,7 +658,7 @@ int cmd_help(int argc,
case HELP_ACTION_ALL:
opt_mode_usage(argc, "--all", help_format);
if (verbose) {
setup_pager();
setup_pager(the_repository);
list_all_cmds_help(show_external_commands,
show_aliases);
return 0;
@ -692,7 +692,7 @@ int cmd_help(int argc,
return 0;
case HELP_ACTION_CONFIG:
opt_mode_usage(argc, "--config", help_format);
setup_pager();
setup_pager(the_repository);
list_config_help(SHOW_CONFIG_HUMAN);
printf("\n%s\n", _("'git help config' for more information"));
return 0;

View File

@ -369,7 +369,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
if (rev->line_level_traverse)
line_log_init(rev, line_cb.prefix, &line_cb.args);
setup_pager();
setup_pager(the_repository);
}
static void cmd_log_init(int argc, const char **argv, const char *prefix,
@ -2292,7 +2292,7 @@ int cmd_format_patch(int argc,
rev.commit_format = CMIT_FMT_MBOXRD;
if (use_stdout) {
setup_pager();
setup_pager(the_repository);
} else if (!rev.diffopt.close_file) {
int saved;

View File

@ -42,7 +42,7 @@ static char *sequence_editor(int ident_flag UNUSED)
static char *pager(int ident_flag UNUSED)
{
const char *pgm = git_pager(1);
const char *pgm = git_pager(the_repository, 1);
if (!pgm)
pgm = "cat";

4
diff.c
View File

@ -7386,6 +7386,6 @@ void setup_diff_pager(struct diff_options *opt)
* --exit-code" in hooks and other scripts, we do not do so.
*/
if (!opt->flags.exit_with_status &&
check_pager_config("diff") != 0)
setup_pager();
check_pager_config(the_repository, "diff") != 0)
setup_pager(the_repository);
}

8
git.c
View File

@ -125,7 +125,7 @@ static void commit_pager_choice(void)
setenv("GIT_PAGER", "cat", 1);
break;
case 1:
setup_pager();
setup_pager(the_repository);
break;
default:
break;
@ -136,7 +136,7 @@ void setup_auto_pager(const char *cmd, int def)
{
if (use_pager != -1 || pager_in_use())
return;
use_pager = check_pager_config(cmd);
use_pager = check_pager_config(the_repository, cmd);
if (use_pager == -1)
use_pager = def;
commit_pager_choice();
@ -462,7 +462,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
precompose_argv_prefix(argc, argv, NULL);
if (use_pager == -1 && run_setup &&
!(p->option & DELAY_PAGER_CONFIG))
use_pager = check_pager_config(p->cmd);
use_pager = check_pager_config(the_repository, p->cmd);
if (use_pager == -1 && p->option & USE_PAGER)
use_pager = 1;
if (run_setup && startup_info->have_repository)
@ -750,7 +750,7 @@ static void execv_dashed_external(const char **argv)
int status;
if (use_pager == -1 && !is_builtin(argv[0]))
use_pager = check_pager_config(argv[0]);
use_pager = check_pager_config(the_repository, argv[0]);
commit_pager_choice();
strvec_pushf(&cmd.args, "git-%s", argv[0]);

14
pager.c
View File

@ -1,5 +1,3 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "editor.h"
@ -84,7 +82,7 @@ static int core_pager_config(const char *var, const char *value,
return 0;
}
const char *git_pager(int stdout_is_tty)
const char *git_pager(struct repository *r, int stdout_is_tty)
{
const char *pager;
@ -94,7 +92,7 @@ const char *git_pager(int stdout_is_tty)
pager = getenv("GIT_PAGER");
if (!pager) {
if (!pager_program)
read_early_config(the_repository,
read_early_config(r,
core_pager_config, NULL);
pager = pager_program;
}
@ -143,10 +141,10 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
pager_process->trace2_child_class = "pager";
}
void setup_pager(void)
void setup_pager(struct repository *r)
{
static int once = 0;
const char *pager = git_pager(isatty(1));
const char *pager = git_pager(r, isatty(1));
if (!pager)
return;
@ -293,7 +291,7 @@ static int pager_command_config(const char *var, const char *value,
}
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
int check_pager_config(const char *cmd)
int check_pager_config(struct repository *r, const char *cmd)
{
struct pager_command_config_data data;
@ -301,7 +299,7 @@ int check_pager_config(const char *cmd)
data.want = -1;
data.value = NULL;
read_early_config(the_repository, pager_command_config, &data);
read_early_config(r, pager_command_config, &data);
if (data.value)
pager_program = data.value;

View File

@ -2,15 +2,16 @@
#define PAGER_H
struct child_process;
struct repository;
const char *git_pager(int stdout_is_tty);
void setup_pager(void);
const char *git_pager(struct repository *r, int stdout_is_tty);
void setup_pager(struct repository *r);
void wait_for_pager(void);
int pager_in_use(void);
int term_columns(void);
void term_clear_line(void);
int decimal_width(uintmax_t);
int check_pager_config(const char *cmd);
int check_pager_config(struct repository *r, const char *cmd);
void prepare_pager_args(struct child_process *, const char *pager);
extern int pager_use_color;