From patchwork Fri Aug 18 23:59:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13358380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43D71EE499B for ; Sat, 19 Aug 2023 00:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242973AbjHRX7w (ORCPT ); Fri, 18 Aug 2023 19:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243121AbjHRX7l (ORCPT ); Fri, 18 Aug 2023 19:59:41 -0400 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2974B2D65 for ; Fri, 18 Aug 2023 16:59:40 -0700 (PDT) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id B9A1B29F1E; Fri, 18 Aug 2023 19:59:39 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=YcJQSY2cSsifL3D6Hwv2rdWGh CQ4ncvWoxyj2sX3vCc=; b=AS4Hbvovvp4UWj1WbArnWedgeQXLKKRI8p4JOCQMm LSHg0TFVJm0J/sLHUByaHV1Lr/IJYiEpaBhQULB6EUXMlm59ENGWeBUm6qMAaHFV QDLy4+QbftEEquGWNVw4fSRYfdf9h8ECloOIwhf+tm5ZtbFOGWuKp5hm2TAE29SS ug= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id B146529F1D; Fri, 18 Aug 2023 19:59:39 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.58.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 647E329F17; Fri, 18 Aug 2023 19:59:36 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 1/5] diff: move the fallback "--exit-code" code down Date: Fri, 18 Aug 2023 16:59:28 -0700 Message-ID: <20230818235932.3253552-2-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-rc2-7-gf9972720e9 In-Reply-To: <20230818235932.3253552-1-gitster@pobox.com> References: <20230817222949.3835424-1-gitster@pobox.com> <20230818235932.3253552-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 48FB318E-3E23-11EE-A774-F515D2CDFF5E-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When "--exit-code" is asked and the code cannot just answer by comparing the object names on both sides but needs to inspect and compare the contents, there are two ways that the result is found out. Some output modes, like "--stat" and "--patch", inherently have to inspect the contents in order to show the differences in the way they do. The codepaths for these modes set the .found_changes bit as they compute what to show. However, other output modes do not need to inspect the contents to show the differences in the way they do. The most notable example is "--quiet", which does not need to compute any output to show. When they are asked to report "--exit-code", they run the codepaths for the "--patch" output with their output redirected to "/dev/null", only to set the .found_changes bit. Currently, this fallback invocation of "--patch" output is done after the "--stat" output format and its friends and before the "--patch" and internal callback logic. Move it to the end of the sequence to clarify the fallback status of this code block. Signed-off-by: Junio C Hamano --- diff.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/diff.c b/diff.c index d52db685f7..0ce678fc06 100644 --- a/diff.c +++ b/diff.c @@ -6551,6 +6551,21 @@ void diff_flush(struct diff_options *options) separator++; } + if (output_format & DIFF_FORMAT_PATCH) { + if (separator) { + emit_diff_symbol(options, DIFF_SYMBOL_SEPARATOR, NULL, 0, 0); + if (options->stat_sep) + /* attach patch instead of inline */ + emit_diff_symbol(options, DIFF_SYMBOL_STAT_SEP, + NULL, 0, 0); + } + + diff_flush_patch_all_file_pairs(options); + } + + if (output_format & DIFF_FORMAT_CALLBACK) + options->format_callback(q, options, options->format_callback_data); + if (output_format & DIFF_FORMAT_NO_OUTPUT && options->flags.exit_with_status && options->flags.diff_from_contents) { @@ -6572,21 +6587,6 @@ void diff_flush(struct diff_options *options) } } - if (output_format & DIFF_FORMAT_PATCH) { - if (separator) { - emit_diff_symbol(options, DIFF_SYMBOL_SEPARATOR, NULL, 0, 0); - if (options->stat_sep) - /* attach patch instead of inline */ - emit_diff_symbol(options, DIFF_SYMBOL_STAT_SEP, - NULL, 0, 0); - } - - diff_flush_patch_all_file_pairs(options); - } - - if (output_format & DIFF_FORMAT_CALLBACK) - options->format_callback(q, options, options->format_callback_data); - for (i = 0; i < q->nr; i++) diff_free_filepair(q->queue[i]); free_queue: From patchwork Fri Aug 18 23:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13358376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 339C5EE49A1 for ; Sat, 19 Aug 2023 00:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243034AbjHRX7w (ORCPT ); Fri, 18 Aug 2023 19:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243122AbjHRX7m (ORCPT ); Fri, 18 Aug 2023 19:59:42 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5AC93AAE for ; Fri, 18 Aug 2023 16:59:40 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 377231A1FD4; Fri, 18 Aug 2023 19:59:40 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=MxFpL1pjw/VCL4g9Ye6NbJxWB N6a4PLAhjQjeCDHlI4=; b=JowfaZmcGDV4vx7Heu1PlfdR4Rz/Uh19a5ott3sML zTrWAKZsTCiXOEZcjYXcCiZvu9hqIHgWVzZ9c5vBcbSB9xLO7aIBKBQE8tHsnzTf gRgZFYPF97jQJj4b+2LwGHl2wMIl9bywZ20wOfrs/GS/no+wYchE1YzbfwGeszRb lM= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 2DEE01A1FD3; Fri, 18 Aug 2023 19:59:40 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.58.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 8DF401A1FD2; Fri, 18 Aug 2023 19:59:39 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 2/5] diff: mode-only change should be noticed by "--patch -w --exit-code" Date: Fri, 18 Aug 2023 16:59:29 -0700 Message-ID: <20230818235932.3253552-3-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-rc2-7-gf9972720e9 In-Reply-To: <20230818235932.3253552-1-gitster@pobox.com> References: <20230817222949.3835424-1-gitster@pobox.com> <20230818235932.3253552-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 4ADF1D1C-3E23-11EE-83AF-25B3960A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The codepath to notice the content-level changes, taking certain no-op changes like "ignore whitespace" into account, forgot that a mode-only change is still a change. This resulted in $ git diff --patch --exit-code -w to exit with status 0 even when there is such a mode-only change, breaking both "--patch" and "--quiet" output formats. Teach the builtin_diff() codepath that creation and deletion as well as mode changes are all interesting changes. Note that the test specifically checks removal of an empty file, because if there is anything in the preimage (i.e. the removed file is not empty), the removal would still trigger textual patch output and the codepath for that does update .found_changes bit to report that it found an interesting change. We need to make sure that the .found_changes bit is set even without triggering textual patch output. Signed-off-by: Junio C Hamano --- diff.c | 3 +++ t/t4015-diff-whitespace.sh | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 0ce678fc06..998d7ae20c 100644 --- a/diff.c +++ b/diff.c @@ -3497,18 +3497,21 @@ static void builtin_diff(const char *name_a, strbuf_addf(&header, "%s%snew file mode %06o%s\n", line_prefix, meta, two->mode, reset); if (xfrm_msg) strbuf_addstr(&header, xfrm_msg); + o->found_changes = 1; must_show_header = 1; } else if (lbl[1][0] == '/') { strbuf_addf(&header, "%s%sdeleted file mode %06o%s\n", line_prefix, meta, one->mode, reset); if (xfrm_msg) strbuf_addstr(&header, xfrm_msg); + o->found_changes = 1; must_show_header = 1; } else { if (one->mode != two->mode) { strbuf_addf(&header, "%s%sold mode %06o%s\n", line_prefix, meta, one->mode, reset); strbuf_addf(&header, "%s%snew mode %06o%s\n", line_prefix, meta, two->mode, reset); + o->found_changes = 1; must_show_header = 1; } if (xfrm_msg) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index f3e20dd5bb..02731dccb9 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -1,7 +1,7 @@ #!/bin/sh # # Copyright (c) 2006 Johannes E. Schindelin -# +# Copyright (c) 2023 Google LLC test_description='Test special whitespace in diff engine. @@ -11,6 +11,39 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh +for opts in --patch --quiet -s +do + + test_expect_success "status with $opts (different)" ' + echo foo >x && + git add x && + echo bar >x && + test_expect_code 1 git diff -w $opts --exit-code x + ' + + test_expect_success POSIXPERM "status with $opts (mode differs)" ' + test_when_finished "git update-index --chmod=-x x" && + echo foo >x && + git add x && + git update-index --chmod=+x x && + test_expect_code 1 git diff -w $opts --exit-code x + ' + + test_expect_success "status with $opts (removing an empty file)" ' + : >x && + git add x && + rm x && + test_expect_code 1 git diff -w $opts --exit-code -- x + ' + + test_expect_success "status with $opts (different but equivalent)" ' + echo foo >x && + git add x && + echo " foo" >x && + git diff -w $opts --exit-code x + ' +done + test_expect_success "Ray Lehtiniemi's example" ' cat <<-\EOF >x && do { From patchwork Fri Aug 18 23:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13358378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AF3CEE49A2 for ; Sat, 19 Aug 2023 00:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243043AbjHRX7x (ORCPT ); Fri, 18 Aug 2023 19:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243137AbjHRX7n (ORCPT ); Fri, 18 Aug 2023 19:59:43 -0400 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E0FB3AAE for ; Fri, 18 Aug 2023 16:59:42 -0700 (PDT) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id AAAEC1A3C91; Fri, 18 Aug 2023 19:59:41 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=VjJgijPc/v86MgoPQfgE5TFr6 ncqjwK2vV40zXVIiBU=; b=QM5v4nexNJ+zYIwJepBvvqCBZs6z8euTd2U3VyYFm wQdKFOfBCWeliDyUjLFailj6BpHN1xIo7DkqUMa8QBUQREVIyciP0whNdjqaNPo8 bFPpmSUzJlWQuCXbqzr6ofRfyimMMfIcCnwDo6oey3bA1sp7SH0wP+RlBXTWtYLc xk= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id A2E151A3C90; Fri, 18 Aug 2023 19:59:41 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.58.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 1B14B1A3C8F; Fri, 18 Aug 2023 19:59:41 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 3/5] diff: teach "--stat -w --exit-code" to notice differences Date: Fri, 18 Aug 2023 16:59:30 -0700 Message-ID: <20230818235932.3253552-4-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-rc2-7-gf9972720e9 In-Reply-To: <20230818235932.3253552-1-gitster@pobox.com> References: <20230817222949.3835424-1-gitster@pobox.com> <20230818235932.3253552-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 4BC809C8-3E23-11EE-979B-78DCEB2EC81B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When options like "-w" is used while "--exit-code" option is in effect, instead of the usual "do we have any filepair whose preimage and postimage have different ?" check, we need to compare the contents of the blobs, taking into account that certain changes are considered no-op. With the previous step, we taught "--patch" codepath to set the .found_changes bit correctly, even for a change that only affects the mode and not object. The "--stat" codepath, however, did not set the .found_changes bit at all. This lead to $ git diff --stat -w --exit-code for a change that does have an output to exit with status 0. Set the bit by inspecting the list of paths the diffstat output is given for (a mode-only change will still appear as a "0-line added 0-line deleted" change) to fix it. Signed-off-by: Junio C Hamano --- diff.c | 1 + t/t4015-diff-whitespace.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 998d7ae20c..da965ff688 100644 --- a/diff.c +++ b/diff.c @@ -6901,6 +6901,7 @@ void compute_diffstat(struct diff_options *options, if (check_pair_status(p)) diff_flush_stat(p, options, diffstat); } + options->found_changes = !!diffstat->nr; } void diff_addremove(struct diff_options *options, diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 02731dccb9..230a89b951 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -11,7 +11,7 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh -for opts in --patch --quiet -s +for opts in --patch --quiet -s --stat --shortstat --dirstat=lines do test_expect_success "status with $opts (different)" ' From patchwork Fri Aug 18 23:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13358379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59B7EEE49A3 for ; Sat, 19 Aug 2023 00:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243070AbjHRX7x (ORCPT ); Fri, 18 Aug 2023 19:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243139AbjHRX7r (ORCPT ); Fri, 18 Aug 2023 19:59:47 -0400 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85AF72D65 for ; Fri, 18 Aug 2023 16:59:46 -0700 (PDT) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 018282002A; Fri, 18 Aug 2023 19:59:46 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=wk5IOMhHdk3rj/rcsPwntHaOQ Vw9km6+CyrejWNCzd8=; b=PSjuARCinoxnpsaBGJS8vjLdUCI9KsBrlqIy4yuOH fCfI/gA1ohHc78Bg0JlMRkWjzvbzx0WspuVrcnCKuNZTvEjT8CZPt5VrPROfignH Vf8UjB2bQTbjC9FtiG8kDEljlRjx340oh7UqfcDVOr5T6zoi+AJ7t/hTYwPqBksw QQ= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id EEA1C20029; Fri, 18 Aug 2023 19:59:45 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.58.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id AAFFD20028; Fri, 18 Aug 2023 19:59:42 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 4/5] t4040: remove test that succeeded for a wrong reason Date: Fri, 18 Aug 2023 16:59:31 -0700 Message-ID: <20230818235932.3253552-5-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-rc2-7-gf9972720e9 In-Reply-To: <20230818235932.3253552-1-gitster@pobox.com> References: <20230817222949.3835424-1-gitster@pobox.com> <20230818235932.3253552-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 4CBACA32-3E23-11EE-9022-A19503B9AAD1-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "diff-tree -b --exit-code" without "--patch" exits with 0 status, not because it finds that the two input files are equivalent while ignoring whitespaces, but because the implied "--raw" mode always exits with 0 when whitespace tweaking options like "-b" and "-w" are given, which is a long-standing bug. We are about to fix it so that "--raw" and friends report the differences with the exit status (even though they ignore the whitespace tweaking options when producing their output), which will make this test, which succeeded for a wrong reason, start failing. Remove it. Signed-off-by: Junio C Hamano --- t/t4040-whitespace-status.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/t/t4040-whitespace-status.sh b/t/t4040-whitespace-status.sh index e70e020ae9..eec3d73dc2 100755 --- a/t/t4040-whitespace-status.sh +++ b/t/t4040-whitespace-status.sh @@ -28,8 +28,7 @@ test_expect_success 'diff-tree --exit-code' ' test_expect_success 'diff-tree -b --exit-code' ' git diff -b --exit-code HEAD^ HEAD && - git diff-tree -b -p --exit-code HEAD^ HEAD && - git diff-tree -b --exit-code HEAD^ HEAD + git diff-tree -b -p --exit-code HEAD^ HEAD ' test_expect_success 'diff-index --cached --exit-code' ' From patchwork Fri Aug 18 23:59:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13358381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08A11EE499F for ; Sat, 19 Aug 2023 00:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243121AbjHSAAZ (ORCPT ); Fri, 18 Aug 2023 20:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243015AbjHRX7w (ORCPT ); Fri, 18 Aug 2023 19:59:52 -0400 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CE563AAE for ; Fri, 18 Aug 2023 16:59:51 -0700 (PDT) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id E1CB729F25; Fri, 18 Aug 2023 19:59:50 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=d4jwQiqXt+v/Z0ZVaMZ5O8e73 9TXiskvGpkRGFTZVjU=; b=gmlVPpKS3sVlaFkAQ3RJxj7U/CphutaoMwER2nWNP 5AHPxE0VFEi0+PGPt2S9iaI6CjivmGrqNLjs5cvvnDbwWRPUoytS58PB5T8LEEbw pDlCp8lAp+fIt+wcMl7RRzylXeuGVGvAEU/q8SD1LDOflvsevli9v5gvAdkk7yg4 Hk= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id DC1B629F24; Fri, 18 Aug 2023 19:59:50 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.58.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id D712F29F23; Fri, 18 Aug 2023 19:59:45 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 5/5] diff: the -w option breaks --exit-code for --raw and other output modes Date: Fri, 18 Aug 2023 16:59:32 -0700 Message-ID: <20230818235932.3253552-6-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-rc2-7-gf9972720e9 In-Reply-To: <20230818235932.3253552-1-gitster@pobox.com> References: <20230817222949.3835424-1-gitster@pobox.com> <20230818235932.3253552-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 4EA02C70-3E23-11EE-A8BB-F515D2CDFF5E-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The output from "--raw", "--name-status", and "--name-only" modes in "git diff" does depend on and does not reflect how certain different contents are considered equal, unlike "--patch" and "--stat" output modes do, when used with options like "-w" (another way of thinking about it is that it is not like we recompute the hash of the blob after removing all whitespaces to show "git diff --raw -w" output). But that is not an excuse for "git diff --exit-code --raw" to fail to report differences with its exit status, when used with options like "-w". Make sure the command exits with 1 when these options report paths that are different. Signed-off-by: Junio C Hamano --- diff.c | 6 ++++++ t/t4015-diff-whitespace.sh | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index da965ff688..78f4e7518f 100644 --- a/diff.c +++ b/diff.c @@ -4744,6 +4744,10 @@ void diff_setup_done(struct diff_options *options) else options->prefix_length = 0; + /* + * --name-only, --name-status, --checkdiff, and -s + * turn other output format off. + */ if (options->output_format & (DIFF_FORMAT_NAME | DIFF_FORMAT_NAME_STATUS | DIFF_FORMAT_CHECKDIFF | @@ -6072,6 +6076,8 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt) fprintf(opt->file, "%s", diff_line_prefix(opt)); write_name_quoted(name_a, opt->file, opt->line_termination); } + + opt->found_changes = 1; } static void show_file_mode_name(struct diff_options *opt, const char *newdelete, struct diff_filespec *fs) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 230a89b951..7fcffa4b11 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -11,8 +11,12 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh -for opts in --patch --quiet -s --stat --shortstat --dirstat=lines +for opt_res in --patch --quiet -s --stat --shortstat --dirstat=lines \ + --raw! --name-only! --name-status! do + opts=${opt_res%!} expect_failure= + test "$opts" = "$opt_res" || + expect_failure="test_expect_code 1" test_expect_success "status with $opts (different)" ' echo foo >x && @@ -40,7 +44,7 @@ do echo foo >x && git add x && echo " foo" >x && - git diff -w $opts --exit-code x + $expect_failure git diff -w $opts --exit-code x ' done