2011-09-28 18:03:59 +00:00
|
|
|
{- git ls-tree interface
|
|
|
|
-
|
2020-12-22 18:06:40 +00:00
|
|
|
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
|
2011-09-28 18:03:59 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-09-28 18:03:59 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Git.LsTree (
|
2011-09-28 20:43:10 +00:00
|
|
|
TreeItem(..),
|
2019-02-21 21:32:59 +00:00
|
|
|
LsTreeMode(..),
|
2011-09-29 23:04:24 +00:00
|
|
|
lsTree,
|
2016-02-23 20:36:08 +00:00
|
|
|
lsTree',
|
2020-12-22 18:06:40 +00:00
|
|
|
lsTreeStrict,
|
|
|
|
lsTreeStrict',
|
2013-10-21 19:28:06 +00:00
|
|
|
lsTreeParams,
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
lsTreeFiles,
|
2016-02-23 20:36:08 +00:00
|
|
|
parseLsTree,
|
2019-05-20 20:37:04 +00:00
|
|
|
formatLsTree,
|
2011-09-28 18:03:59 +00:00
|
|
|
) where
|
|
|
|
|
2011-12-20 18:37:53 +00:00
|
|
|
import Common
|
2011-09-30 03:43:42 +00:00
|
|
|
import Git
|
2011-12-14 19:56:11 +00:00
|
|
|
import Git.Command
|
2013-10-17 18:51:19 +00:00
|
|
|
import Git.FilePath
|
2011-12-13 19:22:43 +00:00
|
|
|
import qualified Git.Filename
|
2019-12-06 17:58:28 +00:00
|
|
|
import Utility.Attoparsec
|
2011-09-28 18:03:59 +00:00
|
|
|
|
2015-05-10 20:50:46 +00:00
|
|
|
import Numeric
|
2019-11-25 20:18:19 +00:00
|
|
|
import Data.Either
|
2015-05-10 20:50:46 +00:00
|
|
|
import System.Posix.Types
|
2019-11-25 20:18:19 +00:00
|
|
|
import qualified Data.ByteString as S
|
|
|
|
import qualified Data.ByteString.Lazy as L
|
2020-12-22 18:06:40 +00:00
|
|
|
import qualified Data.Attoparsec.ByteString as AS
|
2019-11-25 20:18:19 +00:00
|
|
|
import qualified Data.Attoparsec.ByteString.Lazy as A
|
|
|
|
import qualified Data.Attoparsec.ByteString.Char8 as A8
|
2015-05-10 20:50:46 +00:00
|
|
|
|
2011-09-28 18:03:59 +00:00
|
|
|
data TreeItem = TreeItem
|
2011-09-28 18:14:52 +00:00
|
|
|
{ mode :: FileMode
|
2019-11-25 20:18:19 +00:00
|
|
|
, typeobj :: S.ByteString
|
2016-01-01 19:56:24 +00:00
|
|
|
, sha :: Ref
|
2013-10-17 18:51:19 +00:00
|
|
|
, file :: TopFilePath
|
2020-12-22 18:06:40 +00:00
|
|
|
} deriving (Show)
|
2011-09-28 18:03:59 +00:00
|
|
|
|
2019-02-21 21:32:59 +00:00
|
|
|
data LsTreeMode = LsTreeRecursive | LsTreeNonRecursive
|
|
|
|
|
|
|
|
{- Lists the contents of a tree, with lazy output. -}
|
|
|
|
lsTree :: LsTreeMode -> Ref -> Repo -> IO ([TreeItem], IO Bool)
|
2016-02-23 20:36:08 +00:00
|
|
|
lsTree = lsTree' []
|
|
|
|
|
2019-02-21 21:32:59 +00:00
|
|
|
lsTree' :: [CommandParam] -> LsTreeMode -> Ref -> Repo -> IO ([TreeItem], IO Bool)
|
2019-02-22 16:41:17 +00:00
|
|
|
lsTree' ps lsmode t repo = do
|
|
|
|
(l, cleanup) <- pipeNullSplit (lsTreeParams lsmode t ps) repo
|
2019-11-25 20:18:19 +00:00
|
|
|
return (rights (map parseLsTree l), cleanup)
|
2013-10-21 19:28:06 +00:00
|
|
|
|
2020-12-22 18:06:40 +00:00
|
|
|
lsTreeStrict :: LsTreeMode -> Ref -> Repo -> IO [TreeItem]
|
|
|
|
lsTreeStrict = lsTreeStrict' []
|
|
|
|
|
|
|
|
lsTreeStrict' :: [CommandParam] -> LsTreeMode -> Ref -> Repo -> IO [TreeItem]
|
|
|
|
lsTreeStrict' ps lsmode t repo = rights . map parseLsTreeStrict
|
|
|
|
<$> pipeNullSplitStrict (lsTreeParams lsmode t ps) repo
|
|
|
|
|
2019-02-21 21:32:59 +00:00
|
|
|
lsTreeParams :: LsTreeMode -> Ref -> [CommandParam] -> [CommandParam]
|
2019-02-22 16:41:17 +00:00
|
|
|
lsTreeParams lsmode r ps =
|
2015-06-01 17:52:23 +00:00
|
|
|
[ Param "ls-tree"
|
|
|
|
, Param "--full-tree"
|
|
|
|
, Param "-z"
|
2019-02-21 21:32:59 +00:00
|
|
|
] ++ recursiveparams ++ ps ++
|
2015-07-06 18:21:43 +00:00
|
|
|
[ Param "--"
|
|
|
|
, File $ fromRef r
|
2015-06-01 17:52:23 +00:00
|
|
|
]
|
2019-02-21 21:32:59 +00:00
|
|
|
where
|
2019-02-22 16:41:17 +00:00
|
|
|
recursiveparams = case lsmode of
|
2019-02-21 21:32:59 +00:00
|
|
|
LsTreeRecursive -> [ Param "-r" ]
|
|
|
|
LsTreeNonRecursive -> []
|
2011-09-28 18:03:59 +00:00
|
|
|
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
{- Lists specified files in a tree. -}
|
|
|
|
lsTreeFiles :: Ref -> [FilePath] -> Repo -> IO [TreeItem]
|
2019-11-25 20:18:19 +00:00
|
|
|
lsTreeFiles t fs repo = rights . map (parseLsTree . L.fromStrict)
|
|
|
|
<$> pipeNullSplitStrict ps repo
|
2013-03-19 02:09:51 +00:00
|
|
|
where
|
2015-06-01 17:52:23 +00:00
|
|
|
ps =
|
|
|
|
[ Param "ls-tree"
|
|
|
|
, Param "--full-tree"
|
|
|
|
, Param "-z"
|
|
|
|
, Param "--"
|
|
|
|
, File $ fromRef t
|
|
|
|
] ++ map File fs
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
parseLsTree :: L.ByteString -> Either String TreeItem
|
|
|
|
parseLsTree b = case A.parse parserLsTree b of
|
|
|
|
A.Done _ r -> Right r
|
|
|
|
A.Fail _ _ err -> Left err
|
|
|
|
|
2020-12-22 18:06:40 +00:00
|
|
|
parseLsTreeStrict :: S.ByteString -> Either String TreeItem
|
|
|
|
parseLsTreeStrict b = go (AS.parse parserLsTree b)
|
|
|
|
where
|
|
|
|
go (AS.Done _ r) = Right r
|
|
|
|
go (AS.Fail _ _ err) = Left err
|
|
|
|
go (AS.Partial c) = go (c mempty)
|
|
|
|
|
2017-02-20 17:44:55 +00:00
|
|
|
{- Parses a line of ls-tree output, in format:
|
|
|
|
- mode SP type SP sha TAB file
|
|
|
|
-
|
2011-09-28 18:03:59 +00:00
|
|
|
- (The --long format is not currently supported.) -}
|
2019-11-25 20:18:19 +00:00
|
|
|
parserLsTree :: A.Parser TreeItem
|
|
|
|
parserLsTree = TreeItem
|
|
|
|
-- mode
|
2019-12-06 17:58:28 +00:00
|
|
|
<$> octal
|
2019-11-25 20:18:19 +00:00
|
|
|
<* A8.char ' '
|
|
|
|
-- type
|
2020-01-07 15:35:17 +00:00
|
|
|
<*> A8.takeTill (== ' ')
|
2019-11-25 20:18:19 +00:00
|
|
|
<* A8.char ' '
|
|
|
|
-- sha
|
2020-04-07 15:54:27 +00:00
|
|
|
<*> (Ref <$> A8.takeTill (== '\t'))
|
2019-11-25 20:18:19 +00:00
|
|
|
<* A8.char '\t'
|
|
|
|
-- file
|
2019-12-09 17:49:05 +00:00
|
|
|
<*> (asTopFilePath . Git.Filename.decode <$> A.takeByteString)
|
2019-05-20 20:37:04 +00:00
|
|
|
|
|
|
|
{- Inverse of parseLsTree -}
|
|
|
|
formatLsTree :: TreeItem -> String
|
|
|
|
formatLsTree ti = unwords
|
|
|
|
[ showOct (mode ti) ""
|
2019-11-25 20:18:19 +00:00
|
|
|
, decodeBS (typeobj ti)
|
2020-04-07 15:54:27 +00:00
|
|
|
, fromRef (sha ti)
|
2019-12-09 17:49:05 +00:00
|
|
|
, fromRawFilePath (getTopFilePath (file ti))
|
2019-05-20 20:37:04 +00:00
|
|
|
]
|