context hunk merging in diff
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
Research direction
Reproduce the issue with the shopping-old.txt and shopping-new.txt examples using -U1 and -U2, then compare the unified hunks with the official diff utility. No source file or test is named; trace the unified-diff hunk generation and merging entry point, and consider the issue done when overlapping or abutting context produces one merged hunk.
Written by the indexing model from the issue text.
Description
In playing with diffutils in the uutils playground web page, I noticed that -U1 on the shopping files was outputting a second hunk that has no prior context line. The official diff utility joins hunks together when the context overlaps or even just abuts.
My test:
uutils $ diff shopping-old.txt shopping-new.txt -U1
--- shopping-old.txt 2026-08-09 03:43:13.212000000 +0000
+++ shopping-new.txt 2026-08-09 03:43:13.212000000 +0000
@@ -2,2 +2,3 @@
eggs
+yogurt
bread
@@ -4,2 +5,2 @@
-butter
+honey
apples
As another test, I added another line of context between the chunks:
uutils $ sed shopping-old.txt >s1 -e 's/bread/bread\nrolls/'
uutils $ sed shopping-new.txt >s2 -e 's/bread/bread\nrolls/'
Now the 1-line context is present on hunk 2, but the normal diff util would join them together since they abut:
uutils $ diff s1 s2 -u1
--- s1 1970-01-01 00:00:00.000000000 +0000
+++ s2 1970-01-01 00:00:00.000000000 +0000
@@ -2,2 +2,3 @@
eggs
+yogurt
bread
@@ -4,3 +5,3 @@
rolls
-butter
+honey
apples
At this point -U2 has the missing context in the same manner as in the first example.
- Dominant language
- Rust
- Stars
- 276
- Forks
- 39
- Avg merge
- 3h 27m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from uutils/diffutils
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
All issues in uutils/diffutils
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100