From 4d87b9c5db2590f7616fedfc0a538fc78f528e14 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 20 Jul 2007 13:06:09 +0100 Subject: [PATCH] launch_editor(): Heed GIT_EDITOR and core.editor settings In the commit 'Add GIT_EDITOR environment and core.editor configuration variables', this was done for the shell scripts. Port it over to builtin-tag's version of launch_editor(), which is just about to be refactored into editor.c. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-tag.c | 10 +++++++--- cache.h | 2 ++ config.c | 5 +++++ environment.c | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/builtin-tag.c b/builtin-tag.c index 507f51076..81d37ce90 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -24,7 +24,11 @@ static void launch_editor(const char *path, char **buffer, unsigned long *len) const char *args[3]; int fd; - editor = getenv("VISUAL"); + editor = getenv("GIT_EDITOR"); + if (!editor && editor_program) + editor = editor_program; + if (!editor) + editor = getenv("VISUAL"); if (!editor) editor = getenv("EDITOR"); @@ -249,9 +253,9 @@ static void create_tag(const unsigned char *object, const char *tag, char *message, int sign, unsigned char *result) { enum object_type type; - char header_buf[1024], *buffer; + char header_buf[1024], *buffer = NULL; int header_len, max_size; - unsigned long size; + unsigned long size = 0; type = sha1_object_info(object, NULL); if (type <= 0) diff --git a/cache.h b/cache.h index 53801b808..67b1af16d 100644 --- a/cache.h +++ b/cache.h @@ -560,6 +560,8 @@ extern char *pager_program; extern int pager_in_use; extern int pager_use_color; +extern char *editor_program; + /* base85 */ int decode_85(char *dst, const char *line, int linelen); void encode_85(char *buf, const unsigned char *data, int bytes); diff --git a/config.c b/config.c index f89a61191..103b4fcc6 100644 --- a/config.c +++ b/config.c @@ -426,6 +426,11 @@ int git_default_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.editor")) { + editor_program = xstrdup(value); + return 0; + } + /* Add other config variables here and to Documentation/config.txt. */ return 0; } diff --git a/environment.c b/environment.c index f83fb9e44..35d3f4b59 100644 --- a/environment.c +++ b/environment.c @@ -33,6 +33,7 @@ size_t delta_base_cache_limit = 16 * 1024 * 1024; char *pager_program; int pager_in_use; int pager_use_color = 1; +char *editor_program; int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */ static const char *git_dir; -- 2.26.2