context hunk merging in diff

オープン
#268 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
rust
領域
cli

調査の方向性

-U1 と -U2 を使用して shopping-old.txt と shopping-new.txt の例で問題を再現し、その後、unified hunk を公式の diff ユーティリティと比較します。ソースファイルもテストも指定されていません。unified-diff hunk の生成とマージのエントリポイントを追跡し、重複する、または隣接するコンテキストによって 1 つのマージ済み hunk が生成されれば issue は完了とみなします。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
276
フォーク
39
平均マージ
3時間 27分
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

uutils/diffutils のほかの issue

uutils/diffutils の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。