From 258a3356e6461e0164441bb3a3e202cb9ef889e6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Jul 2016 15:22:55 -0400 Subject: --branch, stage 2 Show branch:file that is being operated on. I had to make ActionItem a type and not a type class because withKeyOptions' passed two different types of values when using the type class, and I could not get the type checker to accept that. --- CmdLine/Seek.hs | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'CmdLine') diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs index e7c52b63f..56592349b 100644 --- a/CmdLine/Seek.hs +++ b/CmdLine/Seek.hs @@ -4,7 +4,7 @@ - the values a user passes to a command, and prepare actions operating - on them. - - - Copyright 2010-2015 Joey Hess + - Copyright 2010-2016 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -161,19 +161,29 @@ withNothing _ _ = error "This command takes no parameters." - - Otherwise falls back to a regular CommandSeek action on - whatever params were passed. -} -withKeyOptions :: Maybe KeyOptions -> Bool -> (Key -> CommandStart) -> (CmdParams -> CommandSeek) -> CmdParams -> CommandSeek +withKeyOptions + :: Maybe KeyOptions + -> Bool + -> (Key -> ActionItem -> CommandStart) + -> (CmdParams -> CommandSeek) + -> CmdParams + -> CommandSeek withKeyOptions ko auto keyaction = withKeyOptions' ko auto mkkeyaction where mkkeyaction = do matcher <- Limit.getMatcher - return $ \getkeys -> - seekActions $ map (process matcher) <$> getkeys - process matcher k = ifM (matcher $ MatchingKey k) - ( keyaction k - , return Nothing - ) - -withKeyOptions' :: Maybe KeyOptions -> Bool -> Annex (Annex [Key] -> Annex ()) -> (CmdParams -> CommandSeek) -> CmdParams -> CommandSeek + return $ \k i -> + whenM (matcher $ MatchingKey k) $ + commandAction $ keyaction k i + +withKeyOptions' + :: Maybe KeyOptions + -> Bool + -> Annex (Key -> ActionItem -> Annex ()) + -> (CmdParams + -> CommandSeek) + -> CmdParams + -> CommandSeek withKeyOptions' ko auto mkkeyaction fallbackaction params = do bare <- fromRepo Git.repoIsLocalBare when (auto && bare) $ @@ -194,15 +204,17 @@ withKeyOptions' ko auto mkkeyaction fallbackaction params = do | auto = error "Cannot use --auto with --all or --branch or --unused or --key or --incomplete" | otherwise = a incompletekeys = staleKeysPrune gitAnnexTmpObjectDir True - runkeyaction ks = do + runkeyaction getks = do keyaction <- mkkeyaction - keyaction ks + ks <- getks + forM_ ks $ \k -> keyaction k (mkActionItem k) runbranchkeys bs = do keyaction <- mkkeyaction forM_ bs $ \b -> do (l, cleanup) <- inRepo $ LsTree.lsTree b - forM_ l $ \i -> - maybe noop (\k -> keyaction (return [k])) + forM_ l $ \i -> do + let bfp = mkActionItem $ BranchFilePath b (LsTree.file i) + maybe noop (\k -> keyaction k bfp) =<< catKey (LsTree.sha i) unlessM (liftIO cleanup) $ error ("git ls-tree " ++ Git.fromRef b ++ " failed") -- cgit v1.2.3