convert TopFilePath to use RawFilePath
Adds a dependency on filepath-bytestring, an as yet unreleased fork of filepath that operates on RawFilePath. Git.Repo also changed to use RawFilePath for the path to the repo. This does eliminate some RawFilePath -> FilePath -> RawFilePath conversions. And filepath-bytestring's </> is probably faster. But I don't expect a major performance improvement from this. This is mostly groundwork for making Annex.Location use RawFilePath, which will allow for a conversion-free pipleline.
This commit is contained in:
parent
a7004375ec
commit
bdec7fed9c
97 changed files with 323 additions and 271 deletions
|
@ -5,7 +5,7 @@
|
|||
- top of the repository even when run in a subdirectory. Adding some
|
||||
- types helps keep that straight.
|
||||
-
|
||||
- Copyright 2012-2013 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2012-2019 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -31,13 +31,14 @@ module Git.FilePath (
|
|||
import Common
|
||||
import Git
|
||||
|
||||
import qualified System.FilePath.Posix
|
||||
import qualified System.FilePath.ByteString as P
|
||||
import qualified System.FilePath.Posix.ByteString
|
||||
import GHC.Generics
|
||||
import Control.DeepSeq
|
||||
import qualified Data.ByteString as S
|
||||
|
||||
{- A RawFilePath, relative to the top of the git repository. -}
|
||||
newtype TopFilePath = TopFilePath { getTopFilePath :: FilePath }
|
||||
newtype TopFilePath = TopFilePath { getTopFilePath :: RawFilePath }
|
||||
deriving (Show, Eq, Ord, Generic)
|
||||
|
||||
instance NFData TopFilePath
|
||||
|
@ -49,19 +50,20 @@ data BranchFilePath = BranchFilePath Ref TopFilePath
|
|||
{- Git uses the branch:file form to refer to a BranchFilePath -}
|
||||
descBranchFilePath :: BranchFilePath -> S.ByteString
|
||||
descBranchFilePath (BranchFilePath b f) =
|
||||
encodeBS' (fromRef b) <> ":" <> toRawFilePath (getTopFilePath f)
|
||||
encodeBS' (fromRef b) <> ":" <> getTopFilePath f
|
||||
|
||||
{- Path to a TopFilePath, within the provided git repo. -}
|
||||
fromTopFilePath :: TopFilePath -> Git.Repo -> FilePath
|
||||
fromTopFilePath p repo = combine (repoPath repo) (getTopFilePath p)
|
||||
fromTopFilePath :: TopFilePath -> Git.Repo -> RawFilePath
|
||||
fromTopFilePath p repo = P.combine (repoPath repo) (getTopFilePath p)
|
||||
|
||||
{- The input FilePath can be absolute, or relative to the CWD. -}
|
||||
toTopFilePath :: FilePath -> Git.Repo -> IO TopFilePath
|
||||
toTopFilePath file repo = TopFilePath <$> relPathDirToFile (repoPath repo) file
|
||||
toTopFilePath :: RawFilePath -> Git.Repo -> IO TopFilePath
|
||||
toTopFilePath file repo = TopFilePath . toRawFilePath
|
||||
<$> relPathDirToFile (fromRawFilePath (repoPath repo)) (fromRawFilePath file)
|
||||
|
||||
{- The input FilePath must already be relative to the top of the git
|
||||
{- The input RawFilePath must already be relative to the top of the git
|
||||
- repository -}
|
||||
asTopFilePath :: FilePath -> TopFilePath
|
||||
asTopFilePath :: RawFilePath -> TopFilePath
|
||||
asTopFilePath file = TopFilePath file
|
||||
|
||||
{- Git may use a different representation of a path when storing
|
||||
|
@ -91,5 +93,5 @@ fromInternalGitPath = encodeBS . replace "/" "\\" . decodeBS
|
|||
- so try posix paths.
|
||||
-}
|
||||
absoluteGitPath :: RawFilePath -> Bool
|
||||
absoluteGitPath p = isAbsolute (decodeBS p) ||
|
||||
System.FilePath.Posix.isAbsolute (decodeBS (toInternalGitPath p))
|
||||
absoluteGitPath p = P.isAbsolute p ||
|
||||
System.FilePath.Posix.ByteString.isAbsolute (toInternalGitPath p)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue