From patchwork Wed Aug 24 21:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12953986 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 85427C04AA5 for ; Wed, 24 Aug 2022 21:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239717AbiHXVV6 (ORCPT ); Wed, 24 Aug 2022 17:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235803AbiHXVV4 (ORCPT ); Wed, 24 Aug 2022 17:21:56 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF648165BC for ; Wed, 24 Aug 2022 14:21:55 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n7so22275002wrv.4 for ; Wed, 24 Aug 2022 14:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=I3Ojpviz0Kfb3I0CUQKssWArPb+HJXPRsrZsL/QUGG0=; b=P9au5XwTDO0N2i1W20hdkVcP6aTu+hEk56PMEeJxc9LmIAE7OW92cdsc9NYBROkrdj 4vh9bhgGQEDJD3Lg6baGd+umzn2JG9oiargMyq2xSSI63+LbBnjcFydQgfenp/v3ZQYB E1sC1SwLsYp6uROqm3BVDeGz2wEnvIcQDeOnUDhcANKVy9suL6o8Doydk9+0O82f88Cg VnVY1yDaigsP/pZkhAdZvo9S2OCty8f8Yv8OXkiQ5ttJIjINiVM8XX10+8d6XSAdkrEC eErcVy86+Lvx2bFRkZQkUEVU5AlRLvYegpYvjv4NQKL8LhSUxPQDHvzrCHZj4mi/gXlJ 5i3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=I3Ojpviz0Kfb3I0CUQKssWArPb+HJXPRsrZsL/QUGG0=; b=MMdHhu7XWl3+Kl0VY5nrnjQPHkJwm+LxyrHG5BDzftwB21R3kbSZ9sDbAZLZBV+BUC hXIVy8zpId8GQ9LvyOOrv/ypaV9msD7WOfhBjh4OdICWyqUjNKjgYq15HZDVHsXquzRa wP7KqrvUThWp3kgakOFDzooN/Y8PsP0YFimzR3Q1Ia2f5wjG670mdakhRLAby7nM24I2 3NmpB/64dCgndjUS5fJVnAcXloXFQ6qmDFVJQ8tKkOLaA4Lk4lHEjhMVQuyZtn8eid9R GxroJL6wxKa5nm2104z1x/R7/hJuVnQU1A6S6/HnXMnSjTyVw2AlyZ/oNEaCt/U1jU36 78bg== X-Gm-Message-State: ACgBeo0XSmh6heeIRiBVGM+02kwO0XD5hTxFViC7fShwLRSI8th/ouBI 8k55KcSviIRQcqvjJmtsfgaT2VH+37g= X-Google-Smtp-Source: AA6agR6PdLjSpK4I5OGsr50MwY+v0i1zZ3b1V4dGjKKVy/iDgi7bM3a6cQ8H+2aYRjlGjXlsIlmZ5w== X-Received: by 2002:a5d:50c8:0:b0:225:75f6:2bf8 with SMTP id f8-20020a5d50c8000000b0022575f62bf8mr531088wrt.673.1661376114056; Wed, 24 Aug 2022 14:21:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k6-20020a5d6d46000000b00225221fd286sm17917907wri.114.2022.08.24.14.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 14:21:53 -0700 (PDT) Message-Id: <74ab50eeb1c6debd2f371e548cf6c782479f69af.1661376112.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 24 Aug 2022 21:21:48 +0000 Subject: [PATCH v2 1/4] t3701: redefine what is "bogus" output of a diff filter Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When parsing the colored version of a diff, the interactive `add` command really relies on the colored version having the same number of lines as the non-colored version. That is an invariant. However, in the 'detect bogus diffFilter output' test case in t3701, we essentially required a hunk header that contains parseable `@@ ... @@` hunk headers, and called all colored diffs without such hunks bogus. The reason for this is that we would like to show the users the adjusted hunk headers _including_ the extra part after the `@@ ... @@` information, which usually contains things like the function name or soms such. Now, there is a _very_ popular diff colorizer called `diff-so-fancy` that does not produce such colored diffs as the built-in `add` command expects. Nevertheless, the Perl variant of the `add` command handles those nicely, essentially by ignoring the hunk header and saying "there is nothing else we can show except the original hunk header, even if we had to adjust the line range and the original hunk header might get that wrong". In preparation for teaching the built-in interactive `add` to be a bit more lenient, let's change the 'detect bogus diffFilter output' test case so that it verifies that a mismatched number of lines causes the command to error out, but not an unparseable hunk header. Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index b354fb39de8..b40d1c94d99 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -761,7 +761,7 @@ test_expect_success 'detect bogus diffFilter output' ' git reset --hard && echo content >test && - test_config interactive.diffFilter "sed 1d" && + test_config interactive.diffFilter "sed q" && printf y >y && force_color test_must_fail git add -p X-Patchwork-Id: 12953987 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 93EDEC3F6B0 for ; Wed, 24 Aug 2022 21:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240039AbiHXVWA (ORCPT ); Wed, 24 Aug 2022 17:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239611AbiHXVV6 (ORCPT ); Wed, 24 Aug 2022 17:21:58 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E89C165BC for ; Wed, 24 Aug 2022 14:21:57 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id ay12so9331528wmb.1 for ; Wed, 24 Aug 2022 14:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=M/2g7wHp52k6Rtik7/3DhHa3bU30ZQdpTtM1UecamjY=; b=bvEQEElAKcHJRXCRrGFdVQzHad5rPCqL7tCfukIW/e6V66frQftyKVRK3wEuvzP+fT Dkp3zKF4w4CV3gmlhFvintk/BioZ8bpbZUfePRcR07Oq6nTAC8+QwGixRESKEfsYVe0W RPt0HlDAhcmvGhnnCeK+KdRR9Vi1lpliPvlRVe3a+JjrFewdXcNUDXJDRy+uf1A03heg 4y10p16ZwT3+b3mebLUDPzpqcF547cHEaS7psQBM9kvlzF72lSt/jRjgF5VyV/BkaFoz Zg/63ClcWE5tEFbz3DASJU/skJplScVmAEbC3siQCbFZvUdB9ktaLKIwSOJ/nvnJQ9Bs v4ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=M/2g7wHp52k6Rtik7/3DhHa3bU30ZQdpTtM1UecamjY=; b=TX8jlyG8GreXh38r6cgEoQu4V+TmRuT8QUI8XYNqVpz8HmWlZPN+E/57QTcSdKGYBs QP6qWHEeqXROvNZC7xu7V6SJSw/Tb7RUiXtdDxf0rXr2pUbRxP2qxFRBOB/9axGDhsfA /ndrc/9XDi9OENhgojcagK/GkFCqY0Ohpc7UNJwEz2YQ7W1yWs/zHUFyexEUgvOH9DPk hYtr5dv5ONir3yrD8Knyl9BzlinispcNQDudQaNHA0g34N5D8S7nISVDNcY/dzAEeDW/ WiNtjIIT2CWp+NCejplDDL/kRGvqolXRYc6KmR9nJIv8GWUvyVFtW1w0Ve0xZwHaVKRt 6qjw== X-Gm-Message-State: ACgBeo3m6jgprnJjBoztHUnSNbtDHjDvm53x+5oKbsalXlFM4bRgroQS l1jCt7LDqil0Dmlnglegk0NDF0zpYbo= X-Google-Smtp-Source: AA6agR4V8C6bAPfOZhPptBzgZtXAognAHBhcy3V/kdkejV41Xbz6hAI25awQJpGpnj3hvW9IcJUGcA== X-Received: by 2002:a05:600c:26d2:b0:3a6:280c:24a with SMTP id 18-20020a05600c26d200b003a6280c024amr6230249wmv.130.1661376115073; Wed, 24 Aug 2022 14:21:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o8-20020a05600c4fc800b003a603fbad5bsm3123441wmq.45.2022.08.24.14.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 14:21:54 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 24 Aug 2022 21:21:49 +0000 Subject: [PATCH v2 2/4] add -p: gracefully ignore unparseable hunk headers in colored diffs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In https://lore.kernel.org/git/ecf6f5be-22ca-299f-a8f1-bda38e5ca246@gmail.com, Phillipe Blain reported that the built-in `git add -p` command fails when asked to use [`diff-so-fancy`][diff-so-fancy] to colorize the diff. The reason is that this tool produces colored diffs with a hunk header that does not contain any parseable `@@ ... @@` line range information, and therefore we cannot detect any part in that header that comes after the line range. Let's punt for now and simply show nothing apart from the line range in that case. [diff-so-fancy]: https://github.com/so-fancy/diff-so-fancy Signed-off-by: Johannes Schindelin --- add-patch.c | 15 ++++++--------- t/t3701-add-interactive.sh | 9 +++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/add-patch.c b/add-patch.c index 509ca04456b..f2fffe1af02 100644 --- a/add-patch.c +++ b/add-patch.c @@ -357,16 +357,13 @@ static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk) eol = memchr(line, '\n', s->colored.len - hunk->colored_start); if (!eol) eol = s->colored.buf + s->colored.len; - p = memmem(line, eol - line, "@@ -", 4); - if (!p) - return error(_("could not parse colored hunk header '%.*s'"), - (int)(eol - line), line); - p = memmem(p + 4, eol - p - 4, " @@", 3); - if (!p) - return error(_("could not parse colored hunk header '%.*s'"), - (int)(eol - line), line); hunk->colored_start = eol - s->colored.buf + (*eol == '\n'); - header->colored_extra_start = p + 3 - s->colored.buf; + p = memmem(line, eol - line, "@@ -", 4); + if (p && (p = memmem(p + 4, eol - p - 4, " @@", 3))) + header->colored_extra_start = p + 3 - s->colored.buf; + else + /* could not parse colored hunk header, showing nothing */ + header->colored_extra_start = hunk->colored_start; header->colored_extra_end = hunk->colored_start; return 0; diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index b40d1c94d99..7e3c1de71f5 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -766,6 +766,15 @@ test_expect_success 'detect bogus diffFilter output' ' force_color test_must_fail git add -p test && + test_config interactive.diffFilter "sed s/@@/XX/g" && + printf y >y && + force_color git add -p X-Patchwork-Id: 12953988 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 55BEAC04AA5 for ; Wed, 24 Aug 2022 21:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239611AbiHXVWI (ORCPT ); Wed, 24 Aug 2022 17:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239719AbiHXVV6 (ORCPT ); Wed, 24 Aug 2022 17:21:58 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FE2167D6 for ; Wed, 24 Aug 2022 14:21:57 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id n23-20020a7bc5d7000000b003a62f19b453so1613974wmk.3 for ; Wed, 24 Aug 2022 14:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=ikFQWEfRdIynsdVGW6fUd+BYEfs3PqfKzNFN9wLsLzY=; b=KyigMd3p6TIGFFzKnTb5CYHrt2hpeEqd1GjjiBXJ5RG/rVd/BXcDbN8w4Jq5WBF01K bNb4ZZOyjzx2QOA5mcRrKKUJ17/KhQYhBU9aWfNarQP2Nptv/nVGoueJP8hy+3iKhkHe D8YO1qmJwOVCPmD9382qyoAfPZlUGPvTNpwuRr6Zo4uE6+XHQi4L9dP/Axbv+5IFZmKM JGeZQq6LZvj7fuSSa5TujWAvTGjXkZb5YRxkwElXtO89UOojq+nshGt5ekDxSswRIRbD uufRhrF7kxH4BHbTEZl9ASmfs49a7g0k3EYJB3YFjwjN8d5qdKKbHj9bLXmmqNUQToPv YfKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=ikFQWEfRdIynsdVGW6fUd+BYEfs3PqfKzNFN9wLsLzY=; b=OuDsQij2/vIroMBD/zJW6ho7D+vo3kX9b+QJ3UKU+5hB2YzYDKDRbOx9j0UPa66EXt h0N1YeoPzrmhU1N/QX4vC5TcQslpplBLNNzmZI+fEtt4mWq8//aWzC3G09tzFMGdJ6Oe rGxrrY+aBOH7iJQ74smv8zGSj0Aww3Lnp9X5iJ1KSa9TpUmCkYURyyhRdasp8c11rgQP Zaaf3zqHZ1sC1rba3u13K1Biha9BLKHSpPnQacK39xL4Da2Z0JYjSBLdxUPZtJ74YTH8 pJJG8BvFHPsai72BNKv0AfihVmQx7TddxVa051K14pS+rLuAllqMnlQJgpAvVjMd1VBp jQCw== X-Gm-Message-State: ACgBeo1ypEnbSDDDOIF/3Uqg44EcQgKxKceuD/gmAzYnM79Ea46B3jxE AKQSqCUJO7v5+KDYPYi9zVXEkmDTLrU= X-Google-Smtp-Source: AA6agR7u3VZMjUb9w13m0d/z4C574Yx2nHygCLpOTcjoVPrIb5iaPBIYmO+sR7kopfwPeJEJbpdtlQ== X-Received: by 2002:a05:600c:2f88:b0:3a5:4014:4b47 with SMTP id t8-20020a05600c2f8800b003a540144b47mr6294358wmn.96.1661376115879; Wed, 24 Aug 2022 14:21:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u18-20020adfdb92000000b0021eaf4138aesm22160088wri.108.2022.08.24.14.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 14:21:55 -0700 (PDT) Message-Id: <9dac9f74d2e19899b3e6c1d28e83878ded4469d6.1661376112.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 24 Aug 2022 21:21:50 +0000 Subject: [PATCH v2 3/4] add -p: handle `diff-so-fancy`'s hunk headers better Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The `diff-so-fancy` diff colorizer produces hunk headers that look nothing like the built-in `add -p` expects: there is no `@@ ... @@` line range, and therefore the parser cannot determine where any extra information starts, such as the function name that is often added to those hunk header lines. However, we can do better than simply swallowing the unparseable hunk header. In the `diff-so-fancy` case, it shows something like `@ file:1 @`. Let's just show the complete hunk header because it probably offers useful information. Signed-off-by: Johannes Schindelin --- add-patch.c | 8 +++++++- t/t3701-add-interactive.sh | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/add-patch.c b/add-patch.c index f2fffe1af02..1f3f3611ee9 100644 --- a/add-patch.c +++ b/add-patch.c @@ -8,6 +8,7 @@ #include "diff.h" #include "compat/terminal.h" #include "prompt.h" +#include "utf8.h" enum prompt_mode_type { PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_ADDITION, PROMPT_HUNK, @@ -363,7 +364,7 @@ static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk) header->colored_extra_start = p + 3 - s->colored.buf; else /* could not parse colored hunk header, showing nothing */ - header->colored_extra_start = hunk->colored_start; + header->colored_extra_start = line - s->colored.buf; header->colored_extra_end = hunk->colored_start; return 0; @@ -649,6 +650,7 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, size_t len; unsigned long old_offset = header->old_offset; unsigned long new_offset = header->new_offset; + int needs_extra_space = 0; if (!colored) { p = s->plain.buf + header->extra_start; @@ -658,6 +660,8 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, p = s->colored.buf + header->colored_extra_start; len = header->colored_extra_end - header->colored_extra_start; + if (utf8_strnwidth(p, len, 1 /* skip ANSI */) > 0) + needs_extra_space = 1; } if (s->mode->is_reverse) @@ -673,6 +677,8 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, strbuf_addf(out, ",%lu", header->new_count); strbuf_addstr(out, " @@"); + if (needs_extra_space) + strbuf_addch(out, ' '); if (len) strbuf_add(out, p, len); else if (colored) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 7e3c1de71f5..9deb7a87f1e 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -772,7 +772,8 @@ test_expect_success 'gracefully fail to parse colored hunk header' ' echo content >test && test_config interactive.diffFilter "sed s/@@/XX/g" && printf y >y && - force_color git add -p output 2>&1 X-Patchwork-Id: 12953989 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 B04F1C48BE4 for ; Wed, 24 Aug 2022 21:22:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240662AbiHXVWJ (ORCPT ); Wed, 24 Aug 2022 17:22:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239769AbiHXVV7 (ORCPT ); Wed, 24 Aug 2022 17:21:59 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A42EB165BC for ; Wed, 24 Aug 2022 14:21:58 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id e20so21771885wri.13 for ; Wed, 24 Aug 2022 14:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=S23Yrq2a5cJCgvTqD4EtlmQDsQQqxQPl5o1PKt5LxgI=; b=cTZ34AVF/AdbQkcJlbNu8m9FX4lIle3yPsmcUtIeJfHTVavdMwGbPhB1uvWxHMZ8YS uWxuGXeshXqeOuDWQN30UrGli2Z09anrQmGyGvRoW/5szgPs/L5NxuHhwMTV3/JH8Ey5 Si1KkKFtY6YH6cgTTrnBNxmdplCc6dOZuXmLFX4BzKg21sZmRDtS6Gj+h561VIh/FnEI NoHjEU/d5Eb8n1SGS0DA0miT+5t6168N4N0cvM3KiWUy7b148OYFM9foG8uWnjzShlrt FLnaxr7lfd6hSYZAWp3CXVmWr+aQEvXVHFRR2+hjEqbGhuauC680xdkzotDxSsVHpjzv 8SBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=S23Yrq2a5cJCgvTqD4EtlmQDsQQqxQPl5o1PKt5LxgI=; b=2M6PXDCiKbKnz9CrN60FQux7U5IHSWXGbtrj1TyfOiPtweTIlHfhLz3+miae4esN9e GS8nCmWoMkDEzsc1mJ9XYTdR7iJ1Tt7aXHSC0UUrBO8/jb5/JRDjOfkOCqLW+d7whg4B P4YkGNFB74IDmw3cWU24LYDnwHUYm1ABa8fqQcNWwm/fF/bP1l2dkY5ryybiDg2foaR9 N1SKMdjtm23oEsMDQUklUUlOLLoSlEIbhTbme3RUswQ10ADxlGdfqIiDgAmoWxQ/OlRj pqLDKZK4LrtdwoYdkaD+SMFE6xKBvaD+cqsDtR1xX+iEdrZEEEaKmzBohvb3Ud+1MMyx svKA== X-Gm-Message-State: ACgBeo3gaNVXLvpzutJOe7jwA1nihlDa5i8Le8ORnRLD7t/8c1BwiMgM dNJ6eg8AHw6g0oIttydHDnZnb8k11o4= X-Google-Smtp-Source: AA6agR71Z4Ldk9ABk6sdwiY9dcpTcPnHdyn/607E1gJIl6veccAjoetAThFr7HZ9NSqov+WvzDqpkA== X-Received: by 2002:a05:6000:1210:b0:225:5eeb:fdf3 with SMTP id e16-20020a056000121000b002255eebfdf3mr549756wrx.334.1661376116764; Wed, 24 Aug 2022 14:21:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bh19-20020a05600c3d1300b003a54d610e5fsm3253706wmb.26.2022.08.24.14.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 14:21:56 -0700 (PDT) Message-Id: <540ce27c38a68bebc9504a1cb19fb4076f87ae1c.1661376112.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 24 Aug 2022 21:21:51 +0000 Subject: [PATCH v2 4/4] add -p: ignore dirty submodules Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Thanks to alwyas running `diff-index` and `diff-files` with the `--numstat` option (the latter with `--ignore-submodules=dirty`) before even generating any real diff to parse, the Perl version of `git add -p` simply ignored dirty submodules and does not even offer them up for staging. However, the built-in variant did not use that flag because it tries to run only one `diff` command, skipping the unneeded `diff-index`/`diff-files` invocation of the Perl variant and therefore only faithfully recapitulates what the Perl code does once it _does_ generate and parse the real diff. This causes a problem when running the built-in `add -p` with `diff-so-fancy` because that diff colorizer always inserts an empty line before the diff header to ensure that it produces 4 lines as expected by `git add -p` (the equivalent of the non-colorized `diff`, `index`, `---` and `+++` lines). But `git diff-files` does not produce any `index` line for dirty submodules. The underlying problem is not even the discrepancy in lines, but that `git add -p` presents diffs for dirty submodules: there is nothing that _can_ be staged for those. Let's fix that bug, and teach the built-in `add -p` to ignore dirty submodules, too. This _incidentally_ also fixes the `diff-so-fancy` problem ;-) Signed-off-by: Johannes Schindelin --- add-patch.c | 3 ++- t/t3701-add-interactive.sh | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/add-patch.c b/add-patch.c index 1f3f3611ee9..64807e7cdc0 100644 --- a/add-patch.c +++ b/add-patch.c @@ -417,7 +417,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps) } color_arg_index = args.nr; /* Use `--no-color` explicitly, just in case `diff.color = always`. */ - strvec_pushl(&args, "--no-color", "-p", "--", NULL); + strvec_pushl(&args, "--no-color", "--ignore-submodules=dirty", "-p", + "--", NULL); for (i = 0; i < ps->nr; i++) strvec_push(&args, ps->items[i].original); diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 9deb7a87f1e..10058b7ce42 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -941,6 +941,18 @@ test_expect_success 'status ignores dirty submodules (except HEAD)' ' ! grep dirty-otherwise output ' +test_expect_success 'handle submodules' ' + echo 123 >>for-submodules/dirty-otherwise/initial.t && + + force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 && + grep "No changes" output && + + force_color git -C for-submodules add -p dirty-head >output 2>&1 actual && + rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" && + grep "$rev" actual +' + test_expect_success 'set up pathological context' ' git reset --hard && test_write_lines a a a a a a a a a a a >a &&