aboutsummaryrefslogtreecommitdiff
path: root/Command/List.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-09-19 21:33:44 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-09-19 21:42:03 -0400
commit0df935bcb77efaaabaad09ff775608f8bfd6ec2e (patch)
tree87d87fd41a1ed6615dc8dba73d0068ada6db6638 /Command/List.hs
parent962713122b0076222e1f61ce4989efe4eef2f12e (diff)
list --allrepos
Diffstat (limited to 'Command/List.hs')
-rw-r--r--Command/List.hs41
1 files changed, 32 insertions, 9 deletions
diff --git a/Command/List.hs b/Command/List.hs
index ae764ecf0..1c424cddc 100644
--- a/Command/List.hs
+++ b/Command/List.hs
@@ -9,30 +9,53 @@
module Command.List where
import qualified Data.Set as S
+import qualified Data.Map as M
+import Data.Function
+import Data.Tuple.Utils
+import Data.Ord
import Common.Annex
import Command
import Remote
import Logs.Trust
+import Logs.UUID
import Annex.UUID
+import qualified Option
+import qualified Annex
def :: [Command]
-def = [noCommit $ command "list" paramPaths seek
+def = [noCommit $ withOptions [allrepos] $ command "list" paramPaths seek
SectionQuery "show which remotes contain files"]
+allrepos :: Option
+allrepos = Option.flag [] "allrepos" "show all repositories, not only remotes"
+
seek :: [CommandSeek]
seek =
- [ withValue getList $ \l -> withNothing $ startHeader l
- , withValue getList $ \l -> withFilesInGit $ whenAnnexed $ start l
+ [ withValue getList $ withNothing . startHeader
+ , withValue getList $ withFilesInGit . whenAnnexed . start
]
getList :: Annex [(UUID, RemoteName, TrustLevel)]
-getList = 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
+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
startHeader :: [(UUID, RemoteName, TrustLevel)] -> CommandStart
startHeader l = do