From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Ward Comfort Subject: [PATCH] commit, status: #comment diff output in verbose mode Date: Thu, 3 Mar 2011 03:23:39 -0800 Message-ID: <1299151419-16027-1-git-send-email-icomfort@stanford.edu> References: Cc: Junio C Hamano , Johan Herland , Jeff King , git@vger.kernel.org To: Sverre Rabbelier X-From: git-owner@vger.kernel.org Thu Mar 03 12:31:17 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pv6kT-0007AN-KW for gcvg-git-2@lo.gmane.org; Thu, 03 Mar 2011 12:31:14 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757909Ab1CCLbI (ORCPT ); Thu, 3 Mar 2011 06:31:08 -0500 Received: from smtp3.Stanford.EDU ([171.67.219.83]:52520 "EHLO smtp.stanford.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756557Ab1CCLbH (ORCPT ); Thu, 3 Mar 2011 06:31:07 -0500 X-Greylist: delayed 440 seconds by postgrey-1.27 at vger.kernel.org; Thu, 03 Mar 2011 06:31:07 EST Received: from smtp.stanford.edu (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with SMTP id 4A9B51A1D06; Thu, 3 Mar 2011 03:23:46 -0800 (PST) Received: from ashbury.stanford.edu (ashbury.Stanford.EDU [171.67.43.200]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.stanford.edu (Postfix) with ESMTPS id C4DDA1A1CF3; Thu, 3 Mar 2011 03:23:43 -0800 (PST) Received: by ashbury.stanford.edu (Postfix, from userid 26037) id A1AC81D005A; Thu, 3 Mar 2011 03:23:43 -0800 (PST) X-Mailer: git-send-email 1.7.4.1.177.g1c06f In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: On 3 Mar 2011, at 3:12 AM, Sverre Rabbelier wrote: > On Thu, Mar 3, 2011 at 04:50, Junio C Hamano wrote: >> Good question. There was no reason other than "that is just a historical >> accident". >> >> The intention has always been "allow people to review the change for the >> last time while writing a log message"; there was never a feature request >> to allow the diff to be included---it would always have been an unwelcome >> accident it that ever happened. > > In that case, can we change it to be that way now if it makes this case > easier? How about something like this? --8<-- By historical accident, diffs included in commit templates and status output when the "-v" option is given are not prefixed with the # comment character, as other advice and status information is. Stripping these lines is thus a best-effort operation, as it is not always possible to tell which lines were generated by "-v" and which were inserted by the user. Improve this situation by adding the # prefix to diff output along with all other status output in these cases. The change is simply made thanks to a3c158d (Add a prefix output callback to diff output, 2010-05-26). The prefixed diff can be stripped (or not, as configured) by the standard cleanup code, so our special verbose-mode heuristic can be removed. Documentation and a few tests which rely on the old "-v" format are updated to match. One known breakage is fixed in t7507. Signed-off-by: Ian Ward Comfort --- Documentation/git-commit.txt | 3 +-- builtin/commit.c | 7 ------- t/t4030-diff-textconv.sh | 2 +- t/t7502-commit.sh | 4 ++-- t/t7507-commit-verbose.sh | 4 ++-- wt-status.c | 12 ++++++++++++ 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 8f89f6f..792f993 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -233,8 +233,7 @@ configuration variable documented in linkgit:git-config[1]. --verbose:: Show unified diff between the HEAD commit and what would be committed at the bottom of the commit message - template. Note that this diff output doesn't have its - lines prefixed with '#'. + template. -q:: --quiet:: diff --git a/builtin/commit.c b/builtin/commit.c index 355b2cb..efecac3 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1381,13 +1381,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix) die("could not read commit message: %s", strerror(saved_errno)); } - /* Truncate the message just before the diff, if any. */ - if (verbose) { - p = strstr(sb.buf, "\ndiff --git "); - if (p != NULL) - strbuf_setlen(&sb, p - sb.buf + 1); - } - if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, cleanup_mode == CLEANUP_ALL); if (message_is_empty(&sb) && !allow_empty_message) { diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 88c5619..b00999e 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -79,7 +79,7 @@ test_expect_success 'format-patch produces binary' ' test_expect_success 'status -v produces text' ' git reset --soft HEAD^ && git status -v >diff && - find_diff actual && + sed -e "s/^# //" actual && test_cmp expect.text actual && git reset --soft HEAD@{1} ' diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 50da034..a916001 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -151,8 +151,8 @@ test_expect_success 'verbose' ' echo minus >negative && git add negative && - git status -v | sed -ne "/^diff --git /p" >actual && - echo "diff --git a/negative b/negative" >expect && + git status -v | sed -ne "/^# diff --git /p" >actual && + echo "# diff --git a/negative b/negative" >expect && test_cmp expect actual ' diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh index da5bd3b..5b21bbb 100755 --- a/t/t7507-commit-verbose.sh +++ b/t/t7507-commit-verbose.sh @@ -5,7 +5,7 @@ test_description='verbose commit template' cat >check-for-diff <is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; setup_revisions(0, NULL, &rev, &opt); + strbuf_addstr(&diff_output_prefix, "# "); + rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.detect_rename = 1; rev.diffopt.file = s->fp; rev.diffopt.close_file = 0; + rev.diffopt.output_prefix = diff_output_prefix_callback; + rev.diffopt.output_prefix_data = &diff_output_prefix; /* * If we're not going to stdout, then we definitely don't * want color, since we are going to the commit message @@ -609,6 +620,7 @@ static void wt_status_print_verbose(struct wt_status *s) if (s->fp != stdout) DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF); run_diff_index(&rev, 1); + strbuf_release(&diff_output_prefix); } static void wt_status_print_tracking(struct wt_status *s) -- 1.7.4.1.177.g1c06f