make hashFile support paths with newlines
authorJoey Hess <joeyh@joeyh.name>
Mon, 13 Mar 2023 17:39:00 +0000 (13:39 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 13 Mar 2023 17:43:40 +0000 (13:43 -0400)
commita6bebe3c0fccf1c4db5cab07319c5a9e110f7966
tree1630e93266d58f2b7adc6bc688265f214d99fba4
parente7ed9b7cbb372f25d6d66ac38088d71d1fc19605
make hashFile support paths with newlines

git hash-object --stdin-paths is a newline protocol so it cannot
support them. It would help to not use absPath, when the problem
is that the repository itself is in a path with a newline. But,
there's a reason it used absPath, which is that
git hash-object --stdin-paths actually chdirs to the top of the
repository on startup! That is not documented, and I think is a bug
in git.

I considered making the path relative to the top of the repo, but
then what if this is a git bug and gets fixed? git-annex would break
horribly.

So instead, keep the absPath, but when the path contains a newline,
fall back to running git hash-object once per file, which avoids
the problem with newlines and --stdin-paths. It will be slower,
but this is an edge case. (Similar slow code paths are already used
elsewhere when dealing with filenames with newlines and other parts
of git that use line-based protocols.)

Sponsored-by: Dartmouth College's Datalad project
Git/HashObject.hs
doc/bugs/init_fails_in_a_folder_with_newline_in_its_name/comment_1_2690ed9441685068c291a182d39c2616._comment [new file with mode: 0644]