2013-09-07 22:38:00 +00:00
|
|
|
{- Utilities for git remotes.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2011-2014 Joey Hess <id@joeyh.name>
|
2013-09-07 22:38:00 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-09-07 22:38:00 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Remote.Helper.Git where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2013-09-07 22:38:00 +00:00
|
|
|
import qualified Git
|
2014-01-13 18:41:10 +00:00
|
|
|
import Types.Availability
|
2015-01-13 22:11:03 +00:00
|
|
|
import qualified Types.Remote as Remote
|
|
|
|
|
|
|
|
import Data.Time.Clock.POSIX
|
2013-09-07 22:38:00 +00:00
|
|
|
|
|
|
|
repoCheap :: Git.Repo -> Bool
|
|
|
|
repoCheap = not . Git.repoIsUrl
|
|
|
|
|
|
|
|
localpathCalc :: Git.Repo -> Maybe FilePath
|
2014-01-13 18:41:10 +00:00
|
|
|
localpathCalc r
|
|
|
|
| availabilityCalc r == GloballyAvailable = Nothing
|
|
|
|
| otherwise = Just $ Git.repoPath r
|
2013-09-07 22:38:00 +00:00
|
|
|
|
2014-01-13 18:41:10 +00:00
|
|
|
availabilityCalc :: Git.Repo -> Availability
|
|
|
|
availabilityCalc r
|
|
|
|
| (Git.repoIsLocal r || Git.repoIsLocalUnknown r) = LocallyAvailable
|
|
|
|
| otherwise = GloballyAvailable
|
2013-09-07 22:38:00 +00:00
|
|
|
|
|
|
|
{- Avoids performing an action on a local repository that's not usable.
|
|
|
|
- Does not check that the repository is still available on disk. -}
|
2014-08-08 23:18:08 +00:00
|
|
|
guardUsable :: Git.Repo -> Annex a -> Annex a -> Annex a
|
|
|
|
guardUsable r fallback a
|
|
|
|
| Git.repoIsLocalUnknown r = fallback
|
2013-09-07 22:38:00 +00:00
|
|
|
| otherwise = a
|
2014-10-21 18:36:09 +00:00
|
|
|
|
2015-01-13 22:11:03 +00:00
|
|
|
gitRepoInfo :: Remote -> Annex [(String, String)]
|
|
|
|
gitRepoInfo r = do
|
|
|
|
d <- fromRepo Git.localGitDir
|
|
|
|
mtimes <- liftIO $ mapM (modificationTime <$$> getFileStatus)
|
|
|
|
=<< dirContentsRecursive (d </> "refs" </> "remotes" </> Remote.name r)
|
|
|
|
let lastsynctime = case mtimes of
|
|
|
|
[] -> "never"
|
|
|
|
_ -> show $ posixSecondsToUTCTime $ realToFrac $ maximum mtimes
|
2018-06-04 18:31:55 +00:00
|
|
|
repo <- Remote.getRepo r
|
2015-01-13 22:11:03 +00:00
|
|
|
return
|
2018-06-04 18:31:55 +00:00
|
|
|
[ ("repository location", Git.repoLocation repo)
|
2015-01-13 22:11:03 +00:00
|
|
|
, ("last synced", lastsynctime)
|
|
|
|
]
|