{"thread":{"id":"11393","subject":"[PATCH 1/4] t7005: do not exit inside test.","startedAt":"2007-12-23T03:55:33Z","lastAt":"2007-12-27T00:44:46Z","messageCount":6,"participants":["Junio C Hamano","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"64025","messageId":"1198382136-15724-1-git-send-email-gitster@pobox.com","threadId":"11393","inReplyTo":null,"subject":"[PATCH 1/4] t7005: do not exit inside test.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-23T03:55:33Z","receivedAt":"2007-12-23T03:55:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The way to signal failure is to leave non-zero in $?, not abort\nthe entire test.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t7005-editor.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex 44228b5..c1cec55 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -37,7 +37,7 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \tif git commit --amend\n \tthen\n \t\techo \"Oops?\"\n-\t\texit 1\n+\t\tfalse\n \telse\n \t\t: happy\n \tfi\n-- \n1.5.4.rc1.19.g9151fa\n"},{"id":"64026","messageId":"1198382136-15724-2-git-send-email-gitster@pobox.com","threadId":"11393","inReplyTo":"1198382136-15724-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/4] builtin-commit: fix amending of the initial commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-23T03:55:34Z","receivedAt":"2007-12-23T03:55:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When amending initial commit without editor, the command\nincorrectly barfed because the check to see if there is anything\nto commit referenced the non-existent HEAD^1.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-commit.c |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 96410de..d8f0dfd 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -374,7 +374,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \n \tif (no_edit) {\n \t\tstruct rev_info rev;\n-\t\tunsigned char sha1[40];\n+\t\tunsigned char sha1[20];\n \t\tconst char *parent = \"HEAD\";\n \n \t\tfclose(fp);\n@@ -382,12 +382,12 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \t\tif (!active_nr && read_cache() < 0)\n \t\t\tdie(\"Cannot read index\");\n \n-\t\tif (get_sha1(\"HEAD\", sha1) != 0)\n-\t\t\treturn !!active_nr;\n-\n \t\tif (amend)\n \t\t\tparent = \"HEAD^1\";\n \n+\t\tif (get_sha1(parent, sha1))\n+\t\t\treturn !!active_nr;\n+\n \t\tinit_revisions(&rev, \"\");\n \t\trev.abbrev = 0;\n \t\tsetup_revisions(0, NULL, &rev, parent);\n-- \n1.5.4.rc1.19.g9151fa\n"},{"id":"64027","messageId":"1198382136-15724-3-git-send-email-gitster@pobox.com","threadId":"11393","inReplyTo":"1198382136-15724-2-git-send-email-gitster@pobox.com","subject":"[PATCH 3/4] builtin-commit: avoid double-negation in the code.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-23T03:55:35Z","receivedAt":"2007-12-23T03:55:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The flag no_edit meant \"we have got final message from the user\nand will not editing it any further\", but there were quite a few\nplaces that needed to check !no_edit.  Rename the variable to\nuse_editor and reverse the logic everywhere.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-commit.c |   12 ++++++------\n 1 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex d8f0dfd..200eb9d 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -48,7 +48,7 @@ static char *edit_message, *use_message;\n static int all, edit_flag, also, interactive, only, amend, signoff;\n static int quiet, verbose, untracked_files, no_verify, allow_empty;\n \n-static int no_edit, initial_commit, in_merge;\n+static int use_editor = 1, initial_commit, in_merge;\n const char *only_include_assumed;\n struct strbuf message;\n \n@@ -372,7 +372,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \n \tstrbuf_release(&sb);\n \n-\tif (no_edit) {\n+\tif (!use_editor) {\n \t\tstruct rev_info rev;\n \t\tunsigned char sha1[20];\n \t\tconst char *parent = \"HEAD\";\n@@ -398,7 +398,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \t\treturn !!DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES);\n \t}\n \n-\tif (in_merge && !no_edit)\n+\tif (in_merge)\n \t\tfprintf(fp,\n \t\t\t\"#\\n\"\n \t\t\t\"# It looks like you may be committing a MERGE.\\n\"\n@@ -513,9 +513,9 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \targc = parse_options(argc, argv, builtin_commit_options, usage, 0);\n \n \tif (logfile || message.len || use_message)\n-\t\tno_edit = 1;\n+\t\tuse_editor = 0;\n \tif (edit_flag)\n-\t\tno_edit = 0;\n+\t\tuse_editor = 1;\n \n \tif (get_sha1(\"HEAD\", head_sha1))\n \t\tinitial_commit = 1;\n@@ -796,7 +796,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \n \t/* Get the commit message and validate it */\n \theader_len = sb.len;\n-\tif (!no_edit) {\n+\tif (use_editor) {\n \t\tchar index[PATH_MAX];\n \t\tconst char *env[2] = { index, NULL };\n \t\tsnprintf(index, sizeof(index), \"GIT_INDEX_FILE=%s\", index_file);\n-- \n1.5.4.rc1.19.g9151fa\n"},{"id":"64028","messageId":"1198382136-15724-4-git-send-email-gitster@pobox.com","threadId":"11393","inReplyTo":"1198382136-15724-3-git-send-email-gitster@pobox.com","subject":"[PATCH 4/4] Allow selection of different cleanup modes for commit messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-23T03:55:36Z","receivedAt":"2007-12-23T03:55:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Alex Riesen <raa.lkml@gmail.com>\n\nFrom: Alex Riesen <raa.lkml@gmail.com>\nDate: Sat, 22 Dec 2007 19:46:24 +0100\n\nAlthough we traditionally stripped away excess blank lines, trailing\nwhitespaces and lines that begin with \"#\" from the commit log message,\nsometimes the message just has to be the way user wants it.\n\nFor instance, a commit message template can contain lines that begin with\n\"#\", the message must be kept as close to its original source as possible\nif you are converting from a foreign SCM, or maybe the message has a shell\nscript including its comments for future reference.\n\nThe cleanup modes are default, verbatim, whitespace and strip. The\ndefault mode depends on if the message is being edited and will either\nstrip whitespace and comments (if editor active) or just strip the\nwhitespace (for where the message is given explicitely).\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-commit.txt |   12 +++++++-\n builtin-commit.c             |   42 ++++++++++++++++++++++++--\n t/t7502-commit.sh            |   65 ++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 114 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex 4261384..96383b6 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -11,7 +11,7 @@ SYNOPSIS\n 'git-commit' [-a | --interactive] [-s] [-v] [-u]\n \t   [(-c | -C) <commit> | -F <file> | -m <msg> | --amend]\n \t   [--allow-empty] [--no-verify] [-e] [--author <author>]\n-\t   [--] [[-i | -o ]<file>...]\n+\t   [--cleanup=<mode>] [--] [[-i | -o ]<file>...]\n \n DESCRIPTION\n -----------\n@@ -95,6 +95,16 @@ OPTIONS\n \tfrom making such a commit.  This option bypasses the safety, and\n \tis primarily for use by foreign scm interface scripts.\n \n+--cleanup=<mode>::\n+\tThis option sets how the commit message is cleaned up.\n+\tThe  '<mode>' can be one of 'verbatim', 'whitespace', 'strip',\n+\tand 'default'. The 'default' mode will strip leading and\n+\ttrailing empty lines and #commentary from the commit message\n+\tonly if the message is to be edited. Otherwise only whitespace\n+\tremoved. The 'verbatim' mode does not change message at all,\n+\t'whitespace' removes just leading/trailing whitespace lines\n+\tand 'strip' removes both whitespace and commentary.\n+\n -e|--edit::\n \tThe message taken from file with `-F`, command line with\n \t`-m`, and from file with `-C` are usually used as the\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 200eb9d..0e827d7 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -47,6 +47,19 @@ static char *logfile, *force_author, *template_file;\n static char *edit_message, *use_message;\n static int all, edit_flag, also, interactive, only, amend, signoff;\n static int quiet, verbose, untracked_files, no_verify, allow_empty;\n+/*\n+ * The default commit message cleanup mode will remove the lines\n+ * beginning with # (shell comments) and leading and trailing\n+ * whitespaces (empty lines or containing only whitespaces)\n+ * if editor is used, and only the whitespaces if the message\n+ * is specified explicitly.\n+ */\n+static enum {\n+\tCLEANUP_SPACE,\n+\tCLEANUP_NONE,\n+\tCLEANUP_ALL,\n+} cleanup_mode;\n+static char *cleanup_arg;\n \n static int use_editor = 1, initial_commit, in_merge;\n const char *only_include_assumed;\n@@ -88,6 +101,7 @@ static struct option builtin_commit_options[] = {\n \tOPT_BOOLEAN(0, \"amend\", &amend, \"amend previous commit\"),\n \tOPT_BOOLEAN(0, \"untracked-files\", &untracked_files, \"show all untracked files\"),\n \tOPT_BOOLEAN(0, \"allow-empty\", &allow_empty, \"ok to record an empty change\"),\n+\tOPT_STRING(0, \"cleanup\", &cleanup_arg, \"default\", \"how to strip spaces and #comments from message\"),\n \n \tOPT_END()\n };\n@@ -346,7 +360,8 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \tif (fp == NULL)\n \t\tdie(\"could not open %s\", git_path(commit_editmsg));\n \n-\tstripspace(&sb, 0);\n+\tif (cleanup_mode != CLEANUP_NONE)\n+\t\tstripspace(&sb, 0);\n \n \tif (signoff) {\n \t\tstruct strbuf sob;\n@@ -411,7 +426,12 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \tfprintf(fp,\n \t\t\"\\n\"\n \t\t\"# Please enter the commit message for your changes.\\n\"\n-\t\t\"# (Comment lines starting with '#' will not be included)\\n\");\n+\t\t\"# (Comment lines starting with '#' will \");\n+\tif (cleanup_mode == CLEANUP_ALL)\n+\t\tfprintf(fp, \"not be included)\\n\");\n+\telse /* CLEANUP_SPACE, that is. */\n+\t\tfprintf(fp, \"be kept.\\n\"\n+\t\t\t\"# You can remove them yourself if you want to)\\n\");\n \tif (only_include_assumed)\n \t\tfprintf(fp, \"# %s\\n\", only_include_assumed);\n \n@@ -435,10 +455,13 @@ static int message_is_empty(struct strbuf *sb, int start)\n \tconst char *nl;\n \tint eol, i;\n \n+\tif (cleanup_mode == CLEANUP_NONE && sb->len)\n+\t\treturn 0;\n+\n \t/* See if the template is just a prefix of the message. */\n \tstrbuf_init(&tmpl, 0);\n \tif (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) {\n-\t\tstripspace(&tmpl, 1);\n+\t\tstripspace(&tmpl, cleanup_mode == CLEANUP_ALL);\n \t\tif (start + tmpl.len <= sb->len &&\n \t\t    memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0)\n \t\t\tstart += tmpl.len;\n@@ -591,6 +614,16 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \t\tonly_include_assumed = \"Explicit paths specified without -i nor -o; assuming --only paths...\";\n \t\talso = 0;\n \t}\n+\tif (!cleanup_arg || !strcmp(cleanup_arg, \"default\"))\n+\t\tcleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;\n+\telse if (!strcmp(cleanup_arg, \"verbatim\"))\n+\t\tcleanup_mode = CLEANUP_NONE;\n+\telse if (!strcmp(cleanup_arg, \"whitespace\"))\n+\t\tcleanup_mode = CLEANUP_SPACE;\n+\telse if (!strcmp(cleanup_arg, \"strip\"))\n+\t\tcleanup_mode = CLEANUP_ALL;\n+\telse\n+\t\tdie(\"Invalid cleanup mode %s\", cleanup_arg);\n \n \tif (all && argc > 0)\n \t\tdie(\"Paths with -a does not make sense.\");\n@@ -817,7 +850,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tif (p != NULL)\n \t\tstrbuf_setlen(&sb, p - sb.buf + 1);\n \n-\tstripspace(&sb, 1);\n+\tif (cleanup_mode != CLEANUP_NONE)\n+\t\tstripspace(&sb, cleanup_mode == CLEANUP_ALL);\n \tif (sb.len < header_len || message_is_empty(&sb, header_len)) {\n \t\trollback_index_files();\n \t\tdie(\"no commit message?  aborting commit.\");\ndiff --git a/t/t7502-commit.sh b/t/t7502-commit.sh\nindex 21ac785..aaf497e 100755\n--- a/t/t7502-commit.sh\n+++ b/t/t7502-commit.sh\n@@ -89,4 +89,69 @@ test_expect_success 'verbose' '\n \n '\n \n+test_expect_success 'cleanup commit messages (verbatim,-t)' '\n+\n+\techo >>negative &&\n+\t{ echo;echo \"# text\";echo; } >expect &&\n+\tgit commit --cleanup=verbatim -t expect -a &&\n+\tgit cat-file -p HEAD |sed -e \"1,/^\\$/d\" |head -n 3 >actual &&\n+\tdiff -u expect actual\n+\n+'\n+\n+test_expect_success 'cleanup commit messages (verbatim,-F)' '\n+\n+\techo >>negative &&\n+\tgit commit --cleanup=verbatim -F expect -a &&\n+\tgit cat-file -p HEAD |sed -e \"1,/^\\$/d\">actual &&\n+\tdiff -u expect actual\n+\n+'\n+\n+test_expect_success 'cleanup commit messages (verbatim,-m)' '\n+\n+\techo >>negative &&\n+\tgit commit --cleanup=verbatim -m \"$(cat expect)\" -a &&\n+\tgit cat-file -p HEAD |sed -e \"1,/^\\$/d\">actual &&\n+\tdiff -u expect actual\n+\n+'\n+\n+test_expect_success 'cleanup commit messages (whitespace,-F)' '\n+\n+\techo >>negative &&\n+\t{ echo;echo \"# text\";echo; } >text &&\n+\techo \"# text\" >expect &&\n+\tgit commit --cleanup=whitespace -F text -a &&\n+\tgit cat-file -p HEAD |sed -e \"1,/^\\$/d\">actual &&\n+\tdiff -u expect actual\n+\n+'\n+\n+test_expect_success 'cleanup commit messages (strip,-F)' '\n+\n+\techo >>negative &&\n+\t{ echo;echo \"# text\";echo sample;echo; } >text &&\n+\techo sample >expect &&\n+\tgit commit --cleanup=strip -F text -a &&\n+\tgit cat-file -p HEAD |sed -e \"1,/^\\$/d\">actual &&\n+\tdiff -u expect actual\n+\n+'\n+\n+echo \"sample\n+\n+# Please enter the commit message for your changes.\n+# (Comment lines starting with '#' will not be included)\" >expect\n+\n+test_expect_success 'cleanup commit messages (strip,-F,-e)' '\n+\n+\techo >>negative &&\n+\t{ echo;echo sample;echo; } >text &&\n+\tgit commit -e -F text -a &&\n+\thead -n 4 .git/COMMIT_EDITMSG >actual &&\n+\tdiff -u expect actual\n+\n+'\n+\n test_done\n-- \n1.5.4.rc1.19.g9151fa\n"},{"id":"64111","messageId":"7vmyrxm2qh.fsf@gitster.siamese.dyndns.org","threadId":"11393","inReplyTo":"1198382136-15724-4-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 4/4] Allow selection of different cleanup modes for commit messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-26T23:54:14Z","receivedAt":"2007-12-26T23:54:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> From: Alex Riesen <raa.lkml@gmail.com>\n> Date: Sat, 22 Dec 2007 19:46:24 +0100\n>\n> Although we traditionally stripped away excess blank lines, trailing\n> whitespaces and lines that begin with \"#\" from the commit log message,\n> sometimes the message just has to be the way user wants it.\n> ...\n\nAny comments on the cleaned-up series?\n"},{"id":"64112","messageId":"alpine.LFD.0.9999.0712261643440.21557@woody.linux-foundation.org","threadId":"11393","inReplyTo":"7vmyrxm2qh.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 4/4] Allow selection of different cleanup modes for commit messages","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-12-27T00:44:46Z","receivedAt":"2007-12-27T00:44:46Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 26 Dec 2007, Junio C Hamano wrote:\n> \n> Any comments on the cleaned-up series?\n\nMe likee. I think there's still room for some possible future discussions \n(the whole \"flag in the file to allow the editor to choose\" kind of \nthing), but this seems like a good improvement on the current state.\n\n\t\tLinus\n"}]}