builtin-commit: Include the diff in the commit message when verbose.
run_diff_index() and the entire diff machinery is hard coded to output to stdout, so just redirect that and restore it when done. Signed-off-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristian Høgsberg committed
Nov 21, 2007 at 21:54 UTC
99a12694582e2148fcd492f1eedaddcfe2a21621
2 files changed
+23
-1
builtin-commit.c
+7
-1
@@ -662,7 +662,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
662
int header_len;
663
struct strbuf sb;
664
const char *index_file, *reflog_msg;
665
- char *nl;
665
+ char *nl, *p;
666
unsigned char commit_sha1[20];
667
struct ref_lock *ref_lock;
668
@@ -758,6 +758,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
758
rollback_index_files();
759
exit(1);
760
}
761
+
762
+ /* Truncate the message just before the diff, if any. */
763
+ p = strstr(sb.buf, "\ndiff --git a/");
764
+ if (p != NULL)
765
+ strbuf_setlen(&sb, p - sb.buf);
766
+
767
stripspace(&sb, 1);
768
if (sb.len < header_len || message_is_empty(&sb, header_len)) {
769
rollback_index_files();
wt-status.c
+16
@@ -315,12 +315,28 @@ static void wt_status_print_untracked(struct wt_status *s)
315
static void wt_status_print_verbose(struct wt_status *s)
316
{
317
struct rev_info rev;
318
+ int saved_stdout;
319
+
320
+ fflush(s->fp);
321
+
322
+ /* Sigh, the entire diff machinery is hardcoded to output to
323
+ * stdout. Do the dup-dance...*/
324
+ saved_stdout = dup(STDOUT_FILENO);
325
+ if (saved_stdout < 0 ||dup2(fileno(s->fp), STDOUT_FILENO) < 0)
326
+ die("couldn't redirect stdout\n");
327
+
328
init_revisions(&rev, NULL);
329
setup_revisions(0, NULL, &rev, s->reference);
330
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
331
rev.diffopt.detect_rename = 1;
332
wt_read_cache(s);
333
run_diff_index(&rev, 1);
334
+
335
+ fflush(stdout);
336
+
337
+ if (dup2(saved_stdout, STDOUT_FILENO) < 0)
338
+ die("couldn't restore stdout\n");
339
+ close(saved_stdout);
340
}
341
342
void wt_status_print(struct wt_status *s)