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.
This commit is contained in:
Joey Hess 2012-10-08 15:34:44 -04:00
parent e375b931c0
commit 17543f6e80
3 changed files with 24 additions and 17 deletions

View file

@ -21,7 +21,7 @@ module Command (
isBareRepo,
numCopies,
autoCopies,
autoCopiesDrop,
autoCopiesWith,
module ReExported
) where
@ -40,7 +40,6 @@ import Config
import Annex.CheckAttr
import Logs.PreferredContent
import Git.FilePath
import Annex.UUID
import qualified Data.Set as S
@ -135,13 +134,8 @@ autoCopies file key vs a = Annex.getState Annex.auto >>= go
( a, stop )
else stop
{- For dropping, supplies the number of known copies to the action.
-
- In auto mode, checks the number of known copies.
- Also, checks if the repo would prefer to retain the content.
-}
autoCopiesDrop :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
autoCopiesDrop file key vs a = do
autoCopiesWith :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
autoCopiesWith file key vs a = do
numcopiesattr <- numCopies file
Annex.getState Annex.auto >>= auto numcopiesattr
where
@ -150,9 +144,5 @@ autoCopiesDrop file key vs a = do
needed <- getNumCopies numcopiesattr
(_, have) <- trustPartition UnTrusted =<< Remote.keyLocations key
if length have `vs` needed
then do
fp <- inRepo $ toTopFilePath file
u <- getUUID
ifM (isPreferredContent (Just u) (S.singleton u) fp)
( stop, a numcopiesattr )
then a numcopiesattr
else stop

View file

@ -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

4
debian/changelog vendored
View file

@ -10,8 +10,8 @@ git-annex (3.20121002) UNRELEASED; urgency=low
* Added preferred content expressions, configurable using vicfg.
* get --auto, copy --auto: If the local repository has preferred content
configured, only get that content.
* drop --auto: If the local repository has preferred content configured,
drop content that is not preferred, when numcopies allows.
* drop --auto: If the repository the content is dropped from has
preferred content configured, drop only content that is not preferred.
* --copies=group:number can now be used to match files that are present
in a specified number of repositories in a group.
* Added --smallerthan, --largerthan, and --inall limits.