From 148bab5c7bdc90fb21754fc83b180ecda1745218 Mon Sep 17 00:00:00 2001 From: pompos02 Date: Wed, 4 Mar 2026 20:44:15 +0200 Subject: [PATCH 1/2] feat: compare directory diffs by file content instead of mtime - Directory diff mode now verifies modified files by reading and comparing file bytes instead of relying on mtime metadata. --- README.md | 2 +- lua/codediff/core/dir.lua | 44 +++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3a2b5dcc..a82580ee 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,7 @@ Compare two directories without git: :CodeDiff dir /path/to/dir1 /path/to/dir2 ``` -Shows files as Added (A), Deleted (D), or Modified (M) based on file size and modification time. Select a file to view its diff. +Shows files as Added (A), Deleted (D), or Modified (M) using file size plus byte-level content comparison. Select a file to view its diff. ### File History Mode diff --git a/lua/codediff/core/dir.lua b/lua/codediff/core/dir.lua index 0cee0d63..890c2fb3 100644 --- a/lua/codediff/core/dir.lua +++ b/lua/codediff/core/dir.lua @@ -38,8 +38,8 @@ local function scan_dir(root) local stat = uv.fs_stat(abs) or {} files[rel] = { path = rel, + abs = abs, size = stat.size, - mtime = stat.mtime and stat.mtime.sec or nil, } end end @@ -56,16 +56,52 @@ local function is_modified(a, b) if a.size ~= b.size then return true end - if a.mtime ~= b.mtime then + + local fd_a = uv.fs_open(a.abs, "r", 0) + if not fd_a then + return true + end + + local fd_b = uv.fs_open(b.abs, "r", 0) + if not fd_b then + uv.fs_close(fd_a) return true end + + local offset = 0 + local chunk_size = 65536 + + while true do + local chunk_a = uv.fs_read(fd_a, chunk_size, offset) + local chunk_b = uv.fs_read(fd_b, chunk_size, offset) + + if chunk_a == nil or chunk_b == nil then + uv.fs_close(fd_a) + uv.fs_close(fd_b) + return true + end + + if chunk_a ~= chunk_b then + uv.fs_close(fd_a) + uv.fs_close(fd_b) + return true + end + + if #chunk_a == 0 then + break + end + + offset = offset + #chunk_a + end + + uv.fs_close(fd_a) + uv.fs_close(fd_b) return false end -- Compare two directories and return a git-like status_result. -- dir1 = "original", dir2 = "modified" --- NOTE: Modification detection is metadata-based (size and mtime only), --- not a content hash; this is a fast, best-effort diff. +-- NOTE: Modification detection compares file content with readblob. function M.diff_directories(dir1, dir2) local root1 = normalize_dir(dir1) local root2 = normalize_dir(dir2) From 4f48609331b3d5ec3df78ae701f4d22cc1629f97 Mon Sep 17 00:00:00 2001 From: Yanuo Ma Date: Wed, 4 Mar 2026 19:01:07 -0500 Subject: [PATCH 2/2] chore: bump version to 2.43.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 345a83ee..5b9cd9af 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.42.0 +2.43.0