uutils / uutils/diffutils

context hunk merging in diff

Offen
#268 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Rust
Sterne
276
Forks
39
Ø Merge
3 Std. 27 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Problem anhand der Beispiele shopping-old.txt und shopping-new.txt mit -U1 und -U2 und vergleiche anschließend die Unified-Hunks mit dem offiziellen diff-Utility. Es wird keine Quelldatei und kein Test genannt; verfolge den Einstiegspunkt für die Erzeugung und Zusammenführung der Unified-Diff-Hunks und betrachte das Issue als erledigt, wenn überlappender oder angrenzender Kontext einen zusammengeführten Hunk erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
58/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.