summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Schneider <larsxschneider@gmail.com>2017-11-29 14:37:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-04 17:38:30 (GMT)
commita64f213d3fa13fa01e582b6734fe7883ed975dc9 (patch)
tree24b1b8f7e95c639ed5cf1c77f6bd6e7753e9a20a
parent5a1f5c3060427375de30d609d72ac032516be4c2 (diff)
downloadgit-a64f213d3fa13fa01e582b6734fe7883ed975dc9.zip
git-a64f213d3fa13fa01e582b6734fe7883ed975dc9.tar.gz
git-a64f213d3fa13fa01e582b6734fe7883ed975dc9.tar.bz2
refactor "dumb" terminal determination
Move the code to detect "dumb" terminals into a single location. This avoids duplicating the terminal detection code yet again in a subsequent commit. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--cache.h1
-rw-r--r--color.c3
-rw-r--r--editor.c9
-rw-r--r--sideband.c5
4 files changed, 11 insertions, 7 deletions
diff --git a/cache.h b/cache.h
index 6440e2b..0217462 100644
--- a/cache.h
+++ b/cache.h
@@ -1438,6 +1438,7 @@ extern const char *ident_default_name(void);
extern const char *ident_default_email(void);
extern const char *git_editor(void);
extern const char *git_pager(int stdout_is_tty);
+extern int is_terminal_dumb(void);
extern int git_ident_config(const char *, const char *, void *);
extern void reset_ident_date(void);
diff --git a/color.c b/color.c
index 9a9261a..d48dd94 100644
--- a/color.c
+++ b/color.c
@@ -329,8 +329,7 @@ static int check_auto_color(void)
if (color_stdout_is_tty < 0)
color_stdout_is_tty = isatty(1);
if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
- char *term = getenv("TERM");
- if (term && strcmp(term, "dumb"))
+ if (!is_terminal_dumb())
return 1;
}
return 0;
diff --git a/editor.c b/editor.c
index 7519ede..c65ea69 100644
--- a/editor.c
+++ b/editor.c
@@ -7,11 +7,16 @@
#define DEFAULT_EDITOR "vi"
#endif
+int is_terminal_dumb(void)
+{
+ const char *terminal = getenv("TERM");
+ return !terminal || !strcmp(terminal, "dumb");
+}
+
const char *git_editor(void)
{
const char *editor = getenv("GIT_EDITOR");
- const char *terminal = getenv("TERM");
- int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
+ int terminal_is_dumb = is_terminal_dumb();
if (!editor && editor_program)
editor = editor_program;
diff --git a/sideband.c b/sideband.c
index 1e4d684..6d7f943 100644
--- a/sideband.c
+++ b/sideband.c
@@ -20,13 +20,12 @@
int recv_sideband(const char *me, int in_stream, int out)
{
- const char *term, *suffix;
+ const char *suffix;
char buf[LARGE_PACKET_MAX + 1];
struct strbuf outbuf = STRBUF_INIT;
int retval = 0;
- term = getenv("TERM");
- if (isatty(2) && term && strcmp(term, "dumb"))
+ if (isatty(2) && !is_terminal_dumb())
suffix = ANSI_SUFFIX;
else
suffix = DUMB_SUFFIX;