From patchwork Tue Nov 17 21:35:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Altmanninger X-Patchwork-Id: 11913569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA655C6379D for ; Tue, 17 Nov 2020 21:36:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53F46221F9 for ; Tue, 17 Nov 2020 21:36:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f3Bcn5vR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbgKQVgF (ORCPT ); Tue, 17 Nov 2020 16:36:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726136AbgKQVgE (ORCPT ); Tue, 17 Nov 2020 16:36:04 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41638C0613CF for ; Tue, 17 Nov 2020 13:36:04 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id e18so24081517edy.6 for ; Tue, 17 Nov 2020 13:36:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ss7GyOaT78nJ5Jk3PH2IClj2LsH5TJucGg9eP+H5lDQ=; b=f3Bcn5vR+XrNNPUWcDukU9EslMzkbcSfkvWRp1kuEaajBjvq4Wy01AjPOJC2aYp68G bxTJPDEAkW3+SS7D6HfVQJhn6Aywnh8+ctoKLTd5d53h57X0tjVPkeUMfjYgQIoAq3DM dDpKgW+DB1JieAoS2IE/gKAjsSbIxxNLP1WP8VXi8BgdgLQwRovi5D6PE9Tme9SMCXko KsaDNRf1U3HnCAw1YM3AGGqybNgNjE+XyKnB+7ugi3Zac8Uv6EDcPxGi/2CREUJVXhN/ oAY3jD4n3nILCdxy7a9Agn6kq9g+NPLVD0/peMH632qeBdp/X5JJcApLpS+y5xiazg/G 87Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ss7GyOaT78nJ5Jk3PH2IClj2LsH5TJucGg9eP+H5lDQ=; b=pStd6Ej9V7k6/G8lr8ru1cqH4KmDSrwhtP7fdqZaVez62Wxi/1ySiqIN/j1Y5FR4yn 1INvWVqM6/vsca/NiJHBd0Zs3VcnMFlSii2pLNPaz5VPDge64mSmYaL0GelvVK024hTu /aiQ3RYUNdZ7yWr7zeb3nibOgrg6BZ+/w7Skq/WNaL6yuv6Xy6Y4Dp+D9YGS9b2EROup 8OUx2BEzQ2qz5Yr+CNFp5W3vNE9cCwyXEooGiS4jRcfxRYMcL/6ZdoIyVOTeS2pHF4+7 q9A3yDBNMQDcUBcm88eZFuInToPpk4+UrJ+veCNiurZVRyfqvjdHPmMuos53YC62HOVx N0Tg== X-Gm-Message-State: AOAM531a5FnIIQDL6vcxs3j4OG9RhP4wWf75nsUYKZrpHy7vZrvE0bla xZUfZUmKk2JKGUkDqCRunCg= X-Google-Smtp-Source: ABdhPJxi9pKgTnGYiaLCSNmc4bpgtNr8CWzxcTJLJ9ep/nwUbj4424uuj5qCXZQlebrsZUoSVi7xAg== X-Received: by 2002:a50:9e8a:: with SMTP id a10mr23599501edf.150.1605648962967; Tue, 17 Nov 2020 13:36:02 -0800 (PST) Received: from localhost.localdomain (178.115.129.143.wireless.dyn.drei.com. [178.115.129.143]) by smtp.gmail.com with ESMTPSA id by8sm12623417edb.49.2020.11.17.13.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 13:36:02 -0800 (PST) From: Johannes Altmanninger To: gitster@pobox.com Cc: git@vger.kernel.org, newren@gmail.com, peff@peff.net, Johannes Altmanninger Subject: [PATCH 1/3] range-diff: move " ## filename ##" headers to the first column Date: Tue, 17 Nov 2020 22:35:49 +0100 Message-Id: <20201117213551.2539438-2-aclopte@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117213551.2539438-1-aclopte@gmail.com> References: <20201117213551.2539438-1-aclopte@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Output of range-diff may include comparisons of metadata like commit messages and filenames. Metadata lines look like " ## ##". When range-diff compares two matching commits, it computes a diff of two special commit diffs. In these commit diffs, each changed file is introduced with a " ## filename ##" line which is followed by the diff hunks with changes to the file's contents. The leading space makes it hard to distinguish between file metadata lines and context lines from a diff hunk, especially when looking only at the output of range-diff. Drop the space prefix to facilitate that. --- range-diff.c | 4 ++-- t/t3206-range-diff.sh | 42 +++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/range-diff.c b/range-diff.c index 24dc435e48..72660453bd 100644 --- a/range-diff.c +++ b/range-diff.c @@ -136,7 +136,7 @@ static int read_patches(const char *range, struct string_list *list, if (len < 0) die(_("could not parse git header '%.*s'"), orig_len, line); - strbuf_addstr(&buf, " ## "); + strbuf_addstr(&buf, "## "); if (patch.is_new > 0) strbuf_addf(&buf, "%s (new)", patch.new_name); else if (patch.is_delete > 0) @@ -432,7 +432,7 @@ static void output_pair_header(struct diff_options *diffopt, } static struct userdiff_driver section_headers = { - .funcname = { "^ ## (.*) ##$\n" + .funcname = { "^ ?## (.*) ##$\n" "^.?@@ (.*)$", REG_EXTENDED } }; diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index 6eb344be03..f875843b5e 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -304,8 +304,8 @@ test_expect_success 'renamed file' ' - s/4/A/ + s/4/A/ + rename file Z - - ## file ## - + ## file => renamed-file ## + -## file ## + +## file => renamed-file ## Z@@ Z 1 Z 2 @@ -314,9 +314,9 @@ test_expect_success 'renamed file' ' Z ## Commit message ## Z s/11/B/ Z - - ## file ## + -## file ## -@@ file: A - + ## renamed-file ## + +## renamed-file ## +@@ renamed-file: A Z 8 Z 9 @@ -326,9 +326,9 @@ test_expect_success 'renamed file' ' Z ## Commit message ## Z s/12/B/ Z - - ## file ## + -## file ## -@@ file: A - + ## renamed-file ## + +## renamed-file ## +@@ renamed-file: A Z 9 Z 10 @@ -348,14 +348,14 @@ test_expect_success 'file with mode only change' ' - s/4/A/ + s/4/A/ + add other-file Z - Z ## file ## + Z## file ## Z@@ @@ file Z A Z 6 Z 7 + - + ## other-file (new) ## + +## other-file (new) ## 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/ @@ Metadata ZAuthor: Thomas Rast @@ -364,14 +364,14 @@ test_expect_success 'file with mode only change' ' - s/11/B/ + s/11/B/ + mode change other-file Z - Z ## file ## + Z## file ## Z@@ file: A @@ file: A Z 12 Z 13 Z 14 + - + ## other-file (mode change 100644 => 100755) ## + +## other-file (mode change 100644 => 100755) ## 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/ EOF test_cmp expect actual @@ -389,14 +389,14 @@ test_expect_success 'file added and later removed' ' - s/4/A/ + s/4/A/ + new-file Z - Z ## file ## + Z## file ## Z@@ @@ file Z A Z 6 Z 7 + - + ## new-file (new) ## + +## new-file (new) ## 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/ @@ Metadata ZAuthor: Thomas Rast @@ -405,14 +405,14 @@ test_expect_success 'file added and later removed' ' - s/11/B/ + s/11/B/ + remove file Z - Z ## file ## + Z## file ## Z@@ file: A @@ file: A Z 12 Z 13 Z 14 + - + ## new-file (deleted) ## + +## new-file (deleted) ## 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/ EOF test_cmp expect actual @@ -434,7 +434,7 @@ test_expect_success 'changed message' ' Z + Also a silly comment here! + - Z ## file ## + Z## file ## Z@@ Z 1 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/ @@ -453,7 +453,7 @@ test_expect_success 'dual-coloring' ' : : + Also a silly comment here! : + - : ## file ## + : ## file ## : @@ : 1 :3: $(test_oid c3) ! 3: $(test_oid m3) s/11/B/ @@ -537,7 +537,7 @@ test_expect_success 'range-diff compares notes by default' ' - topic note + unmodified note Z - Z ## file ## + Z## file ## Z@@ file: A EOF test_cmp expect actual @@ -584,7 +584,7 @@ test_expect_success 'range-diff with multiple --notes' ' - topic note2 + unmodified note2 Z - Z ## file ## + Z## file ## Z@@ file: A EOF test_cmp expect actual @@ -645,7 +645,7 @@ test_expect_success 'format-patch --range-diff with --notes' ' - topic note + unmodified note Z - Z ## file ## + Z## file ## Z@@ file: A EOF sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && @@ -674,7 +674,7 @@ test_expect_success 'format-patch --range-diff with format.notes config' ' - topic note + unmodified note Z - Z ## file ## + Z## file ## Z@@ file: A EOF sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && @@ -710,7 +710,7 @@ test_expect_success 'format-patch --range-diff with multiple notes' ' - topic note2 + unmodified note2 Z - Z ## file ## + Z## file ## Z@@ file: A EOF sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && From patchwork Tue Nov 17 21:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Altmanninger X-Patchwork-Id: 11913571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89F81C64E7A for ; Tue, 17 Nov 2020 21:36:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EA372465E for ; Tue, 17 Nov 2020 21:36:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FaFx1ji5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728165AbgKQVgI (ORCPT ); Tue, 17 Nov 2020 16:36:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726136AbgKQVgH (ORCPT ); Tue, 17 Nov 2020 16:36:07 -0500 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B83C9C0617A6 for ; Tue, 17 Nov 2020 13:36:05 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id t11so24012309edj.13 for ; Tue, 17 Nov 2020 13:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D5QPhMjYOYZA0kT+wtHZpymZhEACpt3XCZfdWnjrcd4=; b=FaFx1ji5Emu5Sedaa5AwuyWzRwhZ9nKwOf8ty9LdkUNFDCL90BGwAu0jmiyoXuIzTg cStfpnVfI+GnEf4RlLCp3Wyj+GTMXb8U7AC2/uWxGtdw2FJX0SkZ8zkmfzx5eNtrcyCZ 3TCSqo+X3A6v2n5S9vQKsCoHRrOunTbeCdX1sjU+5lOB/FxbEfE10Y5d1sooS8OSxHUk //tTHty1kJbji6+7E7sAR3pAZ2W2GGpSJXe4WBN/fb0mCVZ4dZuXsHatmb5IEBcVDdrS oBVtPG9sj8wlXh7l7j4G+NA5u7f79sCIzJtKaqgHQnK3jLyuUw7x/84mFsJu/Jg5Zkpw Z2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D5QPhMjYOYZA0kT+wtHZpymZhEACpt3XCZfdWnjrcd4=; b=DsNBZNM3je9g+on/D65Juy01d7Rkt6xH98qvcX51YEWvYjl8z0TKBbVEbzADgyBIE8 rqgG8lGs35Ha0TNQ/oiLp68QGumlgZAFvvxyh1L201dH1yLbI4qyg/S1uMHb3sW5cx+h vuOKd3LgsmtqlApexh0LSnUdB6D36Y5BBnA5fcE5TThdf+oEjJUujyaUnRVpk1VK1kN2 E9Hl1CPOKQ/Wehs7AJQU4X9AObUkJ6lbIMpXL8EjeaHezYmB7B7p7nTWH0CO1TncaMne eNzJsYResT/ALEzNbxv81XqHEl2OlM1WBwWsfuMxOJKMiQ7yd32bGLp+iKChOAARMlpF VkFg== X-Gm-Message-State: AOAM533rPnHtS9SD3vntCscBSchWZGkuxXHUHPelosApdOF79O+DAYSP rihPViCeIbVxHO3Hfqdxz3Q= X-Google-Smtp-Source: ABdhPJxRSRGEBw4FVVxwxoynaaZyqVPKRuW0KLbcfXKCI5u28Wm3ugyKCj1mQzOGV4hPU82UGt2MAw== X-Received: by 2002:aa7:d890:: with SMTP id u16mr22951175edq.159.1605648964469; Tue, 17 Nov 2020 13:36:04 -0800 (PST) Received: from localhost.localdomain (178.115.129.143.wireless.dyn.drei.com. [178.115.129.143]) by smtp.gmail.com with ESMTPSA id by8sm12623417edb.49.2020.11.17.13.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 13:36:03 -0800 (PST) From: Johannes Altmanninger To: gitster@pobox.com Cc: git@vger.kernel.org, newren@gmail.com, peff@peff.net, Johannes Altmanninger Subject: [PATCH 2/3] range-diff: ignore context-only changes Date: Tue, 17 Nov 2020 22:35:50 +0100 Message-Id: <20201117213551.2539438-3-aclopte@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117213551.2539438-1-aclopte@gmail.com> References: <20201117213551.2539438-1-aclopte@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org range-diff compares matching commits by comparing their patches against each other. When two patches only differ in their context lines, that difference would still show up in range-diff's output. This commit uses diff's new -I/--ignore-matching-lines regex logic to ignore Signed-off-by: is missing from all of your patches. diff hunks that only consist of changes to context lines in the input diffs. Thanks to the previous commit, lines like "## file => renamed-file ##" are not considered context lines because they no longer have a leading space. This gives some extra @@ lines because we now always calculate two diffs: one for the patch metadata, like the commit message, and another one for the actual file changes. This is because the former contains lines with leading spaces that are not context lines, so we never want to ignore them. --- range-diff.c | 58 +++++++++++++++++++++++++----- t/t3206-range-diff.sh | 83 ++++++------------------------------------- 2 files changed, 60 insertions(+), 81 deletions(-) diff --git a/range-diff.c b/range-diff.c index 72660453bd..df2147ef79 100644 --- a/range-diff.c +++ b/range-diff.c @@ -363,6 +363,31 @@ static void get_correspondences(struct string_list *a, struct string_list *b, free(b2a); } +static int are_diffs_equivalent(const char *a_diff, const char *b_diff) { + for ( + const char + *a_eol = strchr(a_diff, '\n'), + *b_eol = strchr(b_diff, '\n'); + (a_eol = strchr(a_diff, '\n')) && + (b_eol = strchr(b_diff, '\n')); + a_diff = a_eol + 1, b_diff = b_eol + 1 + ) { + if (!!a_eol != !!b_eol) + return 0; + + // Ignore context lines. + if (a_diff[0] == ' ' && b_diff[0] == ' ') + continue; + + size_t a_len = a_eol - a_diff; + size_t b_len = b_eol - b_diff; + if (a_len != b_len || strncmp(a_diff, b_diff, a_len)) + return 0; + } + + return 1; +} + static void output_pair_header(struct diff_options *diffopt, int patch_no_width, struct strbuf *buf, @@ -390,8 +415,10 @@ static void output_pair_header(struct diff_options *diffopt, } else if (!a_util) { color = color_new; status = '>'; - } else if (strcmp(a_util->patch, b_util->patch)) { - color = color_commit; + } else if (a_util->diff_offset != b_util->diff_offset + || strncmp(a_util->patch, b_util->patch, a_util->diff_offset) + || !are_diffs_equivalent(a_util->diff, b_util->diff)) { + color = color_commit; status = '!'; } else { color = color_commit; @@ -436,13 +463,13 @@ static struct userdiff_driver section_headers = { "^.?@@ (.*)$", REG_EXTENDED } }; -static struct diff_filespec *get_filespec(const char *name, const char *p) +static struct diff_filespec *get_filespec(const char *name, const char *p, size_t size) { struct diff_filespec *spec = alloc_filespec(name); fill_filespec(spec, &null_oid, 0, 0100644); spec->data = (char *)p; - spec->size = strlen(p); + spec->size = size; spec->should_munmap = 0; spec->is_stdin = 1; spec->driver = §ion_headers; @@ -450,11 +477,11 @@ static struct diff_filespec *get_filespec(const char *name, const char *p) return spec; } -static void patch_diff(const char *a, const char *b, +static void patch_diff(const char *a, size_t size_a, const char *b, size_t size_b, struct diff_options *diffopt) { diff_queue(&diff_queued_diff, - get_filespec("a", a), get_filespec("b", b)); + get_filespec("a", a, size_a), get_filespec("b", b, size_b)); diffcore_std(diffopt); diff_flush(diffopt); @@ -467,6 +494,14 @@ static void output(struct string_list *a, struct string_list *b, int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr)); int i = 0, j = 0; + regex_t regex; + if (regcomp(®ex, "^ ", REG_EXTENDED | REG_NEWLINE)) + BUG("invalid regex"); + ALLOC_GROW(diffopt->ignore_regex, diffopt->ignore_regex_nr + 1, + diffopt->ignore_regex_alloc); + diffopt->ignore_regex[diffopt->ignore_regex_nr] = ®ex; + size_t ignoring_context_only_changes = diffopt->ignore_regex_nr + 1; + /* * We assume the user is really more interested in the second argument * ("newer" version). To that end, we print the output in the order of @@ -504,9 +539,14 @@ static void output(struct string_list *a, struct string_list *b, a_util = a->items[b_util->matching].util; output_pair_header(diffopt, patch_no_width, &buf, &dashes, a_util, b_util); - if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT)) - patch_diff(a->items[b_util->matching].string, - b->items[j].string, diffopt); + if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT)) { + patch_diff(a_util->patch, a_util->diff_offset, + b_util->patch, b_util->diff_offset, diffopt); + diffopt->ignore_regex_nr = ignoring_context_only_changes; + patch_diff(a_util->diff, strlen(a_util->diff), + b_util->diff, strlen(b_util->diff), diffopt); + diffopt->ignore_regex_nr = ignoring_context_only_changes - 1; + } a_util->shown = 1; j++; } diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index f875843b5e..9a63388bee 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -223,16 +223,7 @@ test_expect_success 'changed commit' ' 12 13 14 - 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ - @@ file - @@ file: A - 9 - 10 - - B - + BB - -12 - +B - 13 + 4: $(test_oid t4) = 4: $(test_oid c4) s/12/B/ EOF test_cmp expect actual ' @@ -243,7 +234,7 @@ test_expect_success 'changed commit with --no-patch diff option' ' 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ - 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ + 4: $(test_oid t4) = 4: $(test_oid c4) s/12/B/ EOF test_cmp expect actual ' @@ -256,9 +247,7 @@ test_expect_success 'changed commit with --stat diff option' ' 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ a => b | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) - 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ - a => b | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) + 4: $(test_oid t4) = 4: $(test_oid c4) s/12/B/ EOF test_cmp expect actual ' @@ -278,16 +267,7 @@ test_expect_success 'changed commit with sm config' ' 12 13 14 - 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ - @@ file - @@ file: A - 9 - 10 - - B - + BB - -12 - +B - 13 + 4: $(test_oid t4) = 4: $(test_oid c4) s/12/B/ EOF test_cmp expect actual ' @@ -304,16 +284,14 @@ test_expect_success 'renamed file' ' - s/4/A/ + s/4/A/ + rename file Z + @@ -## file ## +## file => renamed-file ## Z@@ Z 1 Z 2 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/ - @@ Metadata - Z ## Commit message ## - Z s/11/B/ - Z + @@ -## file ## -@@ file: A +## renamed-file ## @@ -322,10 +300,7 @@ test_expect_success 'renamed file' ' Z 9 Z 10 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/ - @@ Metadata - Z ## Commit message ## - Z s/12/B/ - Z + @@ -## file ## -@@ file: A +## renamed-file ## @@ -348,8 +323,6 @@ test_expect_success 'file with mode only change' ' - s/4/A/ + s/4/A/ + add other-file Z - Z## file ## - Z@@ @@ file Z A Z 6 @@ -364,8 +337,6 @@ test_expect_success 'file with mode only change' ' - s/11/B/ + s/11/B/ + mode change other-file Z - Z## file ## - Z@@ file: A @@ file: A Z 12 Z 13 @@ -389,8 +360,6 @@ test_expect_success 'file added and later removed' ' - s/4/A/ + s/4/A/ + new-file Z - Z## file ## - Z@@ @@ file Z A Z 6 @@ -405,8 +374,6 @@ test_expect_success 'file added and later removed' ' - s/11/B/ + s/11/B/ + remove file Z - Z## file ## - Z@@ file: A @@ file: A Z 12 Z 13 @@ -434,9 +401,6 @@ test_expect_success 'changed message' ' Z + Also a silly comment here! + - Z## file ## - Z@@ - Z 1 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/ 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/ EOF @@ -453,9 +417,6 @@ test_expect_success 'dual-coloring' ' : : + Also a silly comment here! : + - : ## file ## - : @@ - : 1 :3: $(test_oid c3) ! 3: $(test_oid m3) s/11/B/ : @@ file: A : 9 @@ -466,16 +427,7 @@ test_expect_success 'dual-coloring' ' : 12 : 13 : 14 - :4: $(test_oid c4) ! 4: $(test_oid m4) s/12/B/ - : @@ file - : @@ file: A - : 9 - : 10 - : - BB - : + B - : -12 - : +B - : 13 + :4: d966c5c = 4: 8add5f1 s/12/B/ EOF git range-diff changed...changed-message --color --dual-color >actual.raw && test_decode_color >actual actual && + sed "/@@ Commit message/,/unmodified note\$/!d" 0000-* >actual && test_cmp expect actual ' @@ -673,11 +618,8 @@ test_expect_success 'format-patch --range-diff with format.notes config' ' Z ## Notes ## - topic note + unmodified note - Z - Z## file ## - Z@@ file: A EOF - sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && + sed "/@@ Commit message/,/unmodified note\$/!d" 0000-* >actual && test_cmp expect actual ' @@ -709,11 +651,8 @@ test_expect_success 'format-patch --range-diff with multiple notes' ' Z ## Notes (note2) ## - topic note2 + unmodified note2 - Z - Z## file ## - Z@@ file: A EOF - sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && + sed "/@@ Commit message/,/unmodified note2\$/!d" 0000-* >actual && test_cmp expect actual ' From patchwork Tue Nov 17 21:35:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Altmanninger X-Patchwork-Id: 11913573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29121C64E69 for ; Tue, 17 Nov 2020 21:36:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB2D1221F9 for ; Tue, 17 Nov 2020 21:36:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OaTYlRoc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728186AbgKQVgI (ORCPT ); Tue, 17 Nov 2020 16:36:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728160AbgKQVgH (ORCPT ); Tue, 17 Nov 2020 16:36:07 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22876C0613CF for ; Tue, 17 Nov 2020 13:36:07 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id oq3so31499804ejb.7 for ; Tue, 17 Nov 2020 13:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pxTYoQ+UCwjJ5cJTU5ii7+zH6QrQ0S4pwzOx/HgkXwA=; b=OaTYlRoc0TRFjKp4sqlyqFuDfTy6xIKBe5HcSH/qtOFr6yK8kYrygdHiCAF7ud53E8 aZIDzQwIAJzN9ZQmifXH59hxtaLc5zw27IX/VvZ6uCKuLKk+Slb6ywHH0P0auG02JoLc hl1/nhe3QXslYyFaZbX3KyiPxBsY8dsVRij5L47jhvYkjPpu7tgM6oOYmhsIdUbn3wXY h6hoBUF5K2oPyOPBZf5C/6IZMriQjidZeQ5DgGN5jBT6Ul3mopYXKTIXD+vycHlwsiAz uf5IYmFZPbaFIOdqIQiX1DRfgJ3IEtbWwMKBTsYl93ThmzJ5BYt/6kxHS3DtMKjeR0L1 1IPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pxTYoQ+UCwjJ5cJTU5ii7+zH6QrQ0S4pwzOx/HgkXwA=; b=UpRO/vzAb15cT6Jr+uWDekvmeqmmRK8bDxXOhYLBKOuxY4+kGZ+b98P2ix7EvJztuO g08FpSm6EaijEHn8Ktnvodum7KBeSaFkRodOGv2deroWp+Z4ADIPo6qr0dxKFqzVWpL0 NXF6eJZRn891UACvywt5p1CPH9PpUed0yZNRWE+0I8hFVGJ04EYhIBJ6ZVfjrG5Yos4b DHae4W6XYEE2eNAEd+oPSj4ACieowz8aiZdnStKa/hr6R4IULP3hfWTWyBNVO+Wt0c7A TmzRyVUjXUK+ELI1uVZqsxaGJTNA9PllWRYB/ixMix5/ujCOUfu3MAT2rU38POa2HCWF ebbw== X-Gm-Message-State: AOAM532T2ZFoH4GXPBWZ2OQQg0fJti40CnIzbIYGSa8Wv/qLq8zIerPj ESjBghK62h/fHwqjsA0p+1g= X-Google-Smtp-Source: ABdhPJxJW9mNxMsokwrnYhiTDOInSkZysGN8reaGyDbm6nCgFxiRgSeEPhS6yJ7iSKcCf7yIOQxuWw== X-Received: by 2002:a17:906:9445:: with SMTP id z5mr12546059ejx.165.1605648965929; Tue, 17 Nov 2020 13:36:05 -0800 (PST) Received: from localhost.localdomain (178.115.129.143.wireless.dyn.drei.com. [178.115.129.143]) by smtp.gmail.com with ESMTPSA id by8sm12623417edb.49.2020.11.17.13.36.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 13:36:05 -0800 (PST) From: Johannes Altmanninger To: gitster@pobox.com Cc: git@vger.kernel.org, newren@gmail.com, peff@peff.net, Johannes Altmanninger Subject: [PATCH 3/3] range-diff: only compute patch diff when patches are different Date: Tue, 17 Nov 2020 22:35:51 +0100 Message-Id: <20201117213551.2539438-4-aclopte@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117213551.2539438-1-aclopte@gmail.com> References: <20201117213551.2539438-1-aclopte@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This is a pure optimization, probably with negligible impact. I'm not sure if it is a good idea because it could obscure future bugs. --- range-diff.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/range-diff.c b/range-diff.c index df2147ef79..343a71d3eb 100644 --- a/range-diff.c +++ b/range-diff.c @@ -388,7 +388,7 @@ static int are_diffs_equivalent(const char *a_diff, const char *b_diff) { return 1; } -static void output_pair_header(struct diff_options *diffopt, +static char output_pair_header(struct diff_options *diffopt, int patch_no_width, struct strbuf *buf, struct strbuf *dashes, @@ -456,6 +456,8 @@ static void output_pair_header(struct diff_options *diffopt, strbuf_addf(buf, "%s\n", color_reset); fwrite(buf->buf, buf->len, 1, diffopt->file); + + return status; } static struct userdiff_driver section_headers = { @@ -537,9 +539,9 @@ static void output(struct string_list *a, struct string_list *b, /* Show matching LHS/RHS pair. */ if (j < b->nr) { a_util = a->items[b_util->matching].util; - output_pair_header(diffopt, patch_no_width, + char status = output_pair_header(diffopt, patch_no_width, &buf, &dashes, a_util, b_util); - if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT)) { + if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT) && status != '=') { patch_diff(a_util->patch, a_util->diff_offset, b_util->patch, b_util->diff_offset, diffopt); diffopt->ignore_regex_nr = ignoring_context_only_changes;