mirror of
https://github.com/git/git.git
synced 2026-03-13 18:33:25 +01:00
Merge branch 'ml/pager' into next
* ml/pager: pager: environment variable GIT_PAGER to override PAGER pager: config variable pager.color Builtins: control the use of pager from the command table. Fix up some fallout from "setup_git_directory()" cleanups Fix double "close()" in ce_compare_data
This commit is contained in:
@@ -116,6 +116,10 @@ apply.whitespace::
|
||||
Tells `git-apply` how to handle whitespaces, in the same way
|
||||
as the '--whitespace' option. See gitlink:git-apply[1].
|
||||
|
||||
pager.color::
|
||||
A boolean to enable/disable colored output when the pager is in
|
||||
use (default is true).
|
||||
|
||||
diff.color::
|
||||
When true (or `always`), always use colors in patch.
|
||||
When false (or `never`), never. When set to `auto`, use
|
||||
|
||||
@@ -627,6 +627,9 @@ git Diffs
|
||||
|
||||
other
|
||||
~~~~~
|
||||
'GIT_PAGER'::
|
||||
This environment variable overrides `$PAGER`.
|
||||
|
||||
'GIT_TRACE'::
|
||||
If this variable is set git will print `trace:` messages on
|
||||
stderr telling about alias expansion, built-in command
|
||||
|
||||
@@ -34,7 +34,6 @@ static int cmd_log_walk(struct rev_info *rev)
|
||||
struct commit *commit;
|
||||
|
||||
prepare_revision_walk(rev);
|
||||
setup_pager();
|
||||
while ((commit = get_revision(rev)) != NULL) {
|
||||
log_tree_commit(rev, commit);
|
||||
free(commit->buffer);
|
||||
|
||||
@@ -24,7 +24,6 @@ static int show_valid_bit = 0;
|
||||
static int line_terminator = '\n';
|
||||
|
||||
static int prefix_len = 0, prefix_offset = 0;
|
||||
static const char *prefix = NULL;
|
||||
static const char **pathspec = NULL;
|
||||
static int error_unmatch = 0;
|
||||
static char *ps_matched = NULL;
|
||||
@@ -207,7 +206,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
|
||||
}
|
||||
}
|
||||
|
||||
static void show_files(struct dir_struct *dir)
|
||||
static void show_files(struct dir_struct *dir, const char *prefix)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -253,7 +252,7 @@ static void show_files(struct dir_struct *dir)
|
||||
/*
|
||||
* Prune the index to only contain stuff starting with "prefix"
|
||||
*/
|
||||
static void prune_cache(void)
|
||||
static void prune_cache(const char *prefix)
|
||||
{
|
||||
int pos = cache_name_pos(prefix, prefix_len);
|
||||
unsigned int first, last;
|
||||
@@ -276,7 +275,7 @@ static void prune_cache(void)
|
||||
active_nr = last;
|
||||
}
|
||||
|
||||
static void verify_pathspec(void)
|
||||
static const char *verify_pathspec(const char *prefix)
|
||||
{
|
||||
const char **p, *n, *prev;
|
||||
char *real_prefix;
|
||||
@@ -313,7 +312,7 @@ static void verify_pathspec(void)
|
||||
memcpy(real_prefix, prev, max);
|
||||
real_prefix[max] = 0;
|
||||
}
|
||||
prefix = real_prefix;
|
||||
return real_prefix;
|
||||
}
|
||||
|
||||
static const char ls_files_usage[] =
|
||||
@@ -453,7 +452,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||
|
||||
/* Verify that the pathspec matches the prefix */
|
||||
if (pathspec)
|
||||
verify_pathspec();
|
||||
prefix = verify_pathspec(prefix);
|
||||
|
||||
/* Treat unmatching pathspec elements as errors */
|
||||
if (pathspec && error_unmatch) {
|
||||
@@ -476,8 +475,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||
|
||||
read_cache();
|
||||
if (prefix)
|
||||
prune_cache();
|
||||
show_files(&dir);
|
||||
prune_cache(prefix);
|
||||
show_files(&dir, prefix);
|
||||
|
||||
if (ps_matched) {
|
||||
/* We need to make sure all pathspec matched otherwise
|
||||
|
||||
1
cache.h
1
cache.h
@@ -392,6 +392,7 @@ extern int receive_keep_pack(int fd[2], const char *me, int quiet, int);
|
||||
/* pager.c */
|
||||
extern void setup_pager(void);
|
||||
extern int pager_in_use;
|
||||
extern int pager_use_color;
|
||||
|
||||
/* base85 */
|
||||
int decode_85(char *dst, char *line, int linelen);
|
||||
|
||||
5
config.c
5
config.c
@@ -309,6 +309,11 @@ int git_default_config(const char *var, const char *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(var, "pager.color")) {
|
||||
pager_use_color = git_config_bool(var,value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add other config variables here and to Documentation/config.txt. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
2
diff.c
2
diff.c
@@ -175,7 +175,7 @@ int git_diff_ui_config(const char *var, const char *value)
|
||||
diff_use_color_default = 1; /* bool */
|
||||
else if (!strcasecmp(value, "auto")) {
|
||||
diff_use_color_default = 0;
|
||||
if (isatty(1) || pager_in_use) {
|
||||
if (isatty(1) || (pager_in_use && pager_use_color)) {
|
||||
char *term = getenv("TERM");
|
||||
if (term && strcmp(term, "dumb"))
|
||||
diff_use_color_default = 1;
|
||||
|
||||
@@ -23,6 +23,7 @@ int shared_repository = PERM_UMASK;
|
||||
const char *apply_default_whitespace = NULL;
|
||||
int zlib_compression_level = Z_DEFAULT_COMPRESSION;
|
||||
int pager_in_use;
|
||||
int pager_use_color = 1;
|
||||
|
||||
static int dyn_git_object_dir, dyn_git_index_file, dyn_git_graft_file;
|
||||
static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
|
||||
|
||||
13
git.c
13
git.c
@@ -211,6 +211,7 @@ static int handle_alias(int *argcp, const char ***argv)
|
||||
const char git_version_string[] = GIT_VERSION;
|
||||
|
||||
#define NEEDS_PREFIX 1
|
||||
#define USE_PAGER 2
|
||||
|
||||
static void handle_internal_command(int argc, const char **argv, char **envp)
|
||||
{
|
||||
@@ -218,13 +219,13 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
|
||||
static struct cmd_struct {
|
||||
const char *cmd;
|
||||
int (*fn)(int, const char **, const char *);
|
||||
int prefix;
|
||||
int option;
|
||||
} commands[] = {
|
||||
{ "version", cmd_version },
|
||||
{ "help", cmd_help },
|
||||
{ "log", cmd_log, NEEDS_PREFIX },
|
||||
{ "whatchanged", cmd_whatchanged, NEEDS_PREFIX },
|
||||
{ "show", cmd_show, NEEDS_PREFIX },
|
||||
{ "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
|
||||
{ "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
|
||||
{ "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
|
||||
{ "push", cmd_push },
|
||||
{ "format-patch", cmd_format_patch, NEEDS_PREFIX },
|
||||
{ "count-objects", cmd_count_objects },
|
||||
@@ -275,8 +276,10 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
|
||||
continue;
|
||||
|
||||
prefix = NULL;
|
||||
if (p->prefix)
|
||||
if (p->option & NEEDS_PREFIX)
|
||||
prefix = setup_git_directory();
|
||||
if (p->option & USE_PAGER)
|
||||
setup_pager();
|
||||
if (getenv("GIT_TRACE")) {
|
||||
int i;
|
||||
fprintf(stderr, "trace: built-in: git");
|
||||
|
||||
4
pager.c
4
pager.c
@@ -15,10 +15,12 @@ void setup_pager(void)
|
||||
{
|
||||
pid_t pid;
|
||||
int fd[2];
|
||||
const char *pager = getenv("PAGER");
|
||||
const char *pager = getenv("GIT_PAGER");
|
||||
|
||||
if (!isatty(1))
|
||||
return;
|
||||
if (!pager)
|
||||
pager = getenv("PAGER");
|
||||
if (!pager)
|
||||
pager = "less";
|
||||
else if (!*pager || !strcmp(pager, "cat"))
|
||||
|
||||
@@ -61,7 +61,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
|
||||
unsigned char sha1[20];
|
||||
if (!index_fd(sha1, fd, st, 0, NULL))
|
||||
match = memcmp(sha1, ce->sha1, 20);
|
||||
close(fd);
|
||||
/* index_fd() closed the file descriptor already */
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user