diff options
author | Joey Hess <joey@kitenet.net> | 2012-10-08 15:34:44 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-10-08 15:34:44 -0400 |
commit | 98612f75ffee93be2973fd444948314dd1b7f822 (patch) | |
tree | dc1a11d66122fb5f9f36ce6d3654d28168e0e196 /Command/Drop.hs | |
parent | c452c70ef88197b152c1552563daa6a79e88e91f (diff) |
drop --auto --from with preferred content
With --from, it needs to examine the preferred content of the repository
being dropped from, instead of the local repository.
Diffstat (limited to 'Command/Drop.hs')
-rw-r--r-- | Command/Drop.hs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs index 440526347..9640d2804 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -17,6 +17,10 @@ import Logs.Trust import Annex.Content import Config import qualified Option +import Git.FilePath +import Logs.PreferredContent + +import qualified Data.Set as S def :: [Command] def = [withOptions [fromOption] $ command "drop" paramPaths seek @@ -30,7 +34,7 @@ seek = [withField fromOption Remote.byName $ \from -> withFilesInGit $ whenAnnexed $ start from] start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart -start from file (key, _) = autoCopiesDrop file key (>) $ \numcopies -> +start from file (key, _) = shouldDrop $ \numcopies -> case from of Nothing -> startLocal file numcopies key Just remote -> do @@ -38,6 +42,19 @@ start from file (key, _) = autoCopiesDrop file key (>) $ \numcopies -> if Remote.uuid remote == u then startLocal file numcopies key else startRemote file numcopies key remote + where + {- In --auto mode, drop if there are enough copies, + - and the repository being dropped from doesn't prefer + - to keep the content. -} + shouldDrop a = autoCopiesWith file key (>) $ \numcopies -> + ifM (Annex.getState Annex.auto) + ( do + fp <- inRepo $ toTopFilePath file + u <- maybe getUUID (return . Remote.uuid) from + ifM (isPreferredContent (Just u) (S.singleton u) fp) + ( a numcopies, stop ) + , a numcopies + ) startLocal :: FilePath -> Maybe Int -> Key -> CommandStart startLocal file numcopies key = stopUnless (inAnnex key) $ do |