@@ -9,6 +9,43 @@ const char git_usage_string[] =
99const char git_more_info_string [] =
1010 "See 'git help COMMAND' for more information on a specific command." ;
1111
12+ static int use_pager = -1 ;
13+ struct pager_config {
14+ const char * cmd ;
15+ int val ;
16+ };
17+
18+ static int pager_command_config (const char * var , const char * value , void * data )
19+ {
20+ struct pager_config * c = data ;
21+ if (!prefixcmp (var , "pager." ) && !strcmp (var + 6 , c -> cmd ))
22+ c -> val = git_config_bool (var , value );
23+ return 0 ;
24+ }
25+
26+ /* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
27+ int check_pager_config (const char * cmd )
28+ {
29+ struct pager_config c ;
30+ c .cmd = cmd ;
31+ c .val = -1 ;
32+ git_config (pager_command_config , & c );
33+ return c .val ;
34+ }
35+
36+ static void commit_pager_choice (void ) {
37+ switch (use_pager ) {
38+ case 0 :
39+ setenv ("GIT_PAGER" , "cat" , 1 );
40+ break ;
41+ case 1 :
42+ setup_pager ();
43+ break ;
44+ default :
45+ break ;
46+ }
47+ }
48+
1249static int handle_options (const char * * * argv , int * argc , int * envchanged )
1350{
1451 int handled = 0 ;
@@ -38,9 +75,9 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
3875 exit (0 );
3976 }
4077 } else if (!strcmp (cmd , "-p" ) || !strcmp (cmd , "--paginate" )) {
41- setup_pager () ;
78+ use_pager = 1 ;
4279 } else if (!strcmp (cmd , "--no-pager" )) {
43- setenv ( "GIT_PAGER" , "cat" , 1 ) ;
80+ use_pager = 0 ;
4481 if (envchanged )
4582 * envchanged = 1 ;
4683 } else if (!strcmp (cmd , "--git-dir" )) {
@@ -242,8 +279,13 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
242279 prefix = NULL ;
243280 if (p -> option & RUN_SETUP )
244281 prefix = setup_git_directory ();
245- if (p -> option & USE_PAGER )
246- setup_pager ();
282+
283+ if (use_pager == -1 && p -> option & RUN_SETUP )
284+ use_pager = check_pager_config (p -> cmd );
285+ if (use_pager == -1 && p -> option & USE_PAGER )
286+ use_pager = 1 ;
287+ commit_pager_choice ();
288+
247289 if (p -> option & NEED_WORK_TREE )
248290 setup_work_tree ();
249291
@@ -466,6 +508,7 @@ int main(int argc, const char **argv)
466508 argv ++ ;
467509 argc -- ;
468510 handle_options (& argv , & argc , NULL );
511+ commit_pager_choice ();
469512 if (argc > 0 ) {
470513 if (!prefixcmp (argv [0 ], "--" ))
471514 argv [0 ] += 2 ;
0 commit comments