From: Aniket Gupta <aniketgupta3001@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Sami Jawhar <sami@theorem.dev>, Patrick Steinhardt <ps@pks.im>
Subject: [PATCH 2/2] combine-diff: do not show a patch for too many parents
Date: Sat, 21 Nov 2026 16:12:34 +0530 [thread overview]
Message-ID: <20261121104234.98386-3-aniketgupta3001@gmail.com> (raw)
In-Reply-To: <20261121104234.98386-1-aniketgupta3001@gmail.com>
The masks used to show a combined diff patch hold one bit for each
parent, plus two more bits for markers in the flags of a line. With an
unsigned long that is enough for 62 parents, or 30 where long has 32
bits. For a merge with more parents the shifts are undefined, so the
hunks are either missing or shown with the wrong columns, and nothing
tells the user.
Report an error instead and skip the patch for such a merge. Do not
die, so that a "git log --cc" through a history with a big octopus merge
is not cut short. The raw format does not use the masks and is shown
as before.
Add tests for the largest number of parents that works and for one more
than that. The first is skipped where long is not 64 bits.
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
combine-diff.c | 16 +++++++++++++++-
t/t4038-diff-combined.sh | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/combine-diff.c b/combine-diff.c
index 54d0aed6b2..414fec9cb8 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -136,6 +136,12 @@ struct sline {
unsigned long *p_lno;
};
+/*
+ * The masks used to show a patch hold a bit for each parent, followed by
+ * the two marker bits described above.
+ */
+#define MAX_PATCH_PARENTS ((int)bitsizeof(unsigned long) - 2)
+
static int match_string_spaces(const char *line1, int len1,
const char *line2, int len2,
long flags)
@@ -1491,6 +1497,7 @@ void diff_tree_combined(const struct object_id *oid,
struct combine_diff_path *p, *paths;
int i, num_paths, needsep, show_log_first, num_parent = parents->nr;
int need_generic_pathscan;
+ int show_patch;
if (opt->ignore_regex_nr)
die("combined diff and '%s' cannot be used together",
@@ -1515,6 +1522,13 @@ void diff_tree_combined(const struct object_id *oid,
opt->line_termination);
}
+ show_patch = opt->output_format & DIFF_FORMAT_PATCH;
+ if (show_patch && num_parent > MAX_PATCH_PARENTS) {
+ error(_("cannot show a combined diff patch with more than %d parents"),
+ MAX_PATCH_PARENTS);
+ show_patch = 0;
+ }
+
diffopts = *opt;
copy_pathspec(&diffopts.pathspec, &opt->pathspec);
diffopts.flags.allow_external = 0;
@@ -1616,7 +1630,7 @@ void diff_tree_combined(const struct object_id *oid,
else if (opt->output_format & DIFF_FORMAT_CALLBACK)
handle_combined_callback(opt, paths, num_parent, num_paths);
- if (opt->output_format & DIFF_FORMAT_PATCH) {
+ if (show_patch) {
if (needsep)
printf("%s%c", diff_line_prefix(opt),
opt->line_termination);
diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index fcf7333d7b..ad670d76db 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -151,6 +151,42 @@ test_expect_success LONG_IS_64BIT 'check --cc with forty parents, two losing the
test_cmp expect actual
'
+test_expect_success 'setup for --cc with many parents' '
+ blob=$(echo file | git hash-object --stdin -w) &&
+ result_tree=$(echo "100644 blob $blob file" | git mktree) &&
+ many_trees= &&
+ for i in $(test_seq 1 63)
+ do
+ case $i in
+ 2 | 40)
+ extra=common
+ ;;
+ *)
+ extra=
+ ;;
+ esac &&
+ blob=$(test_write_lines $extra file file$i | git hash-object --stdin -w) &&
+ many_trees="$many_trees$(echo "100644 blob $blob file" | git mktree)$LF" || return 1
+ done
+'
+
+test_expect_success LONG_IS_64BIT 'check --cc with sixty-two parents' '
+ sixty_two_trees=$(echo "$many_trees" | sed -e 62q) &&
+ git diff --cc $result_tree $sixty_two_trees >out &&
+ # Check that the second and the fortieth column mark the line:
+ printf " -%37s-%22scommon\n" "" "" >expect &&
+ grep common out >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'refuse --cc patch with sixty-three parents' '
+ git diff --cc --patch-with-raw $result_tree $many_trees >out 2>err &&
+ test_grep "cannot show a combined diff patch with more than [0-9]* parents" err &&
+ # The raw output has a colon for each parent and is still shown:
+ test_grep "^:\{63\}[^:]" out &&
+ test_grep ! "^diff --cc" out
+'
+
test_expect_success 'setup combined ignore spaces' '
git checkout main &&
>test &&
--
2.54.0 (Apple Git-157)
prev parent reply other threads:[~2026-11-21 10:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 10:42 [PATCH 0/2] combine-diff: fix patches for more than 32 parents Aniket Gupta
2026-11-21 10:42 ` [PATCH 1/2] combine-diff: fix the shift for the 33rd parent and later Aniket Gupta
2026-11-21 10:42 ` Aniket Gupta [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121104234.98386-3-aniketgupta3001@gmail.com \
--to=aniketgupta3001@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ps@pks.im \
--cc=sami@theorem.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox