environment: move pager_program into repo_config_values

The 'pager_program' variable is currently defined as a file-scoped static string in pager.c. Move it into 'struct repo_config_values'. The configuration parsing logic remains strictly within pager.c to respect subsystem boundaries. The read/write operations are simply redirected to the repository-specific structure using 'repo_config_values()'. All current callers indeed pass 'the_repository', so this new enforcement does not harm them. Similar to the recent editor_program migration, no standalone getter is introduced to keep the code minimal. The dynamically allocated memory is now managed by 'repo_config_values_clear()'. On top of that, fix memory leaks in pager.c while we are at it. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tian Yuchen committed Jul 14, 2026 at 11:25 UTC e57125d804f29b8a6c70a47a03037cf31ef153d7
3 files changed +26 -9
environment.c
+2
@@ -725,6 +725,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
725 cfg->attributes_file = NULL;
726 cfg->excludes_file = NULL;
727 cfg->editor_program = NULL;
728 + cfg->pager_program = NULL;
729 cfg->apply_sparse_checkout = 0;
730 cfg->branch_track = BRANCH_TRACK_REMOTE;
731 cfg->trust_ctime = 1;
@@ -742,4 +743,5 @@ void repo_config_values_clear(struct repo_config_values *cfg)
743 FREE_AND_NULL(cfg->attributes_file);
744 FREE_AND_NULL(cfg->excludes_file);
745 FREE_AND_NULL(cfg->editor_program);
746 + FREE_AND_NULL(cfg->pager_program);
747 }
environment.h
+1
@@ -92,6 +92,7 @@ struct repo_config_values {
92 char *attributes_file;
93 char *excludes_file;
94 char *editor_program;
95 + char *pager_program;
96 int apply_sparse_checkout;
97 int trust_ctime;
98 int check_stat;
pager.c
+23 -9
@@ -5,6 +5,8 @@
5 #include "run-command.h"
6 #include "sigchain.h"
7 #include "alias.h"
8 +#include "repository.h"
9 +#include "environment.h"
10
11 int pager_use_color = 1;
12
@@ -13,7 +15,6 @@ int pager_use_color = 1;
15 #endif
16
17 static struct child_process pager_process;
16 -static char *pager_program;
18 static int old_fd1 = -1, old_fd2 = -1;
19
20 /* Is the value coming back from term_columns() just a guess? */
@@ -75,10 +76,17 @@ static void wait_for_pager_signal(int signo)
76
77 static int core_pager_config(const char *var, const char *value,
78 const struct config_context *ctx UNUSED,
78 - void *data UNUSED)
79 + void *data)
80 {
80 - if (!strcmp(var, "core.pager"))
81 - return git_config_string(&pager_program, var, value);
81 + struct repository *r = data;
82 +
83 + if (!strcmp(var, "core.pager")) {
84 + struct repo_config_values *cfg = repo_config_values(r);
85 +
86 + FREE_AND_NULL(cfg->pager_program);
87 + return git_config_string(&cfg->pager_program, var, value);
88 + }
89 +
90 return 0;
91 }
92
@@ -91,10 +99,12 @@ const char *git_pager(struct repository *r, int stdout_is_tty)
99
100 pager = getenv("GIT_PAGER");
101 if (!pager) {
94 - if (!pager_program)
102 + struct repo_config_values *cfg = repo_config_values(r);
103 +
104 + if (!cfg->pager_program)
105 read_early_config(r,
96 - core_pager_config, NULL);
97 - pager = pager_program;
106 + core_pager_config, r);
107 + pager = cfg->pager_program;
108 }
109 if (!pager)
110 pager = getenv("PAGER");
@@ -302,7 +312,11 @@ int check_pager_config(struct repository *r, const char *cmd)
312
313 read_early_config(r, pager_command_config, &data);
314
305 - if (data.value)
306 - pager_program = data.value;
315 + if (data.value) {
316 + struct repo_config_values *cfg = repo_config_values(r);
317 +
318 + free(cfg->pager_program);
319 + cfg->pager_program = data.value;
320 + }
321 return data.want;
322 }