]> git.ipfire.org Git - thirdparty/git.git/commit
diff: reject negative values for --inter-hunk-context
authorMichael Montalbo <mmontalbo@gmail.com>
Tue, 12 May 2026 18:10:20 +0000 (18:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 May 2026 01:13:25 +0000 (10:13 +0900)
commit321f0ea17b3bcb70867fad430e972548281803f0
tree0c5a10a56fd1e8a51d3e92cee1fe376c556f3f12
parent94f057755b7941b321fd11fec1b2e3ca5313a4e0
diff: reject negative values for --inter-hunk-context

Negative values for --inter-hunk-context produce structurally invalid
diff output with overlapping hunks:

    $ git log -1 -p -U3 --inter-hunk-context=-100 791aeddfa2 \
        -- git-compat-util.h | grep '^@@'
    @@ -110,6 +110,9 @@
    @@ -115,6 +118,9 @@
    @@ -116,6 +122,7 @@

Hunk 1 covers lines 110-115, hunk 2 starts at 115 (overlap), hunk 3
starts at 116 (overlaps both). The resulting patch cannot be applied.

The config variable diff.interHunkContext already rejects negative
values, but the command line option does not.

Change the type of diff_options.interhunkcontext and its static
default from int to unsigned int, and switch the option parser from
OPT_INTEGER_F to OPT_UNSIGNED. This rejects negative values at parse
time via git_parse_unsigned() and enforces the correct type at compile
time via BARF_UNLESS_UNSIGNED.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
diff.h
t/t4032-diff-inter-hunk-context.sh