2013-09-12 16:21:21 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
2013-09-19 18:27:07 +00:00
|
|
|
- Copyright 2013 Antoine Beaupré
|
2013-09-12 16:21:21 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
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.Tuple.Utils
|
|
|
|
import Data.Ord
|
2013-09-12 16:21:21 +00:00
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
|
|
|
import Remote
|
|
|
|
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-09-20 01:33:44 +00:00
|
|
|
import qualified Option
|
|
|
|
import qualified Annex
|
2013-11-07 22:02:00 +00:00
|
|
|
import Git.Types (RemoteName)
|
2013-09-12 16:21:21 +00:00
|
|
|
|
|
|
|
def :: [Command]
|
2013-09-20 01:33:44 +00:00
|
|
|
def = [noCommit $ withOptions [allrepos] $ command "list" paramPaths seek
|
2013-09-12 16:21:21 +00:00
|
|
|
SectionQuery "show which remotes contain files"]
|
|
|
|
|
2013-09-20 01:33:44 +00:00
|
|
|
allrepos :: Option
|
|
|
|
allrepos = Option.flag [] "allrepos" "show all repositories, not only remotes"
|
|
|
|
|
2013-09-12 16:21:21 +00:00
|
|
|
seek :: [CommandSeek]
|
|
|
|
seek =
|
2013-09-20 01:33:44 +00:00
|
|
|
[ withValue getList $ withNothing . startHeader
|
|
|
|
, withValue getList $ withFilesInGit . whenAnnexed . start
|
2013-09-12 16:21:21 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
getList :: Annex [(UUID, RemoteName, TrustLevel)]
|
2013-09-20 01:33:44 +00:00
|
|
|
getList = ifM (Annex.getFlag $ Option.name allrepos)
|
|
|
|
( nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAll)
|
|
|
|
, getRemotes
|
|
|
|
)
|
|
|
|
where
|
|
|
|
getRemotes = do
|
|
|
|
rs <- remoteList
|
|
|
|
ts <- mapM (lookupTrust . uuid) rs
|
|
|
|
hereu <- getUUID
|
|
|
|
heretrust <- lookupTrust hereu
|
|
|
|
return $ (hereu, "here", heretrust) : zip3 (map uuid rs) (map name rs) ts
|
|
|
|
getAll = do
|
|
|
|
rs <- M.toList <$> uuidMap
|
|
|
|
rs3 <- forM rs $ \(u, n) -> (,,)
|
|
|
|
<$> pure u
|
|
|
|
<*> pure n
|
|
|
|
<*> lookupTrust u
|
|
|
|
return $ sortBy (comparing snd3) $
|
|
|
|
filter (\t -> thd3 t /= DeadTrusted) rs3
|
2013-09-12 16:21:21 +00:00
|
|
|
|
|
|
|
startHeader :: [(UUID, RemoteName, TrustLevel)] -> CommandStart
|
|
|
|
startHeader l = do
|
|
|
|
liftIO $ putStrLn $ header $ map (\(_, n, t) -> (n, t)) l
|
|
|
|
stop
|
|
|
|
|
|
|
|
start :: [(UUID, RemoteName, TrustLevel)] -> FilePath -> (Key, Backend) -> CommandStart
|
|
|
|
start l file (key, _) = do
|
|
|
|
ls <- S.fromList <$> keyLocations key
|
|
|
|
liftIO $ putStrLn $ format (map (\(u, _, t) -> (t, S.member u ls)) l) file
|
|
|
|
stop
|
|
|
|
|
|
|
|
type Present = Bool
|
|
|
|
|
|
|
|
header :: [(RemoteName, TrustLevel)] -> String
|
2013-09-25 07:09:06 +00:00
|
|
|
header remotes = unlines (zipWith formatheader [0..] remotes) ++ pipes (length remotes)
|
2013-09-12 16:21:21 +00:00
|
|
|
where
|
2013-09-25 07:09:06 +00:00
|
|
|
formatheader n (remotename, trustlevel) = pipes n ++ remotename ++ trust trustlevel
|
2013-09-12 16:21:21 +00:00
|
|
|
pipes = flip replicate '|'
|
|
|
|
trust UnTrusted = " (untrusted)"
|
|
|
|
trust _ = ""
|
|
|
|
|
|
|
|
format :: [(TrustLevel, Present)] -> FilePath -> String
|
|
|
|
format remotes file = thereMap ++ " " ++ file
|
|
|
|
where
|
|
|
|
thereMap = concatMap there remotes
|
|
|
|
there (UnTrusted, True) = "x"
|
|
|
|
there (_, True) = "X"
|
|
|
|
there (_, False) = "_"
|