deal with git's CFLR nonsense once again

Work around git hash-object --stdin-paths's odd stripping of carriage
return from the end of the line (some windows infection), avoiding crashing
when the repo contains a filename ending in a carriage return.
This commit is contained in:
Joey Hess 2024-12-02 13:47:51 -04:00
parent 971d9f8057
commit 0c08ff3d2c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 43 additions and 1 deletions

View file

@ -48,13 +48,17 @@ hashFile hdl@(HashObjectHandle h _ _) file = do
-- So, make the filename absolute, which will work now
-- and also if git's behavior later changes.
file' <- absPath file
if newline `S.elem` file'
if newline `S.elem` file' || carriagereturn `S.elem` file
then hashFile' hdl file
else CoProcess.query h (send file') receive
where
send file' to = S8.hPutStrLn to file'
receive from = getSha "hash-object" $ S8.hGetLine from
newline = fromIntegral (ord '\n')
-- git strips carriage return from the end of a line, out of some
-- misplaced desire to support windows, so also use the newline
-- fallback for those.
carriagereturn = fromIntegral (ord '\r')
{- Runs git hash-object once per call, rather than using a running
- one, so is slower. But, is able to handle newlines in the filepath,