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

[PATCH] builtin/commit.c: memoize git-path for COMMIT_EDITMSG

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
May 23, 2016, 18:16 UTC
Message-ID
<1464027390-1512-1-git-send-email-pranit.bauva@gmail.com>

This is a follow up commit for f932729c (memoize common git-path "constant" files, 10-Aug-2015).

It serves two purposes:
  1. It reduces the number of calls to git_path() .
  2. It serves the benefits of using GIT_PATH_FUNC as mentioned in the
     commit message of f932729c.
Mentored-by: Lars Schneider <larsxschneider@gmail.com>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
---
 builtin/commit.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 391126e..ffa242c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -92,8 +92,10 @@ N_("If you wish to skip this commit, use:\n"
 "Then \"git cherry-pick --continue\" will resume cherry-picking\n"
 "the remaining commits.\n");
 
+static GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
+
 static const char *use_message_buffer;
-static const char commit_editmsg[] = "COMMIT_EDITMSG";
+static const char commit_editmsg_path[] = git_path_commit_editmsg();
 static struct lock_file index_lock; /* real index */
 static struct lock_file false_lock; /* used only for partial commits */
 static enum {
@@ -771,9 +773,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		hook_arg2 = "";
 	}
 
-	s->fp = fopen_for_writing(git_path(commit_editmsg));
+	s->fp = fopen_for_writing(commit_editmsg_path);
 	if (s->fp == NULL)
-		die_errno(_("could not open '%s'"), git_path(commit_editmsg));
+		die_errno(_("could not open '%s'"), commit_editmsg_path);
 
 	/* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
 	old_display_comment_prefix = s->display_comment_prefix;
@@ -950,7 +952,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	}
 
 	if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
-			    git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
+			    commit_editmsg_path, hook_arg1, hook_arg2, NULL))
 		return 0;
 
 	if (use_editor) {
@@ -958,7 +960,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		const char *env[2] = { NULL };
 		env[0] =  index;
 		snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
-		if (launch_editor(git_path(commit_editmsg), NULL, env)) {
+		if (launch_editor(commit_editmsg_path, NULL, env)) {
 			fprintf(stderr,
 			_("Please supply the message using either -m or -F option.\n"));
 			exit(1);
@@ -966,7 +968,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	}
 
 	if (!no_verify &&
-	    run_commit_hook(use_editor, index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
+	    run_commit_hook(use_editor, index_file, "commit-msg", commit_editmsg_path, NULL)) {
 		return 0;
 	}
 
@@ -1728,7 +1730,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
 	/* Finally, get the commit message */
 	strbuf_reset(&sb);
-	if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
+	if (strbuf_read_file(&sb, commit_editmsg_path, 0) < 0) {
 		int saved_errno = errno;
 		rollback_index_files();
 		die(_("could not read commit message: %s"), strerror(saved_errno));
-- 
2.8.2
Next: Junio C Hamano
Message 1 of 12 in “builtin/commit.c: memoize git-path for COMMIT_EDITMSG”
  1. builtin/commit.c: memoize git-path for COMMIT_EDITMSGPranit Bauva, May 23, 2016
  2. Junio C HamanoMay 23, 2016
  3. Pranit BauvaMay 24, 2016
  4. Pranit BauvaMay 24, 2016
  5. Matthieu MoyMay 24, 2016
  6. Pranit BauvaMay 24, 2016
  7. Junio C HamanoMay 24, 2016
  8. builtin/commit.c: memoize git-path for COMMIT_EDITMSGPranit Bauva, May 24, 2016
  9. Pranit BauvaJun 7, 2016
  10. Jeff KingJun 9, 2016
  11. Pranit BauvaJun 9, 2016
  12. Junio C HamanoJun 9, 2016

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.