[PATCH] Have git-revert, git-cherry-pick use $GIT_DIR/COMMIT_MSG instead of ./.msg.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 04, 2007 at 05:28:21PM +0200, Alex Riesen wrote:
> On 5/4/07, Gerrit Pape <pape@xxxxxxxxxxx> wrote:
> >git-revert and git-cherry-pick left behind the commit message file ./.msg,
> >have them use the -f option to git-commit to properly cleanup the
> >automatically created file.
>
> Could we also have the files in $GIT_DIR instead of in working directory?

Yes, .git/COMMIT_MSG is already used by git-commit and git-svn, and can be
used here too.

Signed-off-by: Gerrit Pape <pape@xxxxxxxxxxx>
---
 builtin-revert.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/builtin-revert.c b/builtin-revert.c
index 9acdf47..5aff283 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -126,14 +126,15 @@ char *get_encoding(const char *message)
 	return NULL;
 }
 
-struct lock_file msg_file;
+static const char* msg_file;
+struct lock_file msg_file_lock;
 static int msg_fd;
 
 static void add_to_msg(const char *string)
 {
 	int len = strlen(string);
 	if (write_in_full(msg_fd, string, len) < 0)
-		die ("Could not write to .msg");
+		die ("Could not write to %s", msg_file);
 }
 
 static void add_message_to_msg(const char *message)
@@ -280,7 +281,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 	 * reverse of it if we are revert.
 	 */
 
-	msg_fd = hold_lock_file_for_update(&msg_file, ".msg", 1);
+	msg_file = git_path("COMMIT_MSG");
+	msg_fd = hold_lock_file_for_update(&msg_file_lock, msg_file, 1);
 
 	encoding = get_encoding(message);
 	if (!encoding)
@@ -344,11 +346,11 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 					i++;
 			}
 		}
-		if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
-			die ("Error wrapping up .msg");
+		if (close(msg_fd) || commit_lock_file(&msg_file_lock) < 0)
+			die ("Error wrapping up %s", msg_file);
 		unlink(target);
-		if (rename(".msg", target))
-			die ("Could not move .msg to %s", target);
+		if (rename(msg_file, target))
+			die ("Could not move %s to %s", msg_file, target);
 		fprintf(stderr, "Automatic %s failed.  "
 			"After resolving the conflicts,\n"
 			"mark the corrected paths with 'git-add <paths>'\n"
@@ -361,8 +363,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 		}
 		exit(1);
 	}
-	if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
-		die ("Error wrapping up .msg");
+	if (close(msg_fd) || commit_lock_file(&msg_file_lock) < 0)
+		die ("Error wrapping up %s", msg_file);
 	fprintf(stderr, "Finished one %s.\n", me);
 
 	/*
@@ -376,10 +378,10 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 
 	if (!no_commit) {
 		if (edit)
-			return execl_git_cmd("commit", "-n", "-f", ".msg",
+			return execl_git_cmd("commit", "-n", "-f", msg_file,
 				"-e", NULL);
 		else
-			return execl_git_cmd("commit", "-n", "-f", ".msg",
+			return execl_git_cmd("commit", "-n", "-f", msg_file,
 				NULL);
 	}
 	if (reencoded_message)
-- 
1.5.1.2

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]