{"thread":{"id":"10963","subject":"[PATCH] builtin-commit: Include the diff in the commit message when verbose.","startedAt":"2007-11-21T19:10:34Z","lastAt":"2007-11-21T19:10:34Z","messageCount":1,"participants":["Kristian Høgsberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60554","messageId":"1195672234-3919-1-git-send-email-krh@redhat.com","threadId":"10963","inReplyTo":null,"subject":"[PATCH] builtin-commit: Include the diff in the commit message when verbose.","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2007-11-21T19:10:34Z","receivedAt":"2007-11-21T19:10:34Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"run_diff_index() and the entire diff machinery is hard coded to output\nto stdout, so just redirect that and restore it when done.\n\nSigned-off-by: Kristian Høgsberg <krh@redhat.com>\n---\n builtin-commit.c |   24 +++++++++++++++++++++++-\n 1 files changed, 23 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 446a252..d5b8479 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -277,6 +277,7 @@ static char *prepare_index(const char **files, const char *prefix)\n static int run_status(FILE *fp, const char *index_file, const char *prefix)\n {\n \tstruct wt_status s;\n+\tint saved_stdout;\n \n \twt_status_prepare(&s);\n \ts.prefix = prefix;\n@@ -290,8 +291,23 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)\n \ts.index_file = index_file;\n \ts.fp = fp;\n \n+\tfflush(fp);\n+\n+\t/* Sigh, the entire diff machinery is hardcoded to output to\n+\t * stdout.  Do the dup-dance...*/\n+\tsaved_stdout = dup(STDOUT_FILENO);\n+\tif (saved_stdout < 0 ||\tdup2(fileno(fp), STDOUT_FILENO) < 0)\n+\t\tdie(\"couldn't redirect stdout\\n\");\n+\n \twt_status_print(&s);\n \n+\tfflush(fp);\n+\tfflush(stdout);\n+\n+\tif (dup2(saved_stdout, STDOUT_FILENO) < 0)\n+\t\tdie(\"couldn't restore stdout\\n\");\n+\tclose(saved_stdout);\n+\n \treturn s.commitable;\n }\n \n@@ -661,7 +677,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tint header_len;\n \tstruct strbuf sb;\n \tconst char *index_file, *reflog_msg;\n-\tchar *nl;\n+\tchar *nl, *p;\n \tunsigned char commit_sha1[20];\n \tstruct ref_lock *ref_lock;\n \n@@ -757,6 +773,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\trollback_index_files();\n \t\texit(1);\n \t}\n+\n+\t/* Truncate the message just before the diff, if any. */\n+\tp = strstr(sb.buf, \"\\ndiff --git a/\");\n+\tif (p != NULL)\n+\t\tstrbuf_setlen(&sb, p - sb.buf);\n+\n \tstripspace(&sb, 1);\n \tif (sb.len < header_len || message_is_empty(&sb, header_len)) {\n \t\trollback_index_files();\n-- \n1.5.3.4.206.g58ba4\n"}]}