{"thread":{"id":"3854","subject":"Some Commit Messages Scare git-rev-list","startedAt":"2006-04-12T13:11:02Z","lastAt":"2006-04-12T20:04:03Z","messageCount":5,"participants":["Darrin Thompson","Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18581","messageId":"1144847462.5213.6.camel@localhost.localdomain","threadId":"3854","inReplyTo":null,"subject":"Some Commit Messages Scare git-rev-list","fromName":"Darrin Thompson","fromEmail":"darrint@progeny.com","sentAt":"2006-04-12T13:11:02Z","receivedAt":"2006-04-12T13:11:02Z","isPatch":false,"sender":{"key":"darrint@progeny.com","avatar":null},"body":"This scripts exhibits some odd behavior. Apparently git-rev-list\nmishandles commit messages which do not end in a newline. This as best I\ncan tell this is a problem introduced since 1.1.5.\n\nHere is a script to reproduce the problem:\n\nrm -rf git-test\nmkdir git-test\ncd git-test\ngit-init-db\necho hello > hello\ngit-add hello\n\n# send scary message to git-commit -F -\necho -n \"test commit\" | git-commit -F - -a\necho world > world\ngit-add world\ngit-update-index --add world\ntreeid=$(git-write-tree)\n\n# send scary message directly to git-commit-tree\ncommitid=$(echo -n \"another-test\" | git-commit-tree $treeid -p HEAD)\ngit-update-ref HEAD $commitid\n\n# see the wreckage\ngit-rev-list --pretty HEAD\n\nRunning gitk will also show the problem.\n\n--\nDarrin\n"},{"id":"18585","messageId":"Pine.LNX.4.64.0604121002220.14565@g5.osdl.org","threadId":"3854","inReplyTo":"1144847462.5213.6.camel@localhost.localdomain","subject":"Re: Some Commit Messages Scare git-rev-list","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-04-12T17:23:38Z","receivedAt":"2006-04-12T17:23:38Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 12 Apr 2006, Darrin Thompson wrote:\n>\n> This scripts exhibits some odd behavior. Apparently git-rev-list\n> mishandles commit messages which do not end in a newline. This as best I\n> can tell this is a problem introduced since 1.1.5.\n\nFixed like so..\n\nHowever, your script shows another problem: the \"#\" added at the end of \nthe line for a \n\n\techo -n \"duh\" | git-commit -F - -a\n\nseems to be because we append the \"git status\" output to it, and then we \ndrop the lines that start with a '#', but due to the \"-n\", the first # \nends up being at the end of the line. \n\nI suspect that when we get the commit message like that, we should _not_ \ndo any of the commit message editing at all.\n\nThat's a separate issue, though, and not fixed by this patch.\n\n\t\tLinus\n\n---\ndiff --git a/commit.c b/commit.c\nindex d534c9b..c7bb8db 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -400,11 +400,11 @@ static int get_one_line(const char *msg,\n \n \twhile (len--) {\n \t\tchar c = *msg++;\n+\t\tif (!c)\n+\t\t\tbreak;\n \t\tret++;\n \t\tif (c == '\\n')\n \t\t\tbreak;\n-\t\tif (!c)\n-\t\t\treturn 0;\n \t}\n \treturn ret;\n }\n"},{"id":"18586","messageId":"7v3bgi4op7.fsf@assigned-by-dhcp.cox.net","threadId":"3854","inReplyTo":"Pine.LNX.4.64.0604121002220.14565@g5.osdl.org","subject":"Re: Some Commit Messages Scare git-rev-list","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-12T18:46:12Z","receivedAt":"2006-04-12T18:46:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Fixed like so..\n\nThanks.\n\n> However, your script shows another problem: the \"#\" added at the end of \n> the line for a \n>\n> \techo -n \"duh\" | git-commit -F - -a\n>\n> seems to be because we append the \"git status\" output to it, and then we \n> drop the lines that start with a '#', but due to the \"-n\", the first # \n> ends up being at the end of the line. \n>\n> I suspect that when we get the commit message like that, we should _not_ \n> do any of the commit message editing at all.\n\nTrue.\n\n-- >8 --\n[PATCH] git-commit: do not muck with commit message when no_edit is set.\n\nSpotted by Linus and Darrin Thompson.  When we took a commit\nmessage from -F <file> with an incomplete line, we appended \"git\nstatus\" output, which ended up attaching a lone \"#\" at the end.\n\nWe still need the \"do we have anything to commit?\" check by\nrunning \"status\" (which has to know what to do in different\ncases with -i/-o/-a), but there is no point appending its output\nto the proposed commit message given by the user.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n git-commit.sh |   17 ++++++++++++-----\n 1 files changed, 12 insertions(+), 5 deletions(-)\n\n475443c8489d9167b944367d8ec8bfef77bee0a5\ndiff --git a/git-commit.sh b/git-commit.sh\nindex 1e7c09e..bd3dc71 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -537,7 +537,7 @@ t)\n \t;;\n esac\n \n-if [ -f \"$GIT_DIR/MERGE_HEAD\" ]; then\n+if test -f \"$GIT_DIR/MERGE_HEAD\" && test -z \"$no_edit\"; then\n \techo \"#\"\n \techo \"# It looks like you may be committing a MERGE.\"\n \techo \"# If this is not correct, please remove the file\"\n@@ -605,16 +605,23 @@ else\n \tcurrent=\n fi\n \n-{\n-\ttest -z \"$only_include_assumed\" || echo \"$only_include_assumed\"\n-\trun_status\n-} >>\"$GIT_DIR\"/COMMIT_EDITMSG\n+if test -z \"$no_edit\"\n+then\n+\t{\n+\t\ttest -z \"$only_include_assumed\" || echo \"$only_include_assumed\"\n+\t\trun_status\n+\t} >>\"$GIT_DIR\"/COMMIT_EDITMSG\n+else\n+\t# we need to check if there is anything to commit\n+\trun_status >/dev/null \n+fi\n if [ \"$?\" != \"0\" -a ! -f \"$GIT_DIR/MERGE_HEAD\" -a -z \"$amend\" ]\n then\n \trm -f \"$GIT_DIR/COMMIT_EDITMSG\"\n \trun_status\n \texit 1\n fi\n+\n case \"$no_edit\" in\n '')\n \tcase \"${VISUAL:-$EDITOR},$TERM\" in\n-- \n1.3.0.rc3.g72c1\n"},{"id":"18588","messageId":"7vy7ya37o2.fsf@assigned-by-dhcp.cox.net","threadId":"3854","inReplyTo":"7v3bgi4op7.fsf@assigned-by-dhcp.cox.net","subject":"Re: Some Commit Messages Scare git-rev-list","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-12T19:39:25Z","receivedAt":"2006-04-12T19:39:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> We still need the \"do we have anything to commit?\" check by\n> running \"status\" (which has to know what to do in different\n> cases with -i/-o/-a), but there is no point appending its output\n> to the proposed commit message given by the user.\n\nBTW, this does not quite work as expected if you did something\nlike this:\n\n\techo -n 'incomplete line' | git commit -a -s -F -\n\nbecause we would want to append the Signed-off-by: line.  I am\nalmost tempted to say \"then do not do it\", but it might make\nsense to do this as well.\n\n-- >8 --\n[PATCH] stripspace: make sure not to leave an incomplete line.\n\nWhen dealing with a commit log message for human consumption, it\nnever makes sense to keep a log that ends with an incomplete\nline, so make it a part of the clean-up process done with\ngit-stripspace.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\ndiff --git a/stripspace.c b/stripspace.c\nindex 96cd0a8..dee1ef0 100644\n--- a/stripspace.c\n+++ b/stripspace.c\n@@ -6,9 +6,9 @@ #include <ctype.h>\n  * Remove empty lines from the beginning and end.\n  *\n  * Turn multiple consecutive empty lines into just one\n- * empty line.\n+ * empty line.  Return true if it is an incomplete line.\n  */\n-static void cleanup(char *line)\n+static int cleanup(char *line)\n {\n \tint len = strlen(line);\n \n@@ -21,16 +21,19 @@ static void cleanup(char *line)\n \t\t\tlen--;\n \t\t\tline[len] = 0;\n \t\t} while (len > 1);\n+\t\treturn 0;\n \t}\n+\treturn 1;\n }\n \n int main(int argc, char **argv)\n {\n \tint empties = -1;\n+\tint incomplete = 0;\n \tchar line[1024];\n \n \twhile (fgets(line, sizeof(line), stdin)) {\n-\t\tcleanup(line);\n+\t\tincomplete = cleanup(line);\n \n \t\t/* Not just an empty line? */\n \t\tif (line[0] != '\\n') {\n@@ -44,5 +47,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\tempties++;\n \t}\n+\tif (incomplete)\n+\t\tputchar('\\n');\n \treturn 0;\n }\n"},{"id":"18589","messageId":"Pine.LNX.4.64.0604121303520.14565@g5.osdl.org","threadId":"3854","inReplyTo":"7vy7ya37o2.fsf@assigned-by-dhcp.cox.net","subject":"Re: Some Commit Messages Scare git-rev-list","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-04-12T20:04:03Z","receivedAt":"2006-04-12T20:04:03Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 12 Apr 2006, Junio C Hamano wrote:\n>\n> [PATCH] stripspace: make sure not to leave an incomplete line.\n\nAck.\n\n\t\tLinus\n"}]}