2012-06-06 18:26:15 +00:00
|
|
|
{- git FilePath library
|
|
|
|
-
|
|
|
|
- Different git commands use different types of FilePaths to refer to
|
|
|
|
- files in the repository. Some commands use paths relative to the
|
|
|
|
- top of the repository even when run in a subdirectory. Adding some
|
|
|
|
- types helps keep that straight.
|
|
|
|
-
|
2023-04-08 19:48:32 +00:00
|
|
|
- Copyright 2012-2023 Joey Hess <id@joeyh.name>
|
2012-06-06 18:26:15 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-06-06 18:26:15 +00:00
|
|
|
-}
|
|
|
|
|
2013-05-12 22:18:48 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2019-10-29 19:16:15 +00:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
2019-11-26 19:27:22 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2013-05-12 22:18:48 +00:00
|
|
|
|
2012-06-06 18:26:15 +00:00
|
|
|
module Git.FilePath (
|
2016-01-05 21:33:48 +00:00
|
|
|
TopFilePath,
|
2016-07-20 19:22:55 +00:00
|
|
|
BranchFilePath(..),
|
|
|
|
descBranchFilePath,
|
2016-01-05 21:33:48 +00:00
|
|
|
getTopFilePath,
|
2013-10-17 18:51:19 +00:00
|
|
|
fromTopFilePath,
|
2012-06-06 18:26:15 +00:00
|
|
|
toTopFilePath,
|
|
|
|
asTopFilePath,
|
2013-05-12 22:18:48 +00:00
|
|
|
InternalGitPath,
|
|
|
|
toInternalGitPath,
|
2014-02-08 19:31:03 +00:00
|
|
|
fromInternalGitPath,
|
|
|
|
absoluteGitPath
|
2012-06-06 18:26:15 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Common
|
|
|
|
import Git
|
2023-04-12 21:18:29 +00:00
|
|
|
import Git.Quote
|
2012-06-06 18:26:15 +00:00
|
|
|
|
2019-12-09 17:49:05 +00:00
|
|
|
import qualified System.FilePath.ByteString as P
|
|
|
|
import qualified System.FilePath.Posix.ByteString
|
2019-10-29 19:16:15 +00:00
|
|
|
import GHC.Generics
|
|
|
|
import Control.DeepSeq
|
2014-02-08 19:31:03 +00:00
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
{- A RawFilePath, relative to the top of the git repository. -}
|
2019-12-09 17:49:05 +00:00
|
|
|
newtype TopFilePath = TopFilePath { getTopFilePath :: RawFilePath }
|
2019-10-29 19:16:15 +00:00
|
|
|
deriving (Show, Eq, Ord, Generic)
|
|
|
|
|
|
|
|
instance NFData TopFilePath
|
2013-10-17 18:51:19 +00:00
|
|
|
|
2016-07-20 19:22:55 +00:00
|
|
|
{- A file in a branch or other treeish. -}
|
|
|
|
data BranchFilePath = BranchFilePath Ref TopFilePath
|
finish CommandStart transition
The hoped for optimisation of CommandStart with -J did not materialize.
In fact, not runnign CommandStart in parallel is slower than -J3.
So, CommandStart are still run in parallel.
(The actual bad performance I've been seeing with -J in my big repo
has to do with building the remoteList.)
But, this is still progress toward making -J faster, because it gets rid
of the onlyActionOn roadblock in the way of making CommandCleanup jobs
run separate from CommandPerform jobs.
Added OnlyActionOn constructor for ActionItem which fixes the
onlyActionOn breakage in the last commit.
Made CustomOutput include an ActionItem, so even things using it can
specify OnlyActionOn.
In Command.Move and Command.Sync, there were CommandStarts that used
includeCommandAction, so output messages, which is no longer allowed.
Fixed by using startingCustomOutput, but that's still not quite right,
since it prevents message display for the includeCommandAction run
inside it too.
2019-06-12 13:23:26 +00:00
|
|
|
deriving (Show, Eq, Ord)
|
2016-07-20 19:22:55 +00:00
|
|
|
|
|
|
|
{- Git uses the branch:file form to refer to a BranchFilePath -}
|
2023-04-10 21:03:41 +00:00
|
|
|
descBranchFilePath :: BranchFilePath -> StringContainingQuotedPath
|
|
|
|
descBranchFilePath (BranchFilePath b f) =
|
|
|
|
UnquotedByteString (fromRef' b) <> ":" <> QuotedPath (getTopFilePath f)
|
2016-07-20 19:22:55 +00:00
|
|
|
|
2016-01-05 21:33:48 +00:00
|
|
|
{- Path to a TopFilePath, within the provided git repo. -}
|
2019-12-09 17:49:05 +00:00
|
|
|
fromTopFilePath :: TopFilePath -> Git.Repo -> RawFilePath
|
|
|
|
fromTopFilePath p repo = P.combine (repoPath repo) (getTopFilePath p)
|
2012-06-06 18:26:15 +00:00
|
|
|
|
|
|
|
{- The input FilePath can be absolute, or relative to the CWD. -}
|
2019-12-09 17:49:05 +00:00
|
|
|
toTopFilePath :: RawFilePath -> Git.Repo -> IO TopFilePath
|
2020-10-28 19:40:50 +00:00
|
|
|
toTopFilePath file repo = TopFilePath <$> relPathDirToFile (repoPath repo) file
|
2012-06-06 18:26:15 +00:00
|
|
|
|
2019-12-09 17:49:05 +00:00
|
|
|
{- The input RawFilePath must already be relative to the top of the git
|
2012-06-06 18:26:15 +00:00
|
|
|
- repository -}
|
2019-12-09 17:49:05 +00:00
|
|
|
asTopFilePath :: RawFilePath -> TopFilePath
|
2012-06-06 18:26:15 +00:00
|
|
|
asTopFilePath file = TopFilePath file
|
2013-05-12 22:18:48 +00:00
|
|
|
|
|
|
|
{- Git may use a different representation of a path when storing
|
2013-12-05 03:49:18 +00:00
|
|
|
- it internally.
|
|
|
|
-
|
|
|
|
- On Windows, git uses '/' to separate paths stored in the repository,
|
2014-02-08 18:47:57 +00:00
|
|
|
- despite Windows using '\'.
|
2013-12-05 03:49:18 +00:00
|
|
|
-
|
|
|
|
-}
|
2019-11-25 20:18:19 +00:00
|
|
|
type InternalGitPath = RawFilePath
|
2013-05-12 22:18:48 +00:00
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
toInternalGitPath :: RawFilePath -> InternalGitPath
|
2013-08-02 16:27:32 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2013-05-12 22:18:48 +00:00
|
|
|
toInternalGitPath = id
|
|
|
|
#else
|
2019-11-25 20:18:19 +00:00
|
|
|
toInternalGitPath = encodeBS . replace "\\" "/" . decodeBS
|
2013-05-12 22:18:48 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
fromInternalGitPath :: InternalGitPath -> RawFilePath
|
2013-08-02 16:27:32 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2013-05-12 22:18:48 +00:00
|
|
|
fromInternalGitPath = id
|
|
|
|
#else
|
2019-11-25 20:18:19 +00:00
|
|
|
fromInternalGitPath = encodeBS . replace "/" "\\" . decodeBS
|
2013-05-12 22:18:48 +00:00
|
|
|
#endif
|
2014-02-08 19:31:03 +00:00
|
|
|
|
|
|
|
{- isAbsolute on Windows does not think "/foo" or "\foo" is absolute,
|
|
|
|
- so try posix paths.
|
|
|
|
-}
|
2019-11-25 20:18:19 +00:00
|
|
|
absoluteGitPath :: RawFilePath -> Bool
|
2019-12-09 17:49:05 +00:00
|
|
|
absoluteGitPath p = P.isAbsolute p ||
|
|
|
|
System.FilePath.Posix.ByteString.isAbsolute (toInternalGitPath p)
|