OsPath build flag no longer depends on filepath-bytestring

However, filepath-bytestring is still in Setup-Depends.
That's because Utility.OsPath uses it when not built with OsPath.
It would be maybe possible to make Utility.OsPath fall back to using
filepath, and eliminate that dependency too, but it would mean either
wrapping all of System.FilePath's functions, or using `type OsPath = FilePath`

Annex.Import uses ifdefs to avoid converting back to FilePath when not
on windows. On windows it's a bit slower due to that conversion.
Utility.Path.Windows.convertToWindowsNativeNamespace got a bit
slower too, but not really worth optimising I think.

Note that importing Utility.FileSystemEncoding at the same time as
System.Posix.ByteString will result in conflicting definitions for
RawFilePath. filepath-bytestring avoids that by importing RawFilePath
from System.Posix.ByteString, but that's not possible in
Utility.FileSystemEncoding, since Setup-Depends does not include unix.
This turned out not to affect any code in git-annex though.

Sponsored-by: Leon Schuermann
This commit is contained in:
Joey Hess 2025-02-10 16:25:31 -04:00
parent ce697aa8ae
commit 2ff716be30
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
13 changed files with 81 additions and 68 deletions

View file

@ -14,11 +14,11 @@ import qualified Annex
import Utility.Hash
import Types.Key
import Types.KeySource
import qualified Utility.OsString as OS
import qualified Data.ByteString as S
import qualified Data.ByteString.Short as S (ShortByteString, toShort)
import qualified Data.ByteString.Lazy as L
import qualified System.FilePath.ByteString as P
import Data.Char
import Data.Word
@ -49,13 +49,13 @@ addE source sethasext k = do
let ext = selectExtension
(annexMaxExtensionLength c)
(annexMaxExtensions c)
(fromOsPath (keyFilename source))
(keyFilename source)
return $ alterKey k $ \d -> d
{ keyName = keyName d <> S.toShort ext
, keyVariety = sethasext (keyVariety d)
}
selectExtension :: Maybe Int -> Maybe Int -> RawFilePath -> S.ByteString
selectExtension :: Maybe Int -> Maybe Int -> OsPath -> S.ByteString
selectExtension maxlen maxextensions f
| null es = ""
| otherwise = S.intercalate "." ("":es)
@ -64,11 +64,12 @@ selectExtension maxlen maxextensions f
take (fromMaybe maxExtensions maxextensions) $
filter (S.all validInExtension) $
takeWhile shortenough $
reverse $ S.split (fromIntegral (ord '.')) (P.takeExtensions f')
reverse $ S.split (fromIntegral (ord '.')) $
fromOsPath $ takeExtensions f'
shortenough e = S.length e <= fromMaybe maxExtensionLen maxlen
-- Avoid treating a file ".foo" as having its whole name as an
-- extension.
f' = S.dropWhile (== fromIntegral (ord '.')) (P.takeFileName f)
f' = OS.dropWhile (== unsafeFromChar '.') (takeFileName f)
validInExtension :: Word8 -> Bool
validInExtension c