more indentation. must stop.

This commit is contained in:
Joey Hess 2012-10-28 22:09:09 -04:00
parent def5b4cc64
commit ec0bac9d73
5 changed files with 183 additions and 185 deletions

View file

@ -173,58 +173,58 @@ startDaemon assistant foreground webappwaiter
logfd <- liftIO . openLog =<< fromRepo gitAnnexLogFile logfd <- liftIO . openLog =<< fromRepo gitAnnexLogFile
pidfile <- fromRepo gitAnnexPidFile pidfile <- fromRepo gitAnnexPidFile
go $ Utility.Daemon.daemonize logfd (Just pidfile) False go $ Utility.Daemon.daemonize logfd (Just pidfile) False
where where
go d = startAssistant assistant d webappwaiter go d = startAssistant assistant d webappwaiter
startAssistant :: Bool -> (IO () -> IO ()) -> Maybe (String -> FilePath -> IO ()) -> Annex () startAssistant :: Bool -> (IO () -> IO ()) -> Maybe (String -> FilePath -> IO ()) -> Annex ()
startAssistant assistant daemonize webappwaiter = withThreadState $ \st -> do startAssistant assistant daemonize webappwaiter = withThreadState $ \st -> do
checkCanWatch checkCanWatch
dstatus <- startDaemonStatus dstatus <- startDaemonStatus
liftIO $ daemonize $ run dstatus st liftIO $ daemonize $ run dstatus st
where where
run dstatus st = do run dstatus st = do
changechan <- newChangeChan changechan <- newChangeChan
commitchan <- newCommitChan commitchan <- newCommitChan
pushmap <- newFailedPushMap pushmap <- newFailedPushMap
transferqueue <- newTransferQueue transferqueue <- newTransferQueue
transferslots <- newTransferSlots transferslots <- newTransferSlots
scanremotes <- newScanRemoteMap scanremotes <- newScanRemoteMap
branchhandle <- newBranchChangeHandle branchhandle <- newBranchChangeHandle
pushnotifier <- newPushNotifier pushnotifier <- newPushNotifier
#ifdef WITH_WEBAPP #ifdef WITH_WEBAPP
urlrenderer <- newUrlRenderer urlrenderer <- newUrlRenderer
#endif #endif
mapM_ (startthread dstatus) mapM_ (startthread dstatus)
[ watch $ commitThread st changechan commitchan transferqueue dstatus [ watch $ commitThread st changechan commitchan transferqueue dstatus
#ifdef WITH_WEBAPP #ifdef WITH_WEBAPP
, assist $ webAppThread (Just st) dstatus scanremotes transferqueue transferslots pushnotifier commitchan urlrenderer Nothing webappwaiter , assist $ webAppThread (Just st) dstatus scanremotes transferqueue transferslots pushnotifier commitchan urlrenderer Nothing webappwaiter
#ifdef WITH_PAIRING #ifdef WITH_PAIRING
, assist $ pairListenerThread st dstatus scanremotes urlrenderer , assist $ pairListenerThread st dstatus scanremotes urlrenderer
#endif #endif
#endif #endif
, assist $ pushThread st dstatus commitchan pushmap pushnotifier , assist $ pushThread st dstatus commitchan pushmap pushnotifier
, assist $ pushRetryThread st dstatus pushmap pushnotifier , assist $ pushRetryThread st dstatus pushmap pushnotifier
, assist $ mergeThread st dstatus transferqueue branchhandle , assist $ mergeThread st dstatus transferqueue branchhandle
, assist $ transferWatcherThread st dstatus transferqueue , assist $ transferWatcherThread st dstatus transferqueue
, assist $ transferPollerThread st dstatus , assist $ transferPollerThread st dstatus
, assist $ transfererThread st dstatus transferqueue transferslots commitchan , assist $ transfererThread st dstatus transferqueue transferslots commitchan
, assist $ daemonStatusThread st dstatus , assist $ daemonStatusThread st dstatus
, assist $ sanityCheckerThread st dstatus transferqueue changechan , assist $ sanityCheckerThread st dstatus transferqueue changechan
, assist $ mountWatcherThread st dstatus scanremotes pushnotifier , assist $ mountWatcherThread st dstatus scanremotes pushnotifier
, assist $ netWatcherThread st dstatus scanremotes pushnotifier , assist $ netWatcherThread st dstatus scanremotes pushnotifier
, assist $ netWatcherFallbackThread st dstatus scanremotes pushnotifier , assist $ netWatcherFallbackThread st dstatus scanremotes pushnotifier
, assist $ transferScannerThread st dstatus scanremotes transferqueue , assist $ transferScannerThread st dstatus scanremotes transferqueue
, assist $ configMonitorThread st dstatus branchhandle commitchan , assist $ configMonitorThread st dstatus branchhandle commitchan
#ifdef WITH_XMPP #ifdef WITH_XMPP
, assist $ pushNotifierThread st dstatus pushnotifier , assist $ pushNotifierThread st dstatus pushnotifier
#endif #endif
, watch $ watchThread st dstatus transferqueue changechan , watch $ watchThread st dstatus transferqueue changechan
] ]
waitForTermination waitForTermination
watch a = (True, a) watch a = (True, a)
assist a = (False, a) assist a = (False, a)
startthread dstatus (watcher, t) startthread dstatus (watcher, t)
| watcher || assistant = void $ forkIO $ | watcher || assistant = void $ forkIO $
runNamedThread dstatus t runNamedThread dstatus t
| otherwise = noop | otherwise = noop

View file

@ -40,16 +40,16 @@ orderedList = do
if not $ null l if not $ null l
then return l then return l
else handle =<< Annex.getState Annex.forcebackend else handle =<< Annex.getState Annex.forcebackend
where where
handle Nothing = standard handle Nothing = standard
handle (Just "") = standard handle (Just "") = standard
handle (Just name) = do handle (Just name) = do
l' <- (lookupBackendName name :) <$> standard l' <- (lookupBackendName name :) <$> standard
Annex.changeState $ \s -> s { Annex.backends = l' } Annex.changeState $ \s -> s { Annex.backends = l' }
return l' return l'
standard = parseBackendList <$> getConfig (annexConfig "backends") "" standard = parseBackendList <$> getConfig (annexConfig "backends") ""
parseBackendList [] = list parseBackendList [] = list
parseBackendList s = map lookupBackendName $ words s parseBackendList s = map lookupBackendName $ words s
{- Generates a key for a file, trying each backend in turn until one {- Generates a key for a file, trying each backend in turn until one
- accepts it. - accepts it.
@ -66,12 +66,12 @@ genKey' (b:bs) source = do
case r of case r of
Nothing -> genKey' bs source Nothing -> genKey' bs source
Just k -> return $ Just (makesane k, b) Just k -> return $ Just (makesane k, b)
where where
-- keyNames should not contain newline characters. -- keyNames should not contain newline characters.
makesane k = k { keyName = map fixbadchar (keyName k) } makesane k = k { keyName = map fixbadchar (keyName k) }
fixbadchar c fixbadchar c
| c == '\n' = '_' | c == '\n' = '_'
| otherwise = c | otherwise = c
{- Looks up the key and backend corresponding to an annexed file, {- Looks up the key and backend corresponding to an annexed file,
- by examining what the file symlinks to. -} - by examining what the file symlinks to. -}
@ -81,35 +81,33 @@ lookupFile file = do
case tl of case tl of
Left _ -> return Nothing Left _ -> return Nothing
Right l -> makekey l Right l -> makekey l
where where
makekey l = maybe (return Nothing) (makeret l) (fileKey $ takeFileName l) makekey l = maybe (return Nothing) (makeret l) (fileKey $ takeFileName l)
makeret l k = let bname = keyBackendName k in makeret l k = let bname = keyBackendName k in
case maybeLookupBackendName bname of case maybeLookupBackendName bname of
Just backend -> do Just backend -> do
return $ Just (k, backend) return $ Just (k, backend)
Nothing -> do Nothing -> do
when (isLinkToAnnex l) $ warning $ when (isLinkToAnnex l) $ warning $
"skipping " ++ file ++ "skipping " ++ file ++
" (unknown backend " ++ " (unknown backend " ++ bname ++ ")"
bname ++ ")" return Nothing
return Nothing
{- Looks up the backend that should be used for a file. {- Looks up the backend that should be used for a file.
- That can be configured on a per-file basis in the gitattributes file. - That can be configured on a per-file basis in the gitattributes file.
-} -}
chooseBackend :: FilePath -> Annex (Maybe Backend) chooseBackend :: FilePath -> Annex (Maybe Backend)
chooseBackend f = Annex.getState Annex.forcebackend >>= go chooseBackend f = Annex.getState Annex.forcebackend >>= go
where where
go Nothing = maybeLookupBackendName <$> go Nothing = maybeLookupBackendName <$> checkAttr "annex.backend" f
checkAttr "annex.backend" f go (Just _) = Just . Prelude.head <$> orderedList
go (Just _) = Just . Prelude.head <$> orderedList
{- Looks up a backend by name. May fail if unknown. -} {- Looks up a backend by name. May fail if unknown. -}
lookupBackendName :: String -> Backend lookupBackendName :: String -> Backend
lookupBackendName s = fromMaybe unknown $ maybeLookupBackendName s lookupBackendName s = fromMaybe unknown $ maybeLookupBackendName s
where where
unknown = error $ "unknown backend " ++ s unknown = error $ "unknown backend " ++ s
maybeLookupBackendName :: String -> Maybe Backend maybeLookupBackendName :: String -> Maybe Backend
maybeLookupBackendName s = headMaybe matches maybeLookupBackendName s = headMaybe matches
where where
matches = filter (\b -> s == B.name b) list matches = filter (\b -> s == B.name b) list

104
Limit.hs
View file

@ -54,9 +54,9 @@ getMatcher' = do
{- Adds something to the limit list, which is built up reversed. -} {- Adds something to the limit list, which is built up reversed. -}
add :: Utility.Matcher.Token (Annex.FileInfo -> Annex Bool) -> Annex () add :: Utility.Matcher.Token (Annex.FileInfo -> Annex Bool) -> Annex ()
add l = Annex.changeState $ \s -> s { Annex.limit = prepend $ Annex.limit s } add l = Annex.changeState $ \s -> s { Annex.limit = prepend $ Annex.limit s }
where where
prepend (Left ls) = Left $ l:ls prepend (Left ls) = Left $ l:ls
prepend _ = error "internal" prepend _ = error "internal"
{- Adds a new token. -} {- Adds a new token. -}
addToken :: String -> Annex () addToken :: String -> Annex ()
@ -83,9 +83,9 @@ limitExclude glob = Right $ const $ return . not . matchglob glob
matchglob :: String -> Annex.FileInfo -> Bool matchglob :: String -> Annex.FileInfo -> Bool
matchglob glob (Annex.FileInfo { Annex.matchFile = f }) = matchglob glob (Annex.FileInfo { Annex.matchFile = f }) =
isJust $ match cregex f [] isJust $ match cregex f []
where where
cregex = compile regex [] cregex = compile regex []
regex = '^':wildToRegex glob regex = '^':wildToRegex glob
{- Adds a limit to skip files not believed to be present {- Adds a limit to skip files not believed to be present
- in a specfied repository. -} - in a specfied repository. -}
@ -97,21 +97,21 @@ limitIn name = Right $ \notpresent -> check $
if name == "." if name == "."
then inhere notpresent then inhere notpresent
else inremote notpresent else inremote notpresent
where where
check a = lookupFile >=> handle a check a = lookupFile >=> handle a
handle _ Nothing = return False handle _ Nothing = return False
handle a (Just (key, _)) = a key handle a (Just (key, _)) = a key
inremote notpresent key = do inremote notpresent key = do
u <- Remote.nameToUUID name u <- Remote.nameToUUID name
us <- Remote.keyLocations key us <- Remote.keyLocations key
return $ u `elem` us && u `S.notMember` notpresent return $ u `elem` us && u `S.notMember` notpresent
inhere notpresent key inhere notpresent key
| S.null notpresent = inAnnex key | S.null notpresent = inAnnex key
| otherwise = do | otherwise = do
u <- getUUID u <- getUUID
if u `S.member` notpresent if u `S.member` notpresent
then return False then return False
else inAnnex key else inAnnex key
{- Limit to content that is currently present on a uuid. -} {- Limit to content that is currently present on a uuid. -}
limitPresent :: Maybe UUID -> MkLimit limitPresent :: Maybe UUID -> MkLimit
@ -122,10 +122,10 @@ limitPresent u _ = Right $ const $ check $ \key -> do
else do else do
us <- Remote.keyLocations key us <- Remote.keyLocations key
return $ maybe False (`elem` us) u return $ maybe False (`elem` us) u
where where
check a = lookupFile >=> handle a check a = lookupFile >=> handle a
handle _ Nothing = return False handle _ Nothing = return False
handle a (Just (key, _)) = a key handle a (Just (key, _)) = a key
{- Adds a limit to skip files not believed to have the specified number {- Adds a limit to skip files not believed to have the specified number
- of copies. -} - of copies. -}
@ -139,18 +139,18 @@ limitCopies want = case split ":" want of
Nothing -> go n $ checkgroup v Nothing -> go n $ checkgroup v
[n] -> go n $ const $ return True [n] -> go n $ const $ return True
_ -> Left "bad value for copies" _ -> Left "bad value for copies"
where where
go num good = case readish num of go num good = case readish num of
Nothing -> Left "bad number for copies" Nothing -> Left "bad number for copies"
Just n -> Right $ \notpresent f -> Just n -> Right $ \notpresent f ->
lookupFile f >>= handle n good notpresent lookupFile f >>= handle n good notpresent
handle _ _ _ Nothing = return False handle _ _ _ Nothing = return False
handle n good notpresent (Just (key, _)) = do handle n good notpresent (Just (key, _)) = do
us <- filter (`S.notMember` notpresent) us <- filter (`S.notMember` notpresent)
<$> (filterM good =<< Remote.keyLocations key) <$> (filterM good =<< Remote.keyLocations key)
return $ length us >= n return $ length us >= n
checktrust t u = (== t) <$> lookupTrust u checktrust t u = (== t) <$> lookupTrust u
checkgroup g u = S.member g <$> lookupGroups u checkgroup g u = S.member g <$> lookupGroups u
{- Adds a limit to skip files not believed to be present in all {- Adds a limit to skip files not believed to be present in all
- repositories in the specified group. -} - repositories in the specified group. -}
@ -163,15 +163,15 @@ limitInAllGroup :: GroupMap -> MkLimit
limitInAllGroup m groupname limitInAllGroup m groupname
| S.null want = Right $ const $ const $ return True | S.null want = Right $ const $ const $ return True
| otherwise = Right $ \notpresent -> lookupFile >=> check notpresent | otherwise = Right $ \notpresent -> lookupFile >=> check notpresent
where where
want = fromMaybe S.empty $ M.lookup groupname $ uuidsByGroup m want = fromMaybe S.empty $ M.lookup groupname $ uuidsByGroup m
check _ Nothing = return False check _ Nothing = return False
check notpresent (Just (key, _)) check notpresent (Just (key, _))
-- optimisation: Check if a wanted uuid is notpresent. -- optimisation: Check if a wanted uuid is notpresent.
| not (S.null (S.intersection want notpresent)) = return False | not (S.null (S.intersection want notpresent)) = return False
| otherwise = do | otherwise = do
present <- S.fromList <$> Remote.keyLocations key present <- S.fromList <$> Remote.keyLocations key
return $ S.null $ want `S.difference` present return $ S.null $ want `S.difference` present
{- Adds a limit to skip files not using a specified key-value backend. -} {- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex () addInBackend :: String -> Annex ()
@ -179,9 +179,9 @@ addInBackend = addLimit . limitInBackend
limitInBackend :: MkLimit limitInBackend :: MkLimit
limitInBackend name = Right $ const $ lookupFile >=> check limitInBackend name = Right $ const $ lookupFile >=> check
where where
wanted = Backend.lookupBackendName name wanted = Backend.lookupBackendName name
check = return . maybe False ((==) wanted . snd) check = return . maybe False ((==) wanted . snd)
{- Adds a limit to skip files that are too large or too small -} {- Adds a limit to skip files that are too large or too small -}
addLargerThan :: String -> Annex () addLargerThan :: String -> Annex ()
@ -194,9 +194,9 @@ limitSize :: (Maybe Integer -> Maybe Integer -> Bool) -> MkLimit
limitSize vs s = case readSize dataUnits s of limitSize vs s = case readSize dataUnits s of
Nothing -> Left "bad size" Nothing -> Left "bad size"
Just sz -> Right $ const $ lookupFile >=> check sz Just sz -> Right $ const $ lookupFile >=> check sz
where where
check _ Nothing = return False check _ Nothing = return False
check sz (Just (key, _)) = return $ keySize key `vs` Just sz check sz (Just (key, _)) = return $ keySize key `vs` Just sz
addTimeLimit :: String -> Annex () addTimeLimit :: String -> Annex ()
addTimeLimit s = do addTimeLimit s = do

View file

@ -65,29 +65,29 @@ showProgress = handle q $
- The action is passed a callback to use to update the meter. -} - The action is passed a callback to use to update the meter. -}
metered :: (Maybe MeterUpdate) -> Key -> (MeterUpdate -> Annex a) -> Annex a metered :: (Maybe MeterUpdate) -> Key -> (MeterUpdate -> Annex a) -> Annex a
metered combinemeterupdate key a = withOutputType $ go (keySize key) metered combinemeterupdate key a = withOutputType $ go (keySize key)
where where
go (Just size) NormalOutput = do go (Just size) NormalOutput = do
progress <- liftIO $ newProgress "" size progress <- liftIO $ newProgress "" size
meter <- liftIO $ newMeter progress "B" 25 (renderNums binaryOpts 1) meter <- liftIO $ newMeter progress "B" 25 (renderNums binaryOpts 1)
showOutput showOutput
liftIO $ displayMeter stdout meter liftIO $ displayMeter stdout meter
r <- a $ \n -> liftIO $ do r <- a $ \n -> liftIO $ do
incrP progress n incrP progress n
displayMeter stdout meter displayMeter stdout meter
maybe noop (\m -> m n) combinemeterupdate maybe noop (\m -> m n) combinemeterupdate
liftIO $ clearMeter stdout meter liftIO $ clearMeter stdout meter
return r return r
go _ _ = a (const noop) go _ _ = a (const noop)
showSideAction :: String -> Annex () showSideAction :: String -> Annex ()
showSideAction m = Annex.getState Annex.output >>= go showSideAction m = Annex.getState Annex.output >>= go
where where
go (MessageState v StartBlock) = do go (MessageState v StartBlock) = do
p p
Annex.changeState $ \s -> s { Annex.output = MessageState v InBlock } Annex.changeState $ \s -> s { Annex.output = MessageState v InBlock }
go (MessageState _ InBlock) = return () go (MessageState _ InBlock) = return ()
go _ = p go _ = p
p = handle q $ putStrLn $ "(" ++ m ++ "...)" p = handle q $ putStrLn $ "(" ++ m ++ "...)"
showStoringStateAction :: Annex () showStoringStateAction :: Annex ()
showStoringStateAction = showSideAction "Recording state in git" showStoringStateAction = showSideAction "Recording state in git"
@ -106,8 +106,8 @@ doSideAction' b a = do
o <- Annex.getState Annex.output o <- Annex.getState Annex.output
set $ o { sideActionBlock = b } set $ o { sideActionBlock = b }
set o `after` a set o `after` a
where where
set o = Annex.changeState $ \s -> s { Annex.output = o } set o = Annex.changeState $ \s -> s { Annex.output = o }
showOutput :: Annex () showOutput :: Annex ()
showOutput = handle q $ showOutput = handle q $
@ -125,10 +125,10 @@ showEndFail = showEndResult False
showEndResult :: Bool -> Annex () showEndResult :: Bool -> Annex ()
showEndResult ok = handle (JSON.end ok) $ putStrLn msg showEndResult ok = handle (JSON.end ok) $ putStrLn msg
where where
msg msg
| ok = "ok" | ok = "ok"
| otherwise = "failed" | otherwise = "failed"
showErr :: (Show a) => a -> Annex () showErr :: (Show a) => a -> Annex ()
showErr e = warning' $ "git-annex: " ++ show e showErr e = warning' $ "git-annex: " ++ show e
@ -153,9 +153,9 @@ maybeShowJSON v = handle (JSON.add v) q
{- Shows a complete JSON value, only when in json mode. -} {- Shows a complete JSON value, only when in json mode. -}
showFullJSON :: JSON a => [(String, a)] -> Annex Bool showFullJSON :: JSON a => [(String, a)] -> Annex Bool
showFullJSON v = withOutputType $ liftIO . go showFullJSON v = withOutputType $ liftIO . go
where where
go JSONOutput = JSON.complete v >> return True go JSONOutput = JSON.complete v >> return True
go _ = return False go _ = return False
{- Performs an action that outputs nonstandard/customized output, and {- Performs an action that outputs nonstandard/customized output, and
- in JSON mode wraps its output in JSON.start and JSON.end, so it's - in JSON mode wraps its output in JSON.start and JSON.end, so it's
@ -184,10 +184,10 @@ setupConsole = do
handle :: IO () -> IO () -> Annex () handle :: IO () -> IO () -> Annex ()
handle json normal = withOutputType go handle json normal = withOutputType go
where where
go NormalOutput = liftIO normal go NormalOutput = liftIO normal
go QuietOutput = q go QuietOutput = q
go JSONOutput = liftIO $ flushed json go JSONOutput = liftIO $ flushed json
q :: Monad m => m () q :: Monad m => m ()
q = noop q = noop

View file

@ -23,30 +23,30 @@ usage header cmds commonoptions = unlines $
, "Commands:" , "Commands:"
, "" , ""
] ++ cmdlines ] ++ cmdlines
where where
-- To get consistent indentation of options, generate the -- To get consistent indentation of options, generate the
-- usage for all options at once. A command's options will -- usage for all options at once. A command's options will
-- be displayed after the command. -- be displayed after the command.
alloptlines = filter (not . null) $ alloptlines = filter (not . null) $
lines $ usageInfo "" $ lines $ usageInfo "" $
concatMap cmdoptions scmds ++ commonoptions concatMap cmdoptions scmds ++ commonoptions
(cmdlines, optlines) = go scmds alloptlines [] (cmdlines, optlines) = go scmds alloptlines []
go [] os ls = (ls, os) go [] os ls = (ls, os)
go (c:cs) os ls = go cs os' (ls++(l:o)) go (c:cs) os ls = go cs os' (ls++(l:o))
where where
(o, os') = splitAt (length $ cmdoptions c) os (o, os') = splitAt (length $ cmdoptions c) os
l = concat l = concat
[ cmdname c [ cmdname c
, namepad (cmdname c) , namepad (cmdname c)
, cmdparamdesc c , cmdparamdesc c
, descpad (cmdparamdesc c) , descpad (cmdparamdesc c)
, cmddesc c , cmddesc c
] ]
pad n s = replicate (n - length s) ' ' pad n s = replicate (n - length s) ' '
namepad = pad $ longest cmdname + 1 namepad = pad $ longest cmdname + 1
descpad = pad $ longest cmdparamdesc + 2 descpad = pad $ longest cmdparamdesc + 2
longest f = foldl max 0 $ map (length . f) cmds longest f = foldl max 0 $ map (length . f) cmds
scmds = sort cmds scmds = sort cmds
{- Descriptions of params used in usage messages. -} {- Descriptions of params used in usage messages. -}
paramPaths :: String paramPaths :: String