Skip to content

Commit 056d6d4

Browse files
author
Junio C Hamano
committed
Merge branch 'ml/pager'
2 parents 0225de8 + aa086eb commit 056d6d4

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ apply.whitespace::
116116
Tells `git-apply` how to handle whitespaces, in the same way
117117
as the '--whitespace' option. See gitlink:git-apply[1].
118118

119+
pager.color::
120+
A boolean to enable/disable colored output when the pager is in
121+
use (default is true).
122+
119123
diff.color::
120124
When true (or `always`), always use colors in patch.
121125
When false (or `never`), never. When set to `auto`, use

builtin-log.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ static int cmd_log_walk(struct rev_info *rev)
3434
struct commit *commit;
3535

3636
prepare_revision_walk(rev);
37-
setup_pager();
3837
while ((commit = get_revision(rev)) != NULL) {
3938
log_tree_commit(rev, commit);
4039
free(commit->buffer);

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ extern int receive_keep_pack(int fd[2], const char *me, int quiet, int);
386386
/* pager.c */
387387
extern void setup_pager(void);
388388
extern int pager_in_use;
389+
extern int pager_use_color;
389390

390391
/* base85 */
391392
int decode_85(char *dst, char *line, int linelen);

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ int git_default_config(const char *var, const char *value)
309309
return 0;
310310
}
311311

312+
if (!strcmp(var, "pager.color")) {
313+
pager_use_color = git_config_bool(var,value);
314+
return 0;
315+
}
316+
312317
/* Add other config variables here and to Documentation/config.txt. */
313318
return 0;
314319
}

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int git_diff_ui_config(const char *var, const char *value)
175175
diff_use_color_default = 1; /* bool */
176176
else if (!strcasecmp(value, "auto")) {
177177
diff_use_color_default = 0;
178-
if (isatty(1) || pager_in_use) {
178+
if (isatty(1) || (pager_in_use && pager_use_color)) {
179179
char *term = getenv("TERM");
180180
if (term && strcmp(term, "dumb"))
181181
diff_use_color_default = 1;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int shared_repository = PERM_UMASK;
2323
const char *apply_default_whitespace = NULL;
2424
int zlib_compression_level = Z_DEFAULT_COMPRESSION;
2525
int pager_in_use;
26+
int pager_use_color = 1;
2627

2728
static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
2829
*git_graft_file;

git.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,21 @@ static int handle_alias(int *argcp, const char ***argv)
211211
const char git_version_string[] = GIT_VERSION;
212212

213213
#define NEEDS_PREFIX 1
214+
#define USE_PAGER 2
214215

215216
static void handle_internal_command(int argc, const char **argv, char **envp)
216217
{
217218
const char *cmd = argv[0];
218219
static struct cmd_struct {
219220
const char *cmd;
220221
int (*fn)(int, const char **, const char *);
221-
int prefix;
222+
int option;
222223
} commands[] = {
223224
{ "version", cmd_version },
224225
{ "help", cmd_help },
225-
{ "log", cmd_log, NEEDS_PREFIX },
226-
{ "whatchanged", cmd_whatchanged, NEEDS_PREFIX },
227-
{ "show", cmd_show, NEEDS_PREFIX },
226+
{ "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
227+
{ "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
228+
{ "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
228229
{ "push", cmd_push },
229230
{ "format-patch", cmd_format_patch, NEEDS_PREFIX },
230231
{ "count-objects", cmd_count_objects },
@@ -275,8 +276,10 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
275276
continue;
276277

277278
prefix = NULL;
278-
if (p->prefix)
279+
if (p->option & NEEDS_PREFIX)
279280
prefix = setup_git_directory();
281+
if (p->option & USE_PAGER)
282+
setup_pager();
280283
if (getenv("GIT_TRACE")) {
281284
int i;
282285
fprintf(stderr, "trace: built-in: git");

0 commit comments

Comments
 (0)