Repository navigation
Description
The docs and README say diff output is byte-exact with git diff (
pitmaster/docs/operations/diff.md
Line 13 in 5beb97d
| Pitmaster computes diffs that are byte-exact with `git diff` output. The diff engine supports multiple algorithms, unified diff formatting, binary file detection, and tree-level recursive comparison. |
Line 32 in 5beb97d
| - Compute diffs (Myers O(ND) algorithm, byte-exact with `git diff`) |
| Case | git | Pitmaster (DiffResult::format() and pitmaster diff) |
|---|---|---|
| New file | new file mode 100644, index 0000000..<new>, --- /dev/null, @@ -0,0 +1 @@ |
no mode line, no index line, --- a/<path>, @@ -1,0 +1 @@ |
| Deleted file | deleted file mode 100644, index <old>..0000000, +++ /dev/null, @@ -1 +0,0 @@ |
no mode line, no index line, +++ b/<path> |
| Mode | the real mode (100755, 120000, ...) |
always 100644 in the index line |
| Mode-only change | old mode / new mode |
nothing (TreeDiff skips entries with equal hashes) |
| Binary | index a..b 100644 + Binary files a/x and b/x differ |
Binary files differ, no index line |
| Rename | similarity index, rename from, rename to |
plain diff --git a/old b/new with a content diff |
| CLI output to a pipe | no colour unless asked | always ANSI-coloured (commandDiff colorizes unconditionally) |
Repro
git init -q t && cd t && git config user.name T && git config user.email t@x
printf 'one\ntwo\n' > m.txt && printf 'gone\n' > d.txt && printf '\x00\x01' > bin.dat
git add . && git commit -qm init
printf 'one\nTWO\n' > m.txt && git rm -q d.txt && printf '\x00\x02' > bin.dat && git add -A
pitmaster diff --cached | cat -v
git diff --cachedA staged new file alone shows the header difference:
# pitmaster diff --cached # git diff --cached
diff --git a/b.txt b/b.txt diff --git a/b.txt b/b.txt
--- a/b.txt new file mode 100644
+++ b/b.txt index 0000000..3e75765
@@ -1,0 +1 @@ --- /dev/null
+new +++ b/b.txt
@@ -0,0 +1 @@
+new
Source
- : no new/deleted/mode headers,
pitmaster/src/Diff/DiffResult.php
Lines 33 to 52 in 5beb97d
public function format(): string { if ($this->binary) { return "diff --git a/{$this->oldPath} b/{$this->newPath}\n" . "Binary files differ\n"; } if ($this->hunks === []) { return ''; } $lines = []; $lines[] = "diff --git a/{$this->oldPath} b/{$this->newPath}"; if ($this->oldHash !== null && $this->newHash !== null) { $lines[] = "index " . substr($this->oldHash, 0, 7) . ".." . substr($this->newHash, 0, 7) . " 100644"; } $lines[] = "--- a/{$this->oldPath}"; $lines[] = "+++ b/{$this->newPath}"; /dev/nullnever used, mode hard-coded to100644(L48), binary message at L37. - : an empty side prints
Lines 37 to 44 in 5beb97d
public function header(): string { $old = $this->oldCount === 1 ? "-{$this->oldStart}" : "-{$this->oldStart},{$this->oldCount}"; $new = $this->newCount === 1 ? "+{$this->newStart}" : "+{$this->newStart},{$this->newCount}"; $section = $this->section !== null && $this->section !== '' ? ' ' . $this->section : ''; return "@@ {$old} {$new} @@{$section}"; } -1,0instead of git's-0,0. - : equal hashes are skipped, so mode-only changes vanish; modes are not passed to
pitmaster/src/Diff/TreeDiff.php
Lines 236 to 238 in 5beb97d
if ($oldEntry['hash'] === $newEntry['hash']) { continue; } DiffResult. - : rename results carry no rename metadata.
pitmaster/src/Diff/TreeDiff.php
Lines 117 to 124 in 5beb97d
$other[] = new DiffResult( $del->oldPath, $add->newPath, $hunks, false, $del->oldHash, $add->newHash, ); - :
Lines 433 to 435 in 5beb97d
foreach ($results as $diff) { fwrite(STDOUT, ColorDiff::colorize($diff->format())); } ColorDiff::colorize()is applied even when stdout is not a terminal (showchecksstream_isatty(),diffdoes not).
Expected
Either output matching git for these cases, or docs that do not claim byte-exactness. The docs are being updated to describe the current output.
Activity