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 1/2] combine-diff: fix the shift for the 33rd parent and later
Date: Sat, 21 Nov 2026 16:12:33 +0530 [thread overview]
Message-ID: <20261121104234.98386-2-aniketgupta3001@gmail.com> (raw)
In-Reply-To: <20261121104234.98386-1-aniketgupta3001@gmail.com>
coalesce_lines() records which parents lost a line by setting a bit in
the parent_map of that line. The bit is computed with 1<<parent, which
is an int shift. For the 33rd parent and later the shift count is 32 or
more, so the result is undefined, and in practice the bit for parent
minus 32 is set instead. The line is then shown in the wrong column of
the combined diff, and the hunk header can disagree with the lines in
the hunk.
Use 1UL<<parent, like the other masks in this file. parent_map is an
unsigned long.
Add a test where two of forty parents lose the same line. It is skipped
where long is not 64 bits, as the masks cannot hold that many parents
there.
Reported-by: Sami Jawhar <sami@theorem.dev>
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
combine-diff.c | 2 +-
t/t4038-diff-combined.sh | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/combine-diff.c b/combine-diff.c
index 717d537688..54d0aed6b2 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -246,7 +246,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
j--;
while (i != 0 || j != 0) {
if (directions[i][j] == MATCH) {
- baseend->parent_map |= 1<<parent;
+ baseend->parent_map |= 1UL << parent;
baseend = baseend->prev;
newend = newend->prev;
i--;
diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index e11b711388..fcf7333d7b 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -127,6 +127,30 @@ test_expect_success 'check --cc --raw with forty trees' '
test_grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
'
+test_expect_success LONG_IS_64BIT 'check --cc with forty parents, two losing the same line' '
+ blob=$(echo file | git hash-object --stdin -w) &&
+ result_tree=$(echo "100644 blob $blob file" | git mktree) &&
+ parent_trees= &&
+ for i in $(test_seq 1 40)
+ do
+ case $i in
+ 2 | 40)
+ extra=common
+ ;;
+ *)
+ extra=
+ ;;
+ esac &&
+ blob=$(test_write_lines $extra file file$i | git hash-object --stdin -w) &&
+ parent_trees="$parent_trees$(echo "100644 blob $blob file" | git mktree)$LF" || return 1
+ done &&
+ git diff --cc $result_tree $parent_trees >out &&
+ # Check that the second and the fortieth column mark the line:
+ printf " -%37s-common\n" "" >expect &&
+ grep common out >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'setup combined ignore spaces' '
git checkout main &&
>test &&
--
2.54.0 (Apple Git-157)
next 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 ` Aniket Gupta [this message]
2026-11-21 10:42 ` [PATCH 2/2] combine-diff: do not show a patch for too many parents Aniket Gupta
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-2-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