improved OsPath conversion

This commit is contained in:
Joey Hess 2025-02-11 14:05:56 -04:00
parent 2fa1631041
commit 27a0bacc49
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -16,8 +16,7 @@ import Git.Construct
import qualified Git.Config import qualified Git.Config
import Utility.Env import Utility.Env
import Utility.Env.Set import Utility.Env.Set
import qualified Utility.OsString as OS
import qualified Data.ByteString as B
{- Gets the current git repository. {- Gets the current git repository.
- -
@ -40,7 +39,7 @@ import qualified Data.ByteString as B
get :: IO Repo get :: IO Repo
get = do get = do
gd <- getpathenv "GIT_DIR" gd <- getpathenv "GIT_DIR"
r <- configure (fmap toOsPath gd) =<< fromCwd r <- configure gd =<< fromCwd
prefix <- getpathenv "GIT_PREFIX" prefix <- getpathenv "GIT_PREFIX"
wt <- maybe (worktree (location r)) Just wt <- maybe (worktree (location r)) Just
<$> getpathenvprefix "GIT_WORK_TREE" prefix <$> getpathenvprefix "GIT_WORK_TREE" prefix
@ -57,17 +56,17 @@ get = do
case v of case v of
Just d -> do Just d -> do
unsetEnv s unsetEnv s
return (Just (toRawFilePath d)) return (Just (toOsPath d))
Nothing -> return Nothing Nothing -> return Nothing
getpathenvprefix s (Just prefix) | not (B.null prefix) = getpathenvprefix s (Just prefix) | not (OS.null prefix) =
getpathenv s >>= \case getpathenv s >>= \case
Nothing -> return Nothing Nothing -> return Nothing
Just d Just d
| d == "." -> return (Just (toOsPath d)) | d == literalOsPath "." -> return (Just d)
| otherwise -> Just | otherwise -> Just
<$> absPath (toOsPath prefix </> toOsPath d) <$> absPath (prefix </> d)
getpathenvprefix s _ = fmap toOsPath <$> getpathenv s getpathenvprefix s _ = getpathenv s
configure Nothing (Just r) = Git.Config.read r configure Nothing (Just r) = Git.Config.read r
configure (Just d) _ = do configure (Just d) _ = do