Article View: linux.kernel.git
Article #1958[PATCH v4 4/6] log: simplify --follow following renames for non-linear history
From: Miklos Vajna
Date: Fri, 30 Oct 2026 20:08
Date: Fri, 30 Oct 2026 20:08
199 lines
16677 bytes
16677 bytes
Code added in 304812ed33 (log: improve --follow following renames for
non-linear history, 2026-06-22) implemented the feature by introducing a
new propagate_follow_pathspec_to_parent() function which adds a new call
to diff_tree_oid(). Also it introduces a new loop to record what path
each parent of a merge commit should use when following a path.
This was working, but it caused a performance regression: e.g. 'git log
--stat --follow -- include/linux/rsc_table.h' in linux.git went from 28s
to 6m43s. The new code diffs each merge against each of its parents with
rename detection, which is expensive when a parent doesn't have the
followed path yet. Fixing this would require adding even more custom
code, instead of just extending the existing code in log_tree_diff(). So
first simplify the code here, and fix the performance regression in a
follow-up commit.
Remove propagate_follow_pathspec_to_parent() and the loop calling it
for each parent. Instead, record the path to follow for each parent in
the parent loop of log_tree_diff(), right after diff_tree_oid() updated
the pathspec in case of a rename. Merges are not diffed by default, so
with --follow, run the same loop for them as well, but without showing
anything. With -c, --cc or --remerge-diff, show the merge diff after the
loop. With --diff-merges=first-parent, keep diffing the other parents
silently, unless the walk only follows first parents. This gets rid of
the additional call to diff_tree_oid(). The rework has no positive
performance impact yet, it just simplifies the code.
The previous commit restores the path of the merge before diffing each
parent, and also after the loop, for
propagate_follow_pathspec_to_parent(). Keep restoring it between
parents, but not after the loop, since there is no later propagation
anymore.
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
---
log-tree.c | 96 +++++++++++++++++++++++-------------------------------
1 file changed, 41 insertions(+), 55 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index befc5c8b22..0aa27fb210 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1153,33 +1153,6 @@ void release_follow_pathspec_slab(struct rev_info *opt)
FREE_AND_NULL(opt->follow_pathspec_slab);
}
-/* Compute a path to follow in parent, if there is one */
-static void propagate_follow_pathspec_to_parent(struct rev_info *opt,
- struct commit *commit,
- struct commit *parent)
-{
- struct diff_options diff_opts;
- const char *path;
-
- parse_commit_or_die(parent);
- repo_diff_setup(opt->diffopt.repo, &diff_opts);
- copy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);
- diff_opts.flags.recursive = 1;
- diff_opts.flags.follow_renames = 1;
- diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
- diff_setup_done(&diff_opts);
- diff_tree_oid(get_commit_tree_oid(parent),
- get_commit_tree_oid(commit),
- "", &diff_opts);
-
- path = pathspec_single_path(&diff_opts.pathspec);
- if (path)
- remember_follow_pathspec(opt, parent, path);
-
- diff_queue_clear(&diff_queued_diff);
- diff_free(&diff_opts);
-}
-
/* Show the remerge or combined diff of a merge commit */
static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,
struct commit_list *parents,
@@ -1208,10 +1181,11 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,
static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
{
int showed_log;
- struct commit_list *parents;
+ struct commit_list *parents, *all_parents;
struct object_id *oid;
int is_merge;
int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
+ int follow_only = 0;
char *path = NULL;
if (!all_need_diff && !opt->merges_need_diff)
@@ -1241,46 +1215,73 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
}
if (is_merge) {
- if (opt->remerge_diff || opt->combine_merges)
+ int merge_diff = opt->remerge_diff || opt->combine_merges;
+
+ if (merge_diff && !opt->diffopt.flags.follow_renames)
return log_tree_merge_diff(opt, commit, parents, oid);
- if (opt->separate_merges) {
+ if (opt->separate_merges && !merge_diff) {
if (!opt->first_parent_merges) {
/* Show parent info for multiple diffs */
log->parent = parents->item;
}
+ } else if (opt->diffopt.flags.follow_renames) {
+ /* Diff only to find the path to follow in parents */
+ follow_only = 1;
} else
return 0;
}
- if (is_merge && opt->diffopt.flags.follow_renames)
+ if (opt->diffopt.flags.follow_renames)
path = xstrdup_or_null(
pathspec_single_path(&opt->diffopt.pathspec));
showed_log = 0;
+ all_parents = parents;
for (;;) {
struct commit *parent = parents->item;
- /* Diff each parent with the path of the merge */
- if (path)
- set_pathspec_to_single_path(&opt->diffopt.pathspec,
- path);
parse_commit_or_die(parent);
diff_tree_oid(get_commit_tree_oid(parent),
oid, "", &opt->diffopt);
- log_tree_diff_flush(opt);
+ if (follow_only) {
+ diff_queue_clear(&diff_queued_diff);
+ opt->diffopt.found_follow = 0;
+ } else {
+ log_tree_diff_flush(opt);
+ }
showed_log |= !opt->loginfo;
+ /* The diff updated the pathspec in case of a rename */
+ if (path)
+ remember_follow_pathspec(opt, parent,
+ pathspec_single_path(&opt->diffopt.pathspec));
+
/* Set up the log info for the next parent, if any.. */
parents = parents->next;
- if (!parents || opt->first_parent_merges)
+ if (!parents)
break;
+ if (opt->first_parent_merges) {
+ if (!path || opt->first_parent_only)
+ break;
+ /* Only find the path to follow in the other parents */
+ follow_only = 1;
+ }
+ if (path)
+ set_pathspec_to_single_path(&opt->diffopt.pathspec,
+ path);
+ if (follow_only)
+ continue;
log->parent = parents->item;
opt->loginfo = log;
}
- /* Propagate to parents starting from the path of the merge, too */
- if (path)
- set_pathspec_to_single_path(&opt->diffopt.pathspec, path);
+ if (follow_only && (opt->remerge_diff || opt->combine_merges)) {
+ /* Show the merge diff with the path of this commit */
+ if (path)
+ set_pathspec_to_single_path(&opt->diffopt.pathspec,
+ path);
+ showed_log = log_tree_merge_diff(opt, commit, all_parents, oid);
+ }
free(path);
return showed_log;
}
@@ -1319,21 +1320,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar);
if (shown)
show_diff_of_diff(opt);
-
- /* Record what path each parent of this commit should use */
- if (opt->diffopt.flags.follow_renames) {
- struct commit_list *parents = get_saved_parents(opt, commit);
- if (parents && parents->next) {
- struct commit_list *p;
- for (p = parents; p; p = p->next)
- propagate_follow_pathspec_to_parent(opt, commit,
- p->item);
- } else if (parents) {
- remember_follow_pathspec(opt, parents->item,
- pathspec_single_path(&opt->diffopt.pathspec));
- }
- }
-
opt->loginfo = NULL;
maybe_flush_or_die(opt->diffopt.file, "stdout");
opt->diffopt.no_free = no_free;
--
2.56.0
Technical Details
Message-ID:
<b903152bc4bd977e4f4eeec9476d8faa2114b7b2.1793298331.git.vmiklos@collabora.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73951-linux-kernel-git=dewy.ruReferences:
<cover.1793298331.git.vmiklos@collabora.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73951-linux-kernel-git=dewy.ru From: vmiklos@collabora.com (Miklos Vajna) Newsgroups: linux.kernel.git Subject: [PATCH v4 4/6] log: simplify --follow following renames for non-linear history Date: Fri, 30 Oct 2026 21:08:43 +0100 Organization: Usenet Network Message-ID: <b903152bc4bd977e4f4eeec9476d8faa2114b7b2.1793298331.git.vmiklos@collabora.com> References: <cover.1793298331.git.vmiklos@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Injection-Info: usenet.network; logging-data="2307507"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:NgCfJrU15l4anQ8R+Wz6z5+ZBtQ= sha256:02izMNDc3Wqqky8Oq4F+/3LciKoc1FLXDetN3tNu8og= sha1:0AdXeVr0LyCoCPTVtJjSLHa9ga4= sha256:xSyFqh+8AfNJwmUCPu7MUSzQwUrI5nkjASZPNTEwOPg= Content-Disposition: inline List-ID: <git.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 0ABE7125CA6; Fri, 30 Oct 2026 23:10:55 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.749 X-Spam-Status: No, score=-2.749 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=collabora.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tfyLg0VelGuS; Fri, 30 Oct 2026 23:10:52 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-73951-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=collabora.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 0D0A7125CA4; Fri, 30 Oct 2026 23:10:44 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 2CF6524206; Fri, 30 Oct 2026 20:08:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793390939; b=ukVQOqdO7hXWc4eivRlFYAmpTNUhwf+ESTtN/oIbx+Turom5Jfbmg2eoscnJBDn5E5di EVdzqVplCsy4JURIP9Fqu497F/AKTpiilAu1JyW6hzbNq9WRaOaFwIux1d1ZiLgkvvxFm XwBiPTk+6mCqFiQKRMn4CPJ3OXxBnahM+6roHPE/xN+etRywqroIREPp42BafLVqtcbY8 I1Cbmn3roV+h6ZjIfoSiVAdgwpse6Kytk89vbBpvzQ+I0Kbc334WwMH2UNGLFLmFLAMx5 H+XtSh0X4GwcOQP3avYShv+ft8sujp79k7EY1dOmMPgFNe0a0HUjsWJFjp1pKdHGqmA== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793390939; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:Date: From:To:Cc:Subject:Message-ID:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-Zoho-Virus-Status:X-Zoho-AV-Stamp:X-ZohoMailClient; bh=+PwNrjJt3nT2KwvIcpjD6BBRBE41iCV9F5rdKcTOudw=; b=K20dUctUHX8jB7b0YomyuEOqgvd4IvVPawMxI3gpbsEUskrG/EKEWdYTpAj2pWETQWj5 mENFMjXeLrkcUoZ/HTYDbmU2KbqVutxx4k5s32YDkDuo0WzFS7yq9XYRuMrAGcLijJ1Cb 2x0CbDaK/AHmvSjWe1IWqvLcCBZbvhgyDsZFs1kBrhHgbjmWXZwi0V8p77jifCLTW56XV CDaa+zpkfojyBiSD2bTPw+LQyuJSrcHhIBhlkE/vqRNh3J/TH7ZSKTYfWpdZK5sAMoRsp MMuR7VUjg7EVBZB+DFb/V9CA+HTPq1b6IWcy0hC9SGUjE6ImW9R0sH0kt7tEnHwzjxA== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=PxpnLNxV; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04227606A322; Fri, 30 Oct 2026 20:08:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=PxpnLNxV X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.12 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793390938; b=wrHjBDkqUxxT+9/iiz8vZB894I6xROOkSGoBoMj2fgzgc46ckBTon+C9X+Wh4IprtfGK LsQhKlkLh3ZdZhuIzPKjkypXEkEuORMZGREIvI27xnPR5tl/YQSaR6ii3ngbA3SNCTMec lIG0BRPBN0guOt4sfciR003ODXIeXnnmA9tgaSAQ/+uTFxxHI8aMmgkvmpgQhuxp1NiNB T5FdXqr1258j4jySmEhJqh469rjwL6TKON7Wz+VWXpq8bvCZrzLgx5J41ya6ZhUasYe74 6UTWPBa6dn231RbmeyGk868Kfw1nYlEU0WILRY+/Q//xJDbH2clyTJJEYNcjOffWdxg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793390938; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-Zoho-Virus-Status:X-Zoho-AV-Stamp:X-ZohoMailClient; bh=+PwNrjJt3nT2KwvIcpjD6BBRBE41iCV9F5rdKcTOudw=; b=RmzmciKOeenNfG8GSoKkcaMRWrcObY+0T5npmivlvYR4xm7IBag0mFY1RE2XP+23HDlv mPXx2TX6PPVm2zkY3AqagVWe3WgVFFgxeOHhAzjufR2LukCAdKQuVJZOs4Ooz9oP8QdO3 mqrewA5i1Z2mfFOVqRA1NdRWJYiSdyrbeYmVe7w/r1VuWSS0KMMei4jIrCuEaQEOFLyg+ OHjtp4GXvlnHqh52t3cKkpyH+b6XDUPn70ZLlx/ulTlUKE8bw1uW7VNFq5cXnAkQ31cIR rLBoLl3DNlKfhetD+HciL7OH9Nn3Suumst/1L2F0iOFj4EiQJyZzXikY8EP+gdhOu+w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=PxpnLNxV; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.12 X-Received: from sender6-op-o12.zoho.com (sender6-op-o12.zoho.com [165.173.180.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA5DD606A31C for <git@vger.kernel.org>; Fri, 30 Oct 2026 20:08:57 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA5DD606A31C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com X-ARC-Seal: i=1; a=rsa-sha256; t=1793390930; cv=none; d=zohomail.com; s=zohoarc; b=cSZU9UN3OZwXoRg2FjgEpCMyXpJ0QxRcwsMbHTkO+t0UgrY5AwVZG5ReK+gCRKfugfzmeJ7pP9pPIKBsEE8R51dShHepkPi6qFuG7fq6kif6HQYmJCH4lSaJj0CJV0I0RDktZHW7Hm0SQEzDaYS1CqpdP2shKoWN8Zr0ykIc+SA= X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793390930; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=+PwNrjJt3nT2KwvIcpjD6BBRBE41iCV9F5rdKcTOudw=; b=Vmapnk8o7k8FFwiH5eUKBQ6WdR4XV6DlhzUC0YNLiwJqpT4IVL+h27dC/IlnPztZyclvZDo8i2RV9EJmxw7ygrkPkjaWsM+8P3oK7U3PVwArvFZwtmtMjrlUQP8lxzPoMJbTMOcg2tKYHXUSw4V2u6n23tEPtrlJMP39IUMvV2A= X-ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=vmiklos@collabora.com; dmarc=pass header.from=<vmiklos@collabora.com> X-DKIM-Signature: a=rsa-sha256; b=PxpnLNxVma75CeuBE4axxH8HmQdTpxlJfA0ZIdWRyB3z6c53ppkg1Wl1XX+urw2vZ13oM/JhSbh03uUqZyNVOIJmFJSt8IwFYihtQgCDIGYyGEW1+pUPkjmFIzlEpiEkYqh2wSUhUQdOX4dhOBJgVI/H5GcJMwgF5HQ8nUKVahU=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=+PwNrjJt3nT2KwvIcpjD6BBRBE41iCV9F5rdKcTOudw=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; X-Received: by smtp.zohomail.com with SMTPS id 179339092792725.043137035101267; Fri, 30 Oct 2026 13:08:47 -0700 (PDT) X-Cc: szeder.dev@gmail.com, ps@pks.im, git@vger.kernel.org X-Mailing-List: git@vger.kernel.org X-List-Post: <mailto:git@vger.kernel.org> X-List-Help: <mailto:git+help@vger.kernel.org> X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:git+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <cover.1793298331.git.vmiklos@collabora.com> X-Zoho-Virus-Status: 1 X-Zoho-AV-Stamp: zmail-av-0.7.7.1.5.4/291.452.71 X-ZohoMailClient: External