Code

builtin-commit: Include the diff in the commit message when verbose.
authorKristian Høgsberg <krh@redhat.com>
Thu, 22 Nov 2007 02:54:49 +0000 (21:54 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 23 Nov 2007 01:05:05 +0000 (17:05 -0800)
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>
builtin-commit.c
wt-status.c

index e779db8ca3a7493a5353549b7ed562b68679a0ed..4de316a366d1ee7201d89b776a4a9a4b499d32b8 100644 (file)
@@ -662,7 +662,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        int header_len;
        struct strbuf sb;
        const char *index_file, *reflog_msg;
-       char *nl;
+       char *nl, *p;
        unsigned char commit_sha1[20];
        struct ref_lock *ref_lock;
 
@@ -758,6 +758,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                rollback_index_files();
                exit(1);
        }
+
+       /* Truncate the message just before the diff, if any. */
+       p = strstr(sb.buf, "\ndiff --git a/");
+       if (p != NULL)
+               strbuf_setlen(&sb, p - sb.buf);
+
        stripspace(&sb, 1);
        if (sb.len < header_len || message_is_empty(&sb, header_len)) {
                rollback_index_files();
index d3c10b8b8d2fcb0421cde0589e2eb96e8f534c87..0e0439f2c2d8f19abba0a683ce1b2ab3db6197ba 100644 (file)
@@ -315,12 +315,28 @@ static void wt_status_print_untracked(struct wt_status *s)
 static void wt_status_print_verbose(struct wt_status *s)
 {
        struct rev_info rev;
+       int saved_stdout;
+
+       fflush(s->fp);
+
+       /* Sigh, the entire diff machinery is hardcoded to output to
+        * stdout.  Do the dup-dance...*/
+       saved_stdout = dup(STDOUT_FILENO);
+       if (saved_stdout < 0 ||dup2(fileno(s->fp), STDOUT_FILENO) < 0)
+               die("couldn't redirect stdout\n");
+
        init_revisions(&rev, NULL);
        setup_revisions(0, NULL, &rev, s->reference);
        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
        rev.diffopt.detect_rename = 1;
        wt_read_cache(s);
        run_diff_index(&rev, 1);
+
+       fflush(stdout);
+
+       if (dup2(saved_stdout, STDOUT_FILENO) < 0)
+               die("couldn't restore stdout\n");
+       close(saved_stdout);
 }
 
 void wt_status_print(struct wt_status *s)