{"thread":{"id":"8023","subject":"[PATCH] Use .git/MERGE_MSG in cherry-pick/revert","startedAt":"2007-05-08T01:54:47Z","lastAt":"2007-05-08T07:20:56Z","messageCount":2,"participants":["Shawn O. Pearce","Gerrit Pape"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"41387","messageId":"20070508015447.GA22253@spearce.org","threadId":"8023","inReplyTo":null,"subject":"[PATCH] Use .git/MERGE_MSG in cherry-pick/revert","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-05-08T01:54:47Z","receivedAt":"2007-05-08T01:54:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Rather than storing the temporary commit message data in .msg (in\nthe working tree) we now store the message data in .git/MERGE_MSG.\n\nBy storing the message in the .git/ directory we are sure we will\nnever have a collision with a user file, should a project actually\nhave a \".msg\" file in their top level tree.  We also don't need to\nworry about leaving this stale file behind during a `reset --hard`\nand have it show up in the output of status.\n\nWe are using .git/MERGE_MSG here to store the temporary message as\nit is an already established convention between git-merge, git-am\nand git-rebase that git-commit will default the user's edit buffer\nto the contents of .git/MERGE_MSG.  If the user is going to need\nto resolve this commit or wants to edit the message on their own\nprepping that file with the desired message \"just works\".\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n Resend of earlier patch, but with proper commit message.  ;-)\n\n builtin-revert.c |   17 ++++++-----------\n 1 files changed, 6 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin-revert.c b/builtin-revert.c\nindex 4ba0ee6..67c13a3 100644\n--- a/builtin-revert.c\n+++ b/builtin-revert.c\n@@ -237,6 +237,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \tint i;\n \tchar *oneline, *reencoded_message = NULL;\n \tconst char *message, *encoding;\n+\tconst char *defmsg = git_path(\"MERGE_MSG\");\n \n \tgit_config(git_default_config);\n \tme = action == REVERT ? \"revert\" : \"cherry-pick\";\n@@ -280,7 +281,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t * reverse of it if we are revert.\n \t */\n \n-\tmsg_fd = hold_lock_file_for_update(&msg_file, \".msg\", 1);\n+\tmsg_fd = hold_lock_file_for_update(&msg_file, defmsg, 1);\n \n \tencoding = get_encoding(message);\n \tif (!encoding)\n@@ -330,7 +331,6 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t\t\t\tsha1_to_hex(head), \"HEAD\",\n \t\t\t\tsha1_to_hex(next->object.sha1), oneline) ||\n \t\t\twrite_tree(head, 0, NULL)) {\n-\t\tconst char *target = git_path(\"MERGE_MSG\");\n \t\tadd_to_msg(\"\\nConflicts:\\n\\n\");\n \t\tread_cache();\n \t\tfor (i = 0; i < active_nr;) {\n@@ -345,10 +345,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t\t\t}\n \t\t}\n \t\tif (close(msg_fd) || commit_lock_file(&msg_file) < 0)\n-\t\t\tdie (\"Error wrapping up .msg\");\n-\t\tunlink(target);\n-\t\tif (rename(\".msg\", target))\n-\t\t\tdie (\"Could not move .msg to %s\", target);\n+\t\t\tdie (\"Error wrapping up %s\", defmsg);\n \t\tfprintf(stderr, \"Automatic %s failed.  \"\n \t\t\t\"After resolving the conflicts,\\n\"\n \t\t\t\"mark the corrected paths with 'git-add <paths>'\\n\"\n@@ -362,7 +359,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t\texit(1);\n \t}\n \tif (close(msg_fd) || commit_lock_file(&msg_file) < 0)\n-\t\tdie (\"Error wrapping up .msg\");\n+\t\tdie (\"Error wrapping up %s\", defmsg);\n \tfprintf(stderr, \"Finished one %s.\\n\", me);\n \n \t/*\n@@ -376,11 +373,9 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \n \tif (!no_commit) {\n \t\tif (edit)\n-\t\t\treturn execl_git_cmd(\"commit\", \"-n\", \"-F\", \".msg\",\n-\t\t\t\t\"-e\", NULL);\n+\t\t\treturn execl_git_cmd(\"commit\", \"-n\", NULL);\n \t\telse\n-\t\t\treturn execl_git_cmd(\"commit\", \"-n\", \"-F\", \".msg\",\n-\t\t\t\tNULL);\n+\t\t\treturn execl_git_cmd(\"commit\", \"-n\", \"-F\", defmsg, NULL);\n \t}\n \tif (reencoded_message)\n \t\tfree(reencoded_message);\n-- \n1.5.2.rc2.716.gba45c\n"},{"id":"41423","messageId":"20070508072056.16912.qmail@48dfd32da30381.315fe32.mid.smarden.org","threadId":"8023","inReplyTo":"20070508015447.GA22253@spearce.org","subject":"Re: [PATCH] Use .git/MERGE_MSG in cherry-pick/revert","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-05-08T07:20:56Z","receivedAt":"2007-05-08T07:20:56Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"On Mon, May 07, 2007 at 09:54:47PM -0400, Shawn O. Pearce wrote:\n> Rather than storing the temporary commit message data in .msg (in\n> the working tree) we now store the message data in .git/MERGE_MSG.\n\nHi, there's one more error message referring to '.msg':\n\n static void add_to_msg(const char *string)\n {\n \tint len = strlen(string);\n \tif (write_in_full(msg_fd, string, len) < 0)\n \t\tdie (\"Could not write to .msg\");\n }\n\nThanks, Gerrit.\n"}]}