git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] cmd_config(): Make a copy of path obtained from git_path()

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 16, 2014, 07:37 UTC
Message-ID
<1416123464-22874-1-git-send-email-mhagger@alum.mit.edu>

The strings returned by git_path() are recycled after a while. So make a copy of the config filename rather than holding onto the return value from git_path().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
This patch is an improvement by itself, and it also eases the merging
to master of my fix for the incorrectly set config file executable
bit [1].
[1] http://thread.gmane.org/gmane.comp.version-control.git/259644
 builtin/config.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 8cc2604..606a3c0 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -568,8 +568,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		}
 	}
 	else if (actions == ACTION_EDIT) {
-		const char *config_file = given_config_source.file ?
-			given_config_source.file : git_path("config");
+		char *config_file;
+
 		check_argc(argc, 0, 0);
 		if (!given_config_source.file && nongit)
 			die("not in a git directory");
@@ -578,6 +578,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		if (given_config_source.blob)
 			die("editing blobs is not supported");
 		git_config(git_default_config, NULL);
+		config_file = xstrdup(given_config_source.file ?
+				      given_config_source.file : git_path("config"));
 		if (use_global_config) {
 			int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
 			if (fd) {
@@ -590,6 +592,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 				die_errno(_("cannot create configuration file %s"), config_file);
 		}
 		launch_editor(config_file, NULL, NULL);
+		free(config_file);
 	}
 	else if (actions == ACTION_SET) {
 		int ret;
-- 
2.1.1
Next: Junio C Hamano
Message 1 of 2 in “cmd_config(): Make a copy of path obtained from git_path()”
  1. cmd_config(): Make a copy of path obtained from git_path()Michael Haggerty, Nov 16, 2014
  2. Junio C HamanoNov 17, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.