Windows: Fix CRLF handling in some log files
authorJoey Hess <joeyh@joeyh.name>
Mon, 30 Oct 2023 18:23:23 +0000 (14:23 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 30 Oct 2023 18:23:23 +0000 (14:23 -0400)
commiteb42935e5822a43ec29c1c113d5df62ea676d119
tree1b99323a05d1c18190f7f86aa704b292228bdfd1
parentea2876ae770d3cd5dfb66c248ee988ba95abf7b4
Windows: Fix CRLF handling in some log files

In particular, the mergedrefs file was written with CR added to each line,
but read without CRLF handling. This resulted in each update of the file
adding CR to each line in it, growing the number of lines, while also
preventing the optimisation from working, so it remerged unncessarily.

writeFile and readFile do NewlineMode translation on Windows. But the
ByteString conversion prevented that from happening any longer.

I've audited for other cases of this, and found three more
(.git/annex/index.lck, .git/annex/ignoredrefs, and .git/annex/import/). All
of those also only prevent optimisations from working. Some other files are
currently both read and written with ByteString, but old git-annex may have
written them with NewlineMode translation. Other files are at risk for
breakage later if the reader gets converted to ByteString.

This is a minimal fix, but should be enough, as long as I remember to use
fileLines when splitting a ByteString into lines. This leaves files written
using ByteString without CR added, but that's ok because old git-annex has
no difficulty reading such files.

When the mergedrefs file has gotten lines that end with "\r\r\r\n", this
will eventually clean it up. Each update will remove a single trailing CR.

Note that S8.lines is still used in eg Command.Unused, where it is parsing
git show-ref, and similar in Git/*. git commands don't include CR in their
output so that's ok.

Sponsored-by: Joshua Antonishen on Patreon
Annex/Branch.hs
CHANGELOG
Logs/File.hs