From 7036d0a4c1fe05c4833545f9eacfe697bfaf3cc6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 19 Oct 2020 15:36:18 -0400 Subject: [PATCH] add, import: Fix a reversion in 7.20191009 that broke handling of --largerthan and --smallerthan This commit was sponsored by Jochen Bartl on Patreon. --- Annex/FileMatcher.hs | 1 + CHANGELOG | 2 ++ CmdLine/GitAnnex/Options.hs | 14 +++++++------- Command/Add.hs | 9 ++++++++- Command/Import.hs | 12 +++++++++++- Limit.hs | 8 ++++---- doc/bugs/add_--largerthan_reversion.mdwn | 5 +---- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Annex/FileMatcher.hs b/Annex/FileMatcher.hs index e46b75da6a..9aa3ca18cf 100644 --- a/Annex/FileMatcher.hs +++ b/Annex/FileMatcher.hs @@ -25,6 +25,7 @@ module Annex.FileMatcher ( AddUnlockedMatcher, addUnlockedMatcher, checkAddUnlockedMatcher, + LimitBy(..), module Types.FileMatcher ) where diff --git a/CHANGELOG b/CHANGELOG index cdffcba3bf..70c4c406b4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ git-annex (8.20201008) UNRELEASED; urgency=medium * Fix build on Windows with network-3. * Fix a memory leak introduced in the last release. + * add, import: Fix a reversion in 7.20191009 that broke handling + of --largerthan and --smallerthan. -- Joey Hess Thu, 08 Oct 2020 10:48:17 -0400 diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 22f07045ce..87660e50b6 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -223,7 +223,7 @@ parseKey = maybe (Fail.fail "invalid key") return . deserializeKey annexedMatchingOptions :: [GlobalOption] annexedMatchingOptions = concat [ keyMatchingOptions' - , fileMatchingOptions' + , fileMatchingOptions' Limit.LimitAnnexFiles , combiningOptions , timeLimitOption ] @@ -315,11 +315,11 @@ keyMatchingOptions' = ] -- Options to match files which may not yet be annexed. -fileMatchingOptions :: [GlobalOption] -fileMatchingOptions = fileMatchingOptions' ++ combiningOptions ++ timeLimitOption +fileMatchingOptions :: Limit.LimitBy -> [GlobalOption] +fileMatchingOptions lb = fileMatchingOptions' lb ++ combiningOptions ++ timeLimitOption -fileMatchingOptions' :: [GlobalOption] -fileMatchingOptions' = +fileMatchingOptions' :: Limit.LimitBy -> [GlobalOption] +fileMatchingOptions' lb = [ globalSetter Limit.addExclude $ strOption ( long "exclude" <> short 'x' <> metavar paramGlob <> help "skip files matching the glob pattern" @@ -330,12 +330,12 @@ fileMatchingOptions' = <> help "limit to files matching the glob pattern" <> hidden ) - , globalSetter Limit.addLargerThan $ strOption + , globalSetter (Limit.addLargerThan lb) $ strOption ( long "largerthan" <> metavar paramSize <> help "match files larger than a size" <> hidden ) - , globalSetter Limit.addSmallerThan $ strOption + , globalSetter (Limit.addSmallerThan lb) $ strOption ( long "smallerthan" <> metavar paramSize <> help "match files smaller than a size" <> hidden diff --git a/Command/Add.hs b/Command/Add.hs index b19aaea54a..6aecce8d0c 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -29,9 +29,16 @@ import qualified Utility.RawFilePath as R cmd :: Command cmd = notBareRepo $ - withGlobalOptions [jobsOption, jsonOptions, jsonProgressOption, fileMatchingOptions] $ + withGlobalOptions opts $ command "add" SectionCommon "add files to annex" paramPaths (seek <$$> optParser) + where + opts = + [ jobsOption + , jsonOptions + , jsonProgressOption + , fileMatchingOptions LimitDiskFiles + ] data AddOptions = AddOptions { addThese :: CmdParams diff --git a/Command/Import.hs b/Command/Import.hs index 98bc94cf2c..18f75432e7 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -39,11 +39,21 @@ import Control.Concurrent.STM cmd :: Command cmd = notBareRepo $ - withGlobalOptions [jobsOption, jsonOptions, jsonProgressOption, fileMatchingOptions] $ + withGlobalOptions opts $ command "import" SectionCommon "add a tree of files to the repository" (paramPaths ++ "|BRANCH[:SUBDIR]") (seek <$$> optParser) + where + opts = + [ jobsOption + , jsonOptions + , jsonProgressOption + -- These options are only used when importing from a + -- directory, not from a special remote. So it's ok + -- to use LimitDiskFiles. + , fileMatchingOptions LimitDiskFiles + ] data ImportOptions = LocalImportOptions diff --git a/Limit.hs b/Limit.hs index 8f958efd66..9caeb44e02 100644 --- a/Limit.hs +++ b/Limit.hs @@ -441,11 +441,11 @@ limitSecureHash = MatchFiles } {- Adds a limit to skip files that are too large or too small -} -addLargerThan :: String -> Annex () -addLargerThan = addLimit . limitSize LimitAnnexFiles (>) +addLargerThan :: LimitBy -> String -> Annex () +addLargerThan lb = addLimit . limitSize lb (>) -addSmallerThan :: String -> Annex () -addSmallerThan = addLimit . limitSize LimitAnnexFiles (<) +addSmallerThan :: LimitBy -> String -> Annex () +addSmallerThan lb = addLimit . limitSize lb (<) limitSize :: LimitBy -> (Maybe Integer -> Maybe Integer -> Bool) -> MkLimit Annex limitSize lb vs s = case readSize dataUnits s of diff --git a/doc/bugs/add_--largerthan_reversion.mdwn b/doc/bugs/add_--largerthan_reversion.mdwn index 850efdfbe1..c94205688f 100644 --- a/doc/bugs/add_--largerthan_reversion.mdwn +++ b/doc/bugs/add_--largerthan_reversion.mdwn @@ -14,7 +14,4 @@ That commit was otherwise right, eg `git-annex get --largerthan` should look at the size of the annexed file, not of the file on disk, which could be a small pointer file. -Rather than being global options, --largerthan and --smallerthan, -could added by each command, so the command can specify how the size -should be determined. Finding a way to do that w/o needing to add -boilerplate to many commands would be best. +> [[fixed|done]] --[[Joey]]