drop: Now supports --all, --unused, and --key.

This commit is contained in:
Joey Hess 2015-05-12 13:00:06 -04:00
parent cc5d0a3873
commit 4b2e3210ea
3 changed files with 34 additions and 9 deletions

View file

@ -27,7 +27,7 @@ cmd = [withOptions (dropOptions) $ command "drop" paramPaths seek
SectionCommon "indicate content of files not currently wanted"] SectionCommon "indicate content of files not currently wanted"]
dropOptions :: [Option] dropOptions :: [Option]
dropOptions = dropFromOption : annexedMatchingOptions ++ [autoOption] dropOptions = dropFromOption : annexedMatchingOptions ++ [autoOption] ++ keyOptions
dropFromOption :: Option dropFromOption :: Option
dropFromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote" dropFromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote"
@ -36,23 +36,32 @@ seek :: CommandSeek
seek ps = do seek ps = do
from <- getOptionField dropFromOption Remote.byNameWithUUID from <- getOptionField dropFromOption Remote.byNameWithUUID
auto <- getOptionFlag autoOption auto <- getOptionFlag autoOption
withFilesInGit (whenAnnexed $ start auto from) ps withKeyOptions auto
(startKeys auto from)
(withFilesInGit $ whenAnnexed $ start auto from)
ps
start :: Bool -> Maybe Remote -> FilePath -> Key -> CommandStart start :: Bool -> Maybe Remote -> FilePath -> Key -> CommandStart
start auto from file key = checkDropAuto auto from file key $ \numcopies -> start auto from file key = start' auto from key (Just file)
start' :: Bool -> Maybe Remote -> Key -> AssociatedFile -> CommandStart
start' auto from key afile = checkDropAuto auto from afile key $ \numcopies ->
stopUnless want $ stopUnless want $
case from of case from of
Nothing -> startLocal (Just file) numcopies key Nothing Nothing -> startLocal afile numcopies key Nothing
Just remote -> do Just remote -> do
u <- getUUID u <- getUUID
if Remote.uuid remote == u if Remote.uuid remote == u
then startLocal (Just file) numcopies key Nothing then startLocal afile numcopies key Nothing
else startRemote (Just file) numcopies key remote else startRemote afile numcopies key remote
where where
want want
| auto = wantDrop False (Remote.uuid <$> from) (Just key) (Just file) | auto = wantDrop False (Remote.uuid <$> from) (Just key) afile
| otherwise = return True | otherwise = return True
startKeys :: Bool -> Maybe Remote -> Key -> CommandStart
startKeys auto from key = start' auto from key Nothing
startLocal :: AssociatedFile -> NumCopies -> Key -> Maybe Remote -> CommandStart startLocal :: AssociatedFile -> NumCopies -> Key -> Maybe Remote -> CommandStart
startLocal afile numcopies key knownpresentremote = stopUnless (inAnnex key) $ do startLocal afile numcopies key knownpresentremote = stopUnless (inAnnex key) $ do
showStart' "drop" key afile showStart' "drop" key afile
@ -154,8 +163,8 @@ requiredContent = do
{- In auto mode, only runs the action if there are enough {- In auto mode, only runs the action if there are enough
- copies on other semitrusted repositories. -} - copies on other semitrusted repositories. -}
checkDropAuto :: Bool -> Maybe Remote -> FilePath -> Key -> (NumCopies -> CommandStart) -> CommandStart checkDropAuto :: Bool -> Maybe Remote -> AssociatedFile -> Key -> (NumCopies -> CommandStart) -> CommandStart
checkDropAuto auto mremote file key a = go =<< getFileNumCopies file checkDropAuto auto mremote afile key a = go =<< maybe getNumCopies getFileNumCopies afile
where where
go numcopies go numcopies
| auto = do | auto = do

1
debian/changelog vendored
View file

@ -2,6 +2,7 @@ git-annex (5.20150508.2) UNRELEASED; urgency=medium
* import: Refuse to import files that are within the work tree, as that * import: Refuse to import files that are within the work tree, as that
does not make sense and could cause data loss. does not make sense and could cause data loss.
* drop: Now supports --all, --unused, and --key.
-- Joey Hess <id@joeyh.name> Mon, 11 May 2015 12:45:06 -0400 -- Joey Hess <id@joeyh.name> Mon, 11 May 2015 12:45:06 -0400

View file

@ -35,6 +35,21 @@ safe to do so.
the last repository that is storing their content. Data loss can the last repository that is storing their content. Data loss can
result from using this option. result from using this option.
* `--all`
Rather than specifying a filename or path to drop, this option can be
used to drop all available versions of all files.
This is the default behavior when running git-annex drop in a bare repository.
* `--unused`
Drop files found by last run of git-annex unused.
* `--key=keyname`
Use this option to drop a specified key.
* file matching options * file matching options
The [[git-annex-matching-options]](1) The [[git-annex-matching-options]](1)