2013-09-12 16:21:21 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-09-19 18:27:07 +00:00
|
|
|
- Copyright 2013 Antoine Beaupré
|
2013-09-12 16:21:21 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-09-12 16:21:21 +00:00
|
|
|
-}
|
|
|
|
|
2023-04-11 18:27:22 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2013-09-19 18:16:28 +00:00
|
|
|
module Command.List where
|
2013-09-12 16:21:21 +00:00
|
|
|
|
|
|
|
import qualified Data.Set as S
|
2013-09-20 01:33:44 +00:00
|
|
|
import qualified Data.Map as M
|
|
|
|
import Data.Function
|
|
|
|
import Data.Ord
|
2023-04-11 18:27:22 +00:00
|
|
|
import qualified Data.ByteString.Char8 as B8
|
2013-09-12 16:21:21 +00:00
|
|
|
|
|
|
|
import Command
|
|
|
|
import Remote
|
2023-04-11 18:27:22 +00:00
|
|
|
import qualified Annex
|
2013-09-12 16:21:21 +00:00
|
|
|
import Logs.Trust
|
2013-09-20 01:33:44 +00:00
|
|
|
import Logs.UUID
|
2013-09-12 16:21:21 +00:00
|
|
|
import Annex.UUID
|
2013-11-07 22:02:00 +00:00
|
|
|
import Git.Types (RemoteName)
|
2017-05-16 03:32:17 +00:00
|
|
|
import Utility.Tuple
|
2023-04-11 18:27:22 +00:00
|
|
|
import Utility.SafeOutput
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2022-06-29 17:28:08 +00:00
|
|
|
cmd = noCommit $ withAnnexOptions [annexedMatchingOptions] $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "list" SectionQuery
|
|
|
|
"show which remotes contain files"
|
2015-07-11 00:46:48 +00:00
|
|
|
paramPaths (seek <$$> optParser)
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2015-07-11 00:46:48 +00:00
|
|
|
data ListOptions = ListOptions
|
|
|
|
{ listThese :: CmdParams
|
|
|
|
, allRepos :: Bool
|
|
|
|
}
|
2013-09-20 01:33:44 +00:00
|
|
|
|
2015-07-11 00:46:48 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser ListOptions
|
|
|
|
optParser desc = ListOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> switch
|
|
|
|
( long "allrepos"
|
|
|
|
<> help "show all repositories, not only remotes"
|
|
|
|
)
|
|
|
|
|
|
|
|
seek :: ListOptions -> CommandSeek
|
|
|
|
seek o = do
|
|
|
|
list <- getList o
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
printHeader list
|
2020-07-13 21:04:02 +00:00
|
|
|
let seeker = AnnexedFileSeeker
|
2020-07-22 18:23:28 +00:00
|
|
|
{ startAction = start list
|
2020-07-13 21:04:02 +00:00
|
|
|
, checkContentPresent = Nothing
|
|
|
|
, usesLocationLog = True
|
|
|
|
}
|
|
|
|
withFilesInGitAnnex ww seeker =<< workTreeItems ww (listThese o)
|
2020-05-28 19:55:17 +00:00
|
|
|
where
|
2023-04-25 23:26:20 +00:00
|
|
|
ww = WarnUnmatchLsFiles "list"
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2015-07-11 00:46:48 +00:00
|
|
|
getList :: ListOptions -> Annex [(UUID, RemoteName, TrustLevel)]
|
|
|
|
getList o
|
|
|
|
| allRepos o = nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAllUUIDs)
|
|
|
|
| otherwise = getRemotes
|
2013-09-20 01:33:44 +00:00
|
|
|
where
|
|
|
|
getRemotes = do
|
|
|
|
rs <- remoteList
|
|
|
|
ts <- mapM (lookupTrust . uuid) rs
|
|
|
|
hereu <- getUUID
|
|
|
|
heretrust <- lookupTrust hereu
|
2016-06-04 18:33:31 +00:00
|
|
|
let l = (hereu, "here", heretrust) : zip3 (map uuid rs) (map name rs) ts
|
|
|
|
return $ filter (\(_, _, t) -> t /= DeadTrusted) l
|
2014-03-22 14:42:38 +00:00
|
|
|
getAllUUIDs = do
|
2019-01-01 19:39:45 +00:00
|
|
|
rs <- M.toList <$> uuidDescMap
|
|
|
|
rs3 <- forM rs $ \(u, d) -> (,,)
|
2013-09-20 01:33:44 +00:00
|
|
|
<$> pure u
|
2019-01-01 19:39:45 +00:00
|
|
|
<*> pure (fromUUIDDesc d)
|
2013-09-20 01:33:44 +00:00
|
|
|
<*> lookupTrust u
|
|
|
|
return $ sortBy (comparing snd3) $
|
|
|
|
filter (\t -> thd3 t /= DeadTrusted) rs3
|
2013-09-12 16:21:21 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
printHeader :: [(UUID, RemoteName, TrustLevel)] -> Annex ()
|
2023-04-11 18:27:22 +00:00
|
|
|
printHeader l = liftIO $ putStrLn $ safeOutput $ lheader $ map (\(_, n, t) -> (n, t)) l
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start :: [(UUID, RemoteName, TrustLevel)] -> SeekInput -> RawFilePath -> Key -> CommandStart
|
2020-09-15 20:22:44 +00:00
|
|
|
start l _si file key = do
|
2013-09-12 16:21:21 +00:00
|
|
|
ls <- S.fromList <$> keyLocations key
|
2023-04-11 18:27:22 +00:00
|
|
|
qp <- coreQuotePath <$> Annex.getGitConfig
|
|
|
|
liftIO $ B8.putStrLn $ quote qp $
|
|
|
|
format (map (\(u, _, t) -> (t, S.member u ls)) l) file
|
2013-09-12 16:21:21 +00:00
|
|
|
stop
|
|
|
|
|
|
|
|
type Present = Bool
|
|
|
|
|
2015-07-11 00:46:48 +00:00
|
|
|
lheader :: [(RemoteName, TrustLevel)] -> String
|
|
|
|
lheader remotes = unlines (zipWith formatheader [0..] remotes) ++ pipes (length remotes)
|
2013-09-12 16:21:21 +00:00
|
|
|
where
|
2014-10-09 19:09:26 +00:00
|
|
|
formatheader n (remotename, trustlevel) = pipes n ++ remotename ++ trust trustlevel
|
|
|
|
pipes = flip replicate '|'
|
|
|
|
trust UnTrusted = " (untrusted)"
|
|
|
|
trust _ = ""
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2023-04-11 18:27:22 +00:00
|
|
|
format :: [(TrustLevel, Present)] -> RawFilePath -> StringContainingQuotedPath
|
|
|
|
format remotes file = UnquotedString (thereMap) <> " " <> QuotedPath file
|
2013-09-12 16:21:21 +00:00
|
|
|
where
|
2014-10-09 19:09:26 +00:00
|
|
|
thereMap = concatMap there remotes
|
|
|
|
there (UnTrusted, True) = "x"
|
|
|
|
there (_, True) = "X"
|
|
|
|
there (_, False) = "_"
|