diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-09 19:03:21 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-09 19:03:24 -0400 |
commit | ea0f914261e4747de75339952c2d47374c5a7803 (patch) | |
tree | 4af3a12da54d8f40878f1f8d563b8abbd5d0516f /Command | |
parent | 7a5aff2c121f4ecbc173e939b0cf7b2975d18438 (diff) |
wip
Current status:
* building again, but several commands are commented out
* still need to implement global options, file matching options, etc
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Drop.hs | 2 | ||||
-rw-r--r-- | Command/Sync.hs | 77 | ||||
-rw-r--r-- | Command/Unused.hs | 10 | ||||
-rw-r--r-- | Command/Whereis.hs | 8 |
4 files changed, 56 insertions, 41 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs index 1c595b6c2..7141cbc48 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -24,7 +24,7 @@ import qualified Data.Set as S cmd :: Command cmd = command "drop" SectionCommon - "indicate content of files not currently wanted" + "remove content of files from repository" paramPaths (seek <$$> optParser) data DropOptions = DropOptions diff --git a/Command/Sync.hs b/Command/Sync.hs index 2f7c4af7f..a5b601076 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -52,26 +52,32 @@ import Control.Concurrent.MVar import qualified Data.Map as M cmd :: Command -cmd = withOptions syncOptions $ - command "sync" SectionCommon - "synchronize local repository with remotes" - (paramRepeating paramRemote) (withParams seek) - -syncOptions :: [Option] -syncOptions = - [ contentOption - , messageOption - , allOption - ] - -contentOption :: Option -contentOption = flagOption [] "content" "also transfer file contents" - -messageOption :: Option -messageOption = fieldOption ['m'] "message" "MSG" "specify commit message" - -seek :: CmdParams -> CommandSeek -seek rs = do +cmd = command "sync" SectionCommon + "synchronize local repository with remotes" + (paramRepeating paramRemote) (seek <$$> optParser) + +data SyncOptions = SyncOptions + { syncWith :: CmdParams + , contentOption :: Bool + , messageOption :: Maybe String + , keyOptions :: Maybe KeyOptions + } + +optParser :: CmdParamsDesc -> Parser SyncOptions +optParser desc = SyncOptions + <$> cmdParams desc + <*> switch + ( long "content" + <> help "also transfer file contents" + ) + <*> optional (strOption + ( long "message" <> short 'm' <> metavar "MSG" + <> help "commit message" + )) + <*> optional parseAllOption + +seek :: SyncOptions -> CommandSeek +seek o = do prepMerge -- There may not be a branch checked out until after the commit, @@ -90,20 +96,20 @@ seek rs = do ) let withbranch a = a =<< getbranch - remotes <- syncRemotes rs + remotes <- syncRemotes (syncWith o) let gitremotes = filter Remote.gitSyncableRemote remotes let dataremotes = filter (not . remoteAnnexIgnore . Remote.gitconfig) remotes -- Syncing involves many actions, any of which can independently -- fail, without preventing the others from running. seekActions $ return $ concat - [ [ commit ] + [ [ commit o ] , [ withbranch mergeLocal ] , map (withbranch . pullRemote) gitremotes , [ mergeAnnex ] ] - whenM (Annex.getFlag $ optionName contentOption) $ - whenM (seekSyncContent dataremotes) $ + when (contentOption o) $ + whenM (seekSyncContent o dataremotes) $ -- Transferring content can take a while, -- and other changes can be pushed to the git-annex -- branch on the remotes in the meantime, so pull @@ -151,15 +157,14 @@ syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted ) fastest = fromMaybe [] . headMaybe . Remote.byCost -commit :: CommandStart -commit = ifM (annexAutoCommit <$> Annex.getGitConfig) +commit :: SyncOptions -> CommandStart +commit o = ifM (annexAutoCommit <$> Annex.getGitConfig) ( go , stop ) where go = next $ next $ do - commitmessage <- maybe commitMsg return - =<< Annex.getField (optionName messageOption) + commitmessage <- maybe commitMsg return (messageOption o) showStart "commit" "" Annex.Branch.commit "update" ifM isDirect @@ -372,14 +377,16 @@ newer remote b = do - - If any file movements were generated, returns true. -} -seekSyncContent :: [Remote] -> Annex Bool -seekSyncContent rs = do +seekSyncContent :: SyncOptions -> [Remote] -> Annex Bool +seekSyncContent o rs = do mvar <- liftIO newEmptyMVar - bloom <- ifM (Annex.getFlag "all") - ( Just <$> genBloomFilter (seekworktree mvar []) - , seekworktree mvar [] (const noop) >> pure Nothing - ) - withKeyOptions' False (seekkeys mvar bloom) (const noop) [] + bloom <- case keyOptions o of + Just WantAllKeys -> Just <$> genBloomFilter (seekworktree mvar []) + _ -> seekworktree mvar [] (const noop) >> pure Nothing + withKeyOptions' (keyOptions o) False + (seekkeys mvar bloom) + (const noop) + [] liftIO $ not <$> isEmptyMVar mvar where seekworktree mvar l bloomfeeder = seekHelper LsFiles.inRepo l >>= diff --git a/Command/Unused.hs b/Command/Unused.hs index e6d5f7c71..4649485c2 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -57,13 +57,13 @@ start = do !refspec <- maybe cfgrefspec (either error id . parseRefSpec) <$> Annex.getField (optionName refSpecOption) from <- Annex.getField (optionName unusedFromOption) - let (name, action) = case from of + let (name, perform) = case from of Nothing -> (".", checkUnused refspec) Just "." -> (".", checkUnused refspec) Just "here" -> (".", checkUnused refspec) Just n -> (n, checkRemoteUnused n refspec) showStart "unused" name - next action + next perform checkUnused :: RefSpec -> CommandPerform checkUnused refspec = chain 0 @@ -127,11 +127,11 @@ unusedMsg u = unusedMsg' u ["Some annexed data is no longer used by any files:"] [dropMsg Nothing] unusedMsg' :: [(Int, Key)] -> [String] -> [String] -> String -unusedMsg' u header trailer = unlines $ - header ++ +unusedMsg' u mheader mtrailer = unlines $ + mheader ++ table u ++ ["(To see where data was previously used, try: git log --stat -S'KEY')"] ++ - trailer + mtrailer remoteUnusedMsg :: Remote -> [(Int, Key)] -> String remoteUnusedMsg r u = unusedMsg' u diff --git a/Command/Whereis.hs b/Command/Whereis.hs index 05bc70654..fb28daa22 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -21,6 +21,14 @@ cmd = noCommit $ withOptions (jsonOption : annexedMatchingOptions ++ keyOptions) "lists repositories that have file content" paramPaths (withParams seek) +data WhereisOptions = WhereisOptions + { whereisFiles :: CmdParams + , jsonOption :: GlobalSetter + , keyOptions :: Maybe KeyOptions + } + +-- TODO: annexedMatchingOptions + seek :: CmdParams -> CommandSeek seek ps = do m <- remoteMap id |