Skip to content

feat: compare directory diffs by file content instead of mtime#306

Merged
esmuellert merged 2 commits intoesmuellert:mainfrom
pompos02:main
Mar 5, 2026
Merged

feat: compare directory diffs by file content instead of mtime#306
esmuellert merged 2 commits intoesmuellert:mainfrom
pompos02:main

Conversation

@pompos02
Copy link
Contributor

@pompos02 pompos02 commented Mar 4, 2026

Summary

This PR improves non-git directory comparison (:CodeDiff dir ...) by switching modified-file detection from metadata-based checks to content-based checks.
Previously, directory diff mode treated files as modified using size + mtime.
Now it compares file bytes directly (chunked reads), which makes results accurate as timestamps are unreliable.

What changed

  • Removed mtime from directory scan metadata.
  • Added absolute file paths in scan results so files can be opened directly for comparison.
  • Updated modified detection logic to:
    • early-return on size mismatch
    • otherwise read both files in chunks and compare byte-for-byte
    • mark as modified if open/read fails on either side
  • Updated README wording to document content-based directory diff behavior.

Implementation details

The comparison is implemented with libuv file APIs to keep it fast.

Benchmark

Ran a benchmark on the TensorFlow repository (HEAD vs a random branch). The benchmark was executed without using the git index, and the comparison contained 812 changed files.

  • Time (mean ± σ): 3.205 s ± 0.043 s [User: 2.039 s, System: 1.164 s]
  • Range (min … max): 3.152 s … 3.323 s
  • Runs: 15

pompos02 and others added 2 commits March 4, 2026 20:44
- Directory diff mode now verifies modified files by reading and comparing file bytes
instead of relying on mtime metadata.
@esmuellert esmuellert enabled auto-merge March 5, 2026 00:03
@esmuellert esmuellert merged commit 8f89e51 into esmuellert:main Mar 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants