From 5bf806ee5238b7e7bc10a98d2ddf4684338339a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20S=C3=A1enz?= Date: Tue, 7 Apr 2026 19:26:22 +0200 Subject: [PATCH] Skip file transfer for mappings with no differences transfer_mappings now filters valid_mappings through the cached @differs results, skipping mappings that have no additions, modifications, or removals. This prevents unnecessary file mtime updates that caused tools like Neovim to reload plugins on every dotsync pull even when nothing changed. Closes #39 Co-Authored-By: Claude Opus 4.6 (1M context) --- CHANGELOG.md | 13 ++++++++++++- Gemfile.lock | 2 +- lib/dotsync/actions/concerns/mappings_transfer.rb | 7 ++++++- lib/dotsync/version.rb | 2 +- spec/dotsync/actions/pull_action_spec.rb | 9 +++++++-- spec/dotsync/actions/push_action_spec.rb | 8 +++++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9630f4..a09ca4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [0.4.4] - 2026-04-07 + +### Fixed + +- Skip file transfer for mappings with no differences (#39) + - `transfer_mappings` now filters using cached diff results to only transfer mappings that have actual changes + - Prevents unnecessary file mtime updates that caused Neovim to reload all plugins on every `dotsync pull` + - No redundant file comparisons — leverages the already-computed `@differs` from the display phase + ## [0.4.3] - 2026-03-22 ### Fixed @@ -13,7 +22,6 @@ - Fix `cp_r_regular_files` crash on pre-existing symlinks during backup (#35) - Add `FileUtils.rm_f` before `FileUtils.ln_s` to handle leftover symlinks from partial backup runs - ## [0.4.1] - 2026-03-17 ### Fixed @@ -498,6 +506,9 @@ Add gem executables Initial version +[0.4.4]: https://github.com/dsaenztagarro/dotsync/compare/v0.4.3...v0.4.4 +[0.4.3]: https://github.com/dsaenztagarro/dotsync/compare/v0.4.2...v0.4.3 +[0.4.2]: https://github.com/dsaenztagarro/dotsync/compare/v0.4.1...v0.4.2 [0.4.1]: https://github.com/dsaenztagarro/dotsync/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/dsaenztagarro/dotsync/compare/v0.3.3...v0.4.0 [0.3.3]: https://github.com/dsaenztagarro/dotsync/compare/v0.3.2...v0.3.3 diff --git a/Gemfile.lock b/Gemfile.lock index 1e31c1f..3b421a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dotsync (0.4.1) + dotsync (0.4.2) fileutils (~> 1.7.3) find (~> 0.2.0) listen (~> 3.9.0) diff --git a/lib/dotsync/actions/concerns/mappings_transfer.rb b/lib/dotsync/actions/concerns/mappings_transfer.rb index 5a514fb..4cd1eb4 100644 --- a/lib/dotsync/actions/concerns/mappings_transfer.rb +++ b/lib/dotsync/actions/concerns/mappings_transfer.rb @@ -114,8 +114,13 @@ def transfer_mappings errors = [] mutex = Mutex.new + # Only transfer mappings that have actual differences (uses cached diffs) + changed_mappings = valid_mappings.each_with_index.filter_map do |mapping, idx| + mapping if differs[idx].any? + end + # Process mappings in parallel - each mapping is independent - Dotsync::Parallel.each(valid_mappings) do |mapping| + Dotsync::Parallel.each(changed_mappings) do |mapping| Dotsync::FileTransfer.new(mapping).transfer rescue Dotsync::PermissionError => e mutex.synchronize { errors << ["Permission denied: #{e.message}", "Try: chmod +w or check file permissions"] } diff --git a/lib/dotsync/version.rb b/lib/dotsync/version.rb index 1348785..214ef1c 100644 --- a/lib/dotsync/version.rb +++ b/lib/dotsync/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Dotsync - VERSION = "0.4.3" + VERSION = "0.4.4" end diff --git a/spec/dotsync/actions/pull_action_spec.rb b/spec/dotsync/actions/pull_action_spec.rb index 015f13c..2ba8252 100644 --- a/spec/dotsync/actions/pull_action_spec.rb +++ b/spec/dotsync/actions/pull_action_spec.rb @@ -51,6 +51,8 @@ allow(logger).to receive(:action) FileUtils.mkdir_p(mapping1.src) FileUtils.mkdir_p(mapping1.dest) + File.write(File.join(mapping1.src, "file1"), "src content") + File.write(File.join(mapping1.dest, "file1"), "dest content") File.write(mapping2.src, "#{mapping2.src} content") File.write(mapping2.dest, "#{mapping2.dest} content") end @@ -84,7 +86,8 @@ ]) expect_show_differences_legend expect_show_differences([ - { text: "#{icon_diff_updated}/tmp/dotsync/dest/file2", color: color_diff_updated } + { text: "#{icon_diff_updated}/tmp/dotsync/dest/file2", color: color_diff_updated }, + { text: "#{icon_diff_updated}/tmp/dotsync/dest/folder_dest/file1", color: color_diff_updated } ]) action.execute @@ -92,6 +95,7 @@ context "without differences" do before do + File.write(File.join(mapping1.dest, "file1"), "src content") File.write(mapping2.dest, "#{mapping2.src} content") end @@ -126,7 +130,7 @@ end it "displays confirmation prompt" do - expect(logger).to receive(:info).with("About to modify 1 file(s).", icon: :warning) + expect(logger).to receive(:info).with("About to modify 2 file(s).", icon: :warning) action.execute(apply: true) end @@ -260,6 +264,7 @@ context "backup" do context "without differences" do before do + File.write(File.join(mapping1.dest, "file1"), "src content") File.write(mapping2.src, "#{mapping2.src} content") File.write(mapping2.dest, "#{mapping2.src} content") end diff --git a/spec/dotsync/actions/push_action_spec.rb b/spec/dotsync/actions/push_action_spec.rb index ae450df..b6bdf85 100644 --- a/spec/dotsync/actions/push_action_spec.rb +++ b/spec/dotsync/actions/push_action_spec.rb @@ -43,8 +43,8 @@ allow(logger).to receive(:log) allow(logger).to receive(:action) FileUtils.mkdir_p(root) - FileUtils.touch(mapping1.src) - FileUtils.touch(mapping1.dest) + File.write(mapping1.src, "src1 content") + File.write(mapping1.dest, "dest1 content") File.write(mapping2.src, "#{mapping2.src} content") File.write(mapping2.dest, "#{mapping2.dest} content") end @@ -75,6 +75,7 @@ ]) expect_show_differences_legend expect_show_differences([ + { text: "#{icon_diff_updated}/tmp/dotsync/dest1", color: color_diff_updated }, { text: "#{icon_diff_updated}/tmp/dotsync/dest2", color: color_diff_updated } ]) @@ -83,6 +84,7 @@ context "without differences" do before do + File.write(mapping1.dest, "src1 content") File.write(mapping2.dest, "#{mapping2.src} content") end @@ -126,7 +128,7 @@ end it "displays confirmation prompt" do - expect(logger).to receive(:info).with("About to modify 1 file(s).", icon: :warning) + expect(logger).to receive(:info).with("About to modify 2 file(s).", icon: :warning) action.execute(apply: true) end