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

View file

@ -35,6 +35,21 @@ safe to do so.
the last repository that is storing their content. Data loss can
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
The [[git-annex-matching-options]](1)