{"thread":{"id":"66861","subject":"[BUG] combine-diff: wrong deletion columns at 33 parents, no hunks at 64","startedAt":"2026-11-17T06:32:23Z","lastAt":"2026-11-21T01:03:26Z","messageCount":3,"participants":["Sami Jawhar","Aniket Gupta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"558596","messageId":"CAOJ8FdczW9KxFknceHodV0jmhyEB24OMtqQUmhkP3E2vfsmgag@mail.gmail.com","threadId":"66861","inReplyTo":null,"subject":"[BUG] combine-diff: wrong deletion columns at 33 parents, no hunks at 64","fromName":"Sami Jawhar","fromEmail":"sami@theorem.dev","sentAt":"2026-11-17T06:32:23Z","receivedAt":"2026-11-17T06:32:23Z","isPatch":false,"sender":{"key":"sami@theorem.dev","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n\nI ran git diff-tree --cc -U0 on octopus merges with 32, 33, 63 and 64\nparents. Save this script as repro.sh:\n\n    #!/bin/sh\n    # usage: repro.sh N\n    set -eu\n    n=$1\n    lines=$((10 * n + 20))\n    dir=octopus-$n\n    rm -rf \"$dir\"\n    git init -q \"$dir\"\n    cd \"$dir\"\n    export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.com\n    export GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.com\n    file() { # FIRST_LINE SIDE...: \"side <i>\" goes after line 10*i+10\n        first=$1; shift\n        echo \"$first\"\n        k=2\n        while [ \"$k\" -le \"$lines\" ]; do\n            echo \"line $k\"\n            for side in \"$@\"; do\n                [ \"$k\" -eq $((10 * side + 10)) ] && echo \"side $side\"\n            done\n            k=$((k + 1))\n        done\n    }\n    commit() { # MESSAGE PARENT... < content\n        blob=$(git hash-object -w --stdin)\n        tree=$(printf '100644 blob %s\\tf.txt\\n' \"$blob\" | git mktree)\n        message=$1; shift\n        for parent in \"$@\"; do set -- \"$@\" -p \"$parent\"; shift; done\n        git commit-tree \"$tree\" \"$@\" -m \"$message\"\n    }\n    base=$(file \"line 1\" | commit base)\n    parents= all=\n    i=0\n    while [ \"$i\" -lt \"$n\" ]; do\n        first=\"line 1\"\n        { [ \"$i\" -eq 1 ] || [ \"$i\" -eq $((n - 1)) ]; } && first=\"removed line\"\n        parents=\"$parents $(file \"$first\" \"$i\" | commit \"side $i\" \"$base\")\"\n        all=\"$all $i\"\n        i=$((i + 1))\n    done\n    merge=$({ file \"line 1\" $all; echo \"merge-only line\"; } | commit\noctopus $parents)\n    echo \"merge of $n parents\"\n    echo \"lines showing \\\"merge-only line\\\":\" \\\n        \"$(git diff-tree --cc -U0 \"$merge\" | grep -c 'merge-only line')\"\n    git diff-tree --cc -U0 \"$merge\" | awk -v n=\"$n\" '\n        function check() {\n            if (!open) return\n            for (p = 1; p <= n; p++) if (got[p] != want[p]) {\n                printf \"hunk %s: parent %d: header says %d line(s),\nbody shows %d\\n\",\n                    header, p, want[p], got[p]; bad++ }\n        }\n        /^@@@/ { check(); open = 1; header = $(n + 2); split($0, f, \" \")\n                 for (p = 1; p <= n; p++) {\n                     split(substr(f[p + 1], 2), r, \",\")\n                     want[p] = (r[2] == \"\" ? 1 : r[2]); got[p] = 0 }\n                 next }\n        open { m = substr($0, 1, n); lost = index(m, \"-\") > 0\n               for (p = 1; p <= n; p++) {\n                   c = substr(m, p, 1)\n                   if (c == \"-\" || (!lost && c == \" \")) got[p]++ } }\n        END { check(); if (!bad) print \"every hunk agrees with its header\" }'\n\nFrom an empty directory, run:\n\n    for n in 32 33 63 64; do\n        sh repro.sh \"$n\"\n    done\n\nWhat did you expect to happen? (Expected behavior)\n\nEach hunk body should agree with its header, and \"merge-only line\"\nshould appear in the diff.\n\nWhat happened instead? (Actual behavior)\n\nGit 2.43.0 and master at e1ec09b23c8e print identical output:\n\n    merge of 32 parents\n    lines showing \"merge-only line\": 1\n    every hunk agrees with its header\n    merge of 33 parents\n    lines showing \"merge-only line\": 1\n    hunk +1,1: parent 1: header says 1 line(s), body shows 2\n    merge of 63 parents\n    lines showing \"merge-only line\": 1\n    hunk +1,1: parent 31: header says 1 line(s), body shows 2\n    merge of 64 parents\n    lines showing \"merge-only line\": 0\n    every hunk agrees with its header\n\nAt 64 parents the diff has no hunks, so the script's final \"every hunk\"\nmessage does not indicate success.\n\nWhat's different between what you expected and what actually happened?\n\nAt 33 parents, \"removed line\" is present in parents 2 and 33, but the\ndiff marks its deletion in columns 1 and 2. At 63 parents, the line is\npresent in parents 2 and 63, but the diff marks columns 2 and 31.\n\nIn e1ec09b23c8e, coalesce_lines() at combine-diff.c:249 has:\n\n    baseend->parent_map |= 1<<parent;\n\nparent_map is unsigned long, but 1<<parent shifts an int.\n\ngive_context():544-545, make_hunks():610-611 and dump_sline():756 also\nuse 1UL<<num_parent. At 64 parents, this shifts by 64, the width of\nunsigned long in both builds.\n\n[System Info]\nUbuntu 24.04.5 LTS, Linux x86_64, sizeof-long: 8\ngit version 2.43.0\ngit version 2.56.GIT\nbuilt from commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4\n\n"},{"id":"558973","messageId":"20261120165041.91627-1-aniketgupta3001@gmail.com","threadId":"66861","inReplyTo":"CAOJ8FdczW9KxFknceHodV0jmhyEB24OMtqQUmhkP3E2vfsmgag@mail.gmail.com","subject":"Re: [BUG] combine-diff: wrong deletion columns at 33 parents, no hunks at 64","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-20T16:50:41Z","receivedAt":"2026-11-20T16:50:41Z","isPatch":false,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"Hi Sami,\n\n> parent_map is unsigned long, but 1<<parent shifts an int.\n\nThanks for this report and the reproducer. It seems nobody has picked this. Can I send a patch to fix the shift and to handle merges with too many parents?\n\nThanks,\nAniket\n\n"},{"id":"559014","messageId":"CAOJ8FdcOSxprQvi36waQdhhRgDNNx=B2N+J5mR=S26o2mkgSEw@mail.gmail.com","threadId":"66861","inReplyTo":"20261120165041.91627-1-aniketgupta3001@gmail.com","subject":"Re: [BUG] combine-diff: wrong deletion columns at 33 parents, no hunks at 64","fromName":"Sami Jawhar","fromEmail":"sami@theorem.dev","sentAt":"2026-11-21T01:03:26Z","receivedAt":"2026-11-21T01:03:26Z","isPatch":false,"sender":{"key":"sami@theorem.dev","avatar":null},"body":"> Can I send a patch to fix the shift and to handle merges with too many parents?\n\nYes, please do.\n\n"}]}