-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various bugfixes and improvements around buffer md5 hash calculation and fastdirty
#3430
Commits on Aug 18, 2024
-
calcHash: remove unneeded h.Write() error checks
According to the Go hash package documentation [1]: type Hash interface { // Write (via the embedded io.Writer interface) adds more data to the running hash. // It never returns an error. io.Writer [1] https://pkg.go.dev/hash#Hash
Configuration menu - View commit details
-
Copy full SHA for e0f5361 - Browse repository at this point
Copy the full SHA e0f5361View commit details -
calcHash: use correct line endings
Make calcHash() respect the buffer's file endings (unix vs dos), to make its calculation of the file size consistent with how we calculate it in other cases (i.e. when opening or saving the file) and with the `fastdirty` option documentation, i.e. make calcHash() return ErrFileTooLarge if and only if the exact file size exceeds 50KB.
Configuration menu - View commit details
-
Copy full SHA for c0f6b65 - Browse repository at this point
Copy the full SHA c0f6b65View commit details -
buffer/settings: On
fastdirty
off set to on in case of "large file"This behavior is then aligned to the actual documentation of `fastdirty`. Additionally set the origHash to zero in case the buffer was already modified.
Configuration menu - View commit details
-
Copy full SHA for 352fd2b - Browse repository at this point
Copy the full SHA 352fd2bView commit details -
buffer/settings: Don't use Modified() before we updated origHash
When we have already enabled `fastdirty` but have not updated origHash yet, we shouldn't use Modified() since it depends on origHash which is still outdated, and thus returns wrong values. This fixes the following issue: enable `fastdirty`, modify the buffer, save the buffer and disable `fastdirty` -> micro wrongly reports the buffer as modified (whereas it has just been saved). Note that this fix, though, also causes a regression: e.g. if we run `set fastdirty false` while fastdirty is already disabled, micro may unexpectedly report a non-modified buffer as modified (in the case if isModified is true but the buffer it actually not modified, since its md5 sum matches and fastdirty is disabled), since this fix assumes that since we are disabling fastdirty, it has been enabled. This shall be fixed by PR zyedidia#3343 which makes `set` do nothing if the option value doesn't change.
Configuration menu - View commit details
-
Copy full SHA for 93efc9e - Browse repository at this point
Copy the full SHA 93efc9eView commit details -
calcHash: Remove checking file size
Let calcHash() unconditionally hash whatever buffer it is asked to hash, and let its callers explicitly check if the buffer is too large before calling calcHash(). This makes things simpler and less error-prone (no extra source of truth about whether the file is too large, we don't need to remember to check if calcHash() fails, we can be sure calcHash() will actually update the provided hash), and actually faster (since just calculating the buffer size, i.e. adding line lengths, is faster than md5 calculation). In particular, this fixes the following bugs: 1. Since ReOpen() doesn't check calcHash() return value, if the reloaded file is too large while the old version of the file is not, calcHash() returns ErrFileTooLarge and doesn't update origHash, so so Modified() returns true since the reloaded file's md5 sum doesn't match the old origHash, so micro wrongly reports the newly reloaded file as modified. 2. Since Modified() doesn't check calcHash() return value, Modified() may return false positives or false negatives if the buffer has *just* become too large so calcHash() returns ErrFileTooLarge and doesn't update `buff`.
Configuration menu - View commit details
-
Copy full SHA for 7fe98cc - Browse repository at this point
Copy the full SHA 7fe98ccView commit details -
Configuration menu - View commit details
-
Copy full SHA for d31095f - Browse repository at this point
Copy the full SHA d31095fView commit details -
buffer: Set fastdirty=true for large file when reopening
Similarly to how we force `fastdirty` to true when opening a large file (when creating the buffer), force it also when reopening a file, in case the file on disk became large since we opened it.
Configuration menu - View commit details
-
Copy full SHA for 0b15b57 - Browse repository at this point
Copy the full SHA 0b15b57View commit details