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:
parent
e375b931c0
commit
17543f6e80
3 changed files with 24 additions and 17 deletions
18
Command.hs
18
Command.hs
|
@ -21,7 +21,7 @@ module Command (
|
||||||
isBareRepo,
|
isBareRepo,
|
||||||
numCopies,
|
numCopies,
|
||||||
autoCopies,
|
autoCopies,
|
||||||
autoCopiesDrop,
|
autoCopiesWith,
|
||||||
module ReExported
|
module ReExported
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ import Config
|
||||||
import Annex.CheckAttr
|
import Annex.CheckAttr
|
||||||
import Logs.PreferredContent
|
import Logs.PreferredContent
|
||||||
import Git.FilePath
|
import Git.FilePath
|
||||||
import Annex.UUID
|
|
||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
|
@ -135,13 +134,8 @@ autoCopies file key vs a = Annex.getState Annex.auto >>= go
|
||||||
( a, stop )
|
( a, stop )
|
||||||
else stop
|
else stop
|
||||||
|
|
||||||
{- For dropping, supplies the number of known copies to the action.
|
autoCopiesWith :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
|
||||||
-
|
autoCopiesWith file key vs a = do
|
||||||
- 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
|
|
||||||
numcopiesattr <- numCopies file
|
numcopiesattr <- numCopies file
|
||||||
Annex.getState Annex.auto >>= auto numcopiesattr
|
Annex.getState Annex.auto >>= auto numcopiesattr
|
||||||
where
|
where
|
||||||
|
@ -150,9 +144,5 @@ autoCopiesDrop file key vs a = do
|
||||||
needed <- getNumCopies numcopiesattr
|
needed <- getNumCopies numcopiesattr
|
||||||
(_, have) <- trustPartition UnTrusted =<< Remote.keyLocations key
|
(_, have) <- trustPartition UnTrusted =<< Remote.keyLocations key
|
||||||
if length have `vs` needed
|
if length have `vs` needed
|
||||||
then do
|
then a numcopiesattr
|
||||||
fp <- inRepo $ toTopFilePath file
|
|
||||||
u <- getUUID
|
|
||||||
ifM (isPreferredContent (Just u) (S.singleton u) fp)
|
|
||||||
( stop, a numcopiesattr )
|
|
||||||
else stop
|
else stop
|
||||||
|
|
|
@ -17,6 +17,10 @@ import Logs.Trust
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import Config
|
import Config
|
||||||
import qualified Option
|
import qualified Option
|
||||||
|
import Git.FilePath
|
||||||
|
import Logs.PreferredContent
|
||||||
|
|
||||||
|
import qualified Data.Set as S
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions [fromOption] $ command "drop" paramPaths seek
|
def = [withOptions [fromOption] $ command "drop" paramPaths seek
|
||||||
|
@ -30,7 +34,7 @@ seek = [withField fromOption Remote.byName $ \from ->
|
||||||
withFilesInGit $ whenAnnexed $ start from]
|
withFilesInGit $ whenAnnexed $ start from]
|
||||||
|
|
||||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||||
start from file (key, _) = autoCopiesDrop file key (>) $ \numcopies ->
|
start from file (key, _) = shouldDrop $ \numcopies ->
|
||||||
case from of
|
case from of
|
||||||
Nothing -> startLocal file numcopies key
|
Nothing -> startLocal file numcopies key
|
||||||
Just remote -> do
|
Just remote -> do
|
||||||
|
@ -38,6 +42,19 @@ start from file (key, _) = autoCopiesDrop file key (>) $ \numcopies ->
|
||||||
if Remote.uuid remote == u
|
if Remote.uuid remote == u
|
||||||
then startLocal file numcopies key
|
then startLocal file numcopies key
|
||||||
else startRemote file numcopies key remote
|
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 :: FilePath -> Maybe Int -> Key -> CommandStart
|
||||||
startLocal file numcopies key = stopUnless (inAnnex key) $ do
|
startLocal file numcopies key = stopUnless (inAnnex key) $ do
|
||||||
|
|
4
debian/changelog
vendored
4
debian/changelog
vendored
|
@ -10,8 +10,8 @@ git-annex (3.20121002) UNRELEASED; urgency=low
|
||||||
* Added preferred content expressions, configurable using vicfg.
|
* Added preferred content expressions, configurable using vicfg.
|
||||||
* get --auto, copy --auto: If the local repository has preferred content
|
* get --auto, copy --auto: If the local repository has preferred content
|
||||||
configured, only get that content.
|
configured, only get that content.
|
||||||
* drop --auto: If the local repository has preferred content configured,
|
* drop --auto: If the repository the content is dropped from has
|
||||||
drop content that is not preferred, when numcopies allows.
|
preferred content configured, drop only content that is not preferred.
|
||||||
* --copies=group:number can now be used to match files that are present
|
* --copies=group:number can now be used to match files that are present
|
||||||
in a specified number of repositories in a group.
|
in a specified number of repositories in a group.
|
||||||
* Added --smallerthan, --largerthan, and --inall limits.
|
* Added --smallerthan, --largerthan, and --inall limits.
|
||||||
|
|
Loading…
Reference in a new issue