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
|
|
|
-
|
|
|
|
- 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 Annex
|
2013-11-07 22:02:00 +00:00
|
|
|
import Git.Types (RemoteName)
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2014-10-14 18:20:10 +00:00
|
|
|
cmd :: [Command]
|
|
|
|
cmd = [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
|
2014-01-26 20:25:55 +00:00
|
|
|
allrepos = flagOption [] "allrepos" "show all repositories, not only remotes"
|
2013-09-20 01:33:44 +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
|
|
|
seek :: CommandSeek
|
|
|
|
seek ps = do
|
|
|
|
list <- getList
|
|
|
|
printHeader list
|
|
|
|
withFilesInGit (whenAnnexed $ start list) ps
|
2013-09-12 16:21:21 +00:00
|
|
|
|
|
|
|
getList :: Annex [(UUID, RemoteName, TrustLevel)]
|
2014-01-26 20:25:55 +00:00
|
|
|
getList = ifM (Annex.getFlag $ optionName allrepos)
|
2014-03-22 14:42:38 +00:00
|
|
|
( nubBy ((==) `on` fst3) <$> ((++) <$> getRemotes <*> getAllUUIDs)
|
2013-09-20 01:33:44 +00:00
|
|
|
, 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
|
2014-03-22 14:42:38 +00:00
|
|
|
getAllUUIDs = do
|
2013-09-20 01:33:44 +00:00
|
|
|
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
|
|
|
|
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 ()
|
|
|
|
printHeader l = liftIO $ putStrLn $ header $ map (\(_, n, t) -> (n, t)) l
|
2013-09-12 16:21:21 +00:00
|
|
|
|
2014-04-17 22:03:39 +00:00
|
|
|
start :: [(UUID, RemoteName, TrustLevel)] -> FilePath -> Key -> CommandStart
|
|
|
|
start l file key = do
|
2013-09-12 16:21:21 +00:00
|
|
|
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
|
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
|
|
|
|
|
|
|
format :: [(TrustLevel, Present)] -> FilePath -> String
|
|
|
|
format remotes file = thereMap ++ " " ++ file
|
|
|
|
where
|
2014-10-09 19:09:26 +00:00
|
|
|
thereMap = concatMap there remotes
|
|
|
|
there (UnTrusted, True) = "x"
|
|
|
|
there (_, True) = "X"
|
|
|
|
there (_, False) = "_"
|