2011-12-13 19:05:07 +00:00
|
|
|
{- git data types
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010-2012 Joey Hess <id@joeyh.name>
|
2011-12-13 19:05:07 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Git.Types where
|
|
|
|
|
|
|
|
import Network.URI
|
|
|
|
import qualified Data.Map as M
|
2013-10-22 16:58:04 +00:00
|
|
|
import System.Posix.Types
|
2013-11-05 17:38:37 +00:00
|
|
|
import Utility.SafeCommand
|
2011-12-13 19:05:07 +00:00
|
|
|
|
Clean up handling of git directory and git worktree.
Baked into the code was an assumption that a repository's git directory
could be determined by adding ".git" to its work tree (or nothing for bare
repos). That fails when core.worktree, or GIT_DIR and GIT_WORK_TREE are
used to separate the two.
This was attacked at the type level, by storing the gitdir and worktree
separately, so Nothing for the worktree means a bare repo.
A complication arose because we don't learn where a repository is bare
until its configuration is read. So another Location type handles
repositories that have not had their config read yet. I am not entirely
happy with this being a Location type, rather than representing them
entirely separate from the Git type. The new code is not worse than the
old, but better types could enforce more safety.
Added support for core.worktree. Overriding it with -c isn't supported
because it's not really clear what to do if a git repo's config is read, is
not bare, and is then overridden to bare. What is the right git directory
in this case? I will worry about this if/when someone has a use case for
overriding core.worktree with -c. (See Git.Config.updateLocation)
Also removed and renamed some functions like gitDir and workTree that
misused git's terminology.
One minor regression is known: git annex add in a bare repository does not
print a nice error message, but runs git ls-files in a way that fails
earlier with a less nice error message. This is because before --work-tree
was always passed to git commands, even in a bare repo, while now it's not.
2012-05-18 20:38:26 +00:00
|
|
|
{- Support repositories on local disk, and repositories accessed via an URL.
|
|
|
|
-
|
|
|
|
- Repos on local disk have a git directory, and unless bare, a worktree.
|
|
|
|
-
|
|
|
|
- A local repo may not have had its config read yet, in which case all
|
|
|
|
- that's known about it is its path.
|
|
|
|
-
|
|
|
|
- Finally, an Unknown repository may be known to exist, but nothing
|
|
|
|
- else known about it.
|
|
|
|
-}
|
|
|
|
data RepoLocation
|
|
|
|
= Local { gitdir :: FilePath, worktree :: Maybe FilePath }
|
|
|
|
| LocalUnknown FilePath
|
|
|
|
| Url URI
|
|
|
|
| Unknown
|
2014-04-06 23:06:03 +00:00
|
|
|
deriving (Show, Eq, Ord)
|
2011-12-13 19:05:07 +00:00
|
|
|
|
2012-08-25 00:50:39 +00:00
|
|
|
data Repo = Repo
|
|
|
|
{ location :: RepoLocation
|
|
|
|
, config :: M.Map String String
|
2011-12-30 18:07:17 +00:00
|
|
|
-- a given git config key can actually have multiple values
|
2012-08-25 00:50:39 +00:00
|
|
|
, fullconfig :: M.Map String [String]
|
|
|
|
, remotes :: [Repo]
|
2011-12-13 19:05:07 +00:00
|
|
|
-- remoteName holds the name used for this repo in remotes
|
2013-11-07 22:02:00 +00:00
|
|
|
, remoteName :: Maybe RemoteName
|
2012-08-25 00:50:39 +00:00
|
|
|
-- alternate environment to use when running git commands
|
|
|
|
, gitEnv :: Maybe [(String, String)]
|
2016-04-08 18:24:00 +00:00
|
|
|
, gitEnvOverridesGitDir :: Bool
|
2013-11-05 17:38:37 +00:00
|
|
|
-- global options to pass to git when running git commands
|
|
|
|
, gitGlobalOpts :: [CommandParam]
|
2014-04-06 23:06:03 +00:00
|
|
|
} deriving (Show, Eq, Ord)
|
2011-12-13 19:05:07 +00:00
|
|
|
|
2013-11-07 22:02:00 +00:00
|
|
|
type RemoteName = String
|
|
|
|
|
2011-12-13 19:05:07 +00:00
|
|
|
{- A git ref. Can be a sha1, or a branch or tag name. -}
|
|
|
|
newtype Ref = Ref String
|
2014-02-19 05:09:17 +00:00
|
|
|
deriving (Eq, Ord, Read, Show)
|
2011-12-13 19:05:07 +00:00
|
|
|
|
2014-02-19 05:09:17 +00:00
|
|
|
fromRef :: Ref -> String
|
|
|
|
fromRef (Ref s) = s
|
2011-12-13 19:05:07 +00:00
|
|
|
|
|
|
|
{- Aliases for Ref. -}
|
|
|
|
type Branch = Ref
|
|
|
|
type Sha = Ref
|
|
|
|
type Tag = Ref
|
2012-06-06 06:31:31 +00:00
|
|
|
|
2014-02-06 16:43:56 +00:00
|
|
|
{- A date in the format described in gitrevisions. Includes the
|
|
|
|
- braces, eg, "{yesterday}" -}
|
|
|
|
newtype RefDate = RefDate String
|
|
|
|
|
2012-06-06 06:31:31 +00:00
|
|
|
{- Types of objects that can be stored in git. -}
|
|
|
|
data ObjectType = BlobObject | CommitObject | TreeObject
|
2012-06-27 17:08:32 +00:00
|
|
|
deriving (Eq)
|
2012-06-06 06:31:31 +00:00
|
|
|
|
|
|
|
instance Show ObjectType where
|
|
|
|
show BlobObject = "blob"
|
|
|
|
show CommitObject = "commit"
|
|
|
|
show TreeObject = "tree"
|
|
|
|
|
|
|
|
readObjectType :: String -> Maybe ObjectType
|
|
|
|
readObjectType "blob" = Just BlobObject
|
|
|
|
readObjectType "commit" = Just CommitObject
|
|
|
|
readObjectType "tree" = Just TreeObject
|
|
|
|
readObjectType _ = Nothing
|
|
|
|
|
2012-06-06 18:26:15 +00:00
|
|
|
{- Types of blobs. -}
|
|
|
|
data BlobType = FileBlob | ExecutableBlob | SymlinkBlob
|
2012-06-27 17:08:32 +00:00
|
|
|
deriving (Eq)
|
2012-06-06 18:26:15 +00:00
|
|
|
|
|
|
|
{- Git uses magic numbers to denote the type of a blob. -}
|
|
|
|
instance Show BlobType where
|
|
|
|
show FileBlob = "100644"
|
|
|
|
show ExecutableBlob = "100755"
|
|
|
|
show SymlinkBlob = "120000"
|
2012-06-27 13:27:59 +00:00
|
|
|
|
|
|
|
readBlobType :: String -> Maybe BlobType
|
|
|
|
readBlobType "100644" = Just FileBlob
|
|
|
|
readBlobType "100755" = Just ExecutableBlob
|
|
|
|
readBlobType "120000" = Just SymlinkBlob
|
|
|
|
readBlobType _ = Nothing
|
2013-10-22 16:58:04 +00:00
|
|
|
|
|
|
|
toBlobType :: FileMode -> Maybe BlobType
|
|
|
|
toBlobType 0o100644 = Just FileBlob
|
|
|
|
toBlobType 0o100755 = Just ExecutableBlob
|
|
|
|
toBlobType 0o120000 = Just SymlinkBlob
|
|
|
|
toBlobType _ = Nothing
|
2016-02-25 18:59:35 +00:00
|
|
|
|
2016-02-25 19:34:22 +00:00
|
|
|
fromBlobType :: BlobType -> FileMode
|
|
|
|
fromBlobType FileBlob = 0o100644
|
|
|
|
fromBlobType ExecutableBlob = 0o100755
|
|
|
|
fromBlobType SymlinkBlob = 0o120000
|
|
|
|
|
2016-02-25 18:59:35 +00:00
|
|
|
data Commit = Commit
|
|
|
|
{ commitTree :: Sha
|
2016-03-11 16:47:14 +00:00
|
|
|
, commitParent :: [Sha]
|
2016-02-25 18:59:35 +00:00
|
|
|
, commitAuthorMetaData :: CommitMetaData
|
|
|
|
, commitCommitterMetaData :: CommitMetaData
|
|
|
|
, commitMessage :: String
|
|
|
|
}
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
data CommitMetaData = CommitMetaData
|
|
|
|
{ commitName :: Maybe String
|
|
|
|
, commitEmail :: Maybe String
|
|
|
|
, commitDate :: Maybe String -- In raw git form, "epoch -tzoffset"
|
|
|
|
}
|
|
|
|
deriving (Show)
|