2013-03-29 20:17:13 +00:00
|
|
|
{- git-annex file matching
|
|
|
|
-
|
2019-05-14 18:01:09 +00:00
|
|
|
- Copyright 2012-2019 Joey Hess <id@joeyh.name>
|
2013-03-29 20:17:13 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-03-29 20:17:13 +00:00
|
|
|
-}
|
|
|
|
|
2016-02-03 20:29:34 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2016-02-03 18:56:34 +00:00
|
|
|
module Annex.FileMatcher (
|
|
|
|
GetFileMatcher,
|
|
|
|
checkFileMatcher,
|
2018-08-27 18:47:17 +00:00
|
|
|
checkFileMatcher',
|
2016-02-03 18:56:34 +00:00
|
|
|
checkMatcher,
|
2019-05-20 15:54:55 +00:00
|
|
|
checkMatcher',
|
2016-02-03 18:56:34 +00:00
|
|
|
matchAll,
|
2019-05-14 18:01:09 +00:00
|
|
|
PreferredContentData(..),
|
|
|
|
preferredContentTokens,
|
|
|
|
preferredContentKeylessTokens,
|
2016-02-03 18:56:34 +00:00
|
|
|
preferredContentParser,
|
2019-05-14 18:01:09 +00:00
|
|
|
ParseToken,
|
2016-02-03 18:56:34 +00:00
|
|
|
parsedToMatcher,
|
2019-12-20 19:01:34 +00:00
|
|
|
mkMatchExpressionParser,
|
2016-02-03 18:56:34 +00:00
|
|
|
largeFilesMatcher,
|
2019-12-20 19:01:34 +00:00
|
|
|
AddUnlockedMatcher,
|
|
|
|
addUnlockedMatcher,
|
|
|
|
checkAddUnlockedMatcher,
|
|
|
|
module Types.FileMatcher
|
2016-02-03 18:56:34 +00:00
|
|
|
) where
|
2013-03-29 20:17:13 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2013-03-29 20:17:13 +00:00
|
|
|
import Limit
|
|
|
|
import Utility.Matcher
|
|
|
|
import Types.Group
|
2013-05-25 03:07:26 +00:00
|
|
|
import Types.FileMatcher
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
import Types.GitConfig
|
|
|
|
import Config.GitConfig
|
2020-01-15 15:22:36 +00:00
|
|
|
import Annex.SpecialRemote.Config (preferreddirField)
|
2013-03-29 20:17:13 +00:00
|
|
|
import Git.FilePath
|
2013-04-26 03:44:55 +00:00
|
|
|
import Types.Remote (RemoteConfig)
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2016-02-02 19:18:17 +00:00
|
|
|
import Annex.CheckAttr
|
|
|
|
import Git.CheckAttr (unspecifiedAttr)
|
2019-12-20 19:01:34 +00:00
|
|
|
import qualified Git.Config
|
2019-08-08 16:18:53 +00:00
|
|
|
#ifdef WITH_MAGICMIME
|
|
|
|
import Annex.Magic
|
|
|
|
#endif
|
2013-03-29 20:17:13 +00:00
|
|
|
|
|
|
|
import Data.Either
|
|
|
|
import qualified Data.Set as S
|
|
|
|
|
2016-02-02 19:18:17 +00:00
|
|
|
type GetFileMatcher = FilePath -> Annex (FileMatcher Annex)
|
|
|
|
|
|
|
|
checkFileMatcher :: GetFileMatcher -> FilePath -> Annex Bool
|
2018-08-27 18:47:17 +00:00
|
|
|
checkFileMatcher getmatcher file = checkFileMatcher' getmatcher file (return True)
|
|
|
|
|
|
|
|
-- | Allows running an action when no matcher is configured for the file.
|
|
|
|
checkFileMatcher' :: GetFileMatcher -> FilePath -> Annex Bool -> Annex Bool
|
|
|
|
checkFileMatcher' getmatcher file notconfigured = do
|
2016-02-02 19:18:17 +00:00
|
|
|
matcher <- getmatcher file
|
2018-08-27 18:47:17 +00:00
|
|
|
checkMatcher matcher Nothing afile S.empty notconfigured d
|
|
|
|
where
|
2019-11-26 19:27:22 +00:00
|
|
|
afile = AssociatedFile (Just (toRawFilePath file))
|
2018-08-27 18:47:17 +00:00
|
|
|
-- checkMatcher will never use this, because afile is provided.
|
|
|
|
d = return True
|
2013-03-29 20:17:13 +00:00
|
|
|
|
2018-08-27 18:47:17 +00:00
|
|
|
checkMatcher :: FileMatcher Annex -> Maybe Key -> AssociatedFile -> AssumeNotPresent -> Annex Bool -> Annex Bool -> Annex Bool
|
|
|
|
checkMatcher matcher mkey afile notpresent notconfigured d
|
|
|
|
| isEmpty matcher = notconfigured
|
2014-01-23 20:37:08 +00:00
|
|
|
| otherwise = case (mkey, afile) of
|
2019-12-09 17:49:05 +00:00
|
|
|
(_, AssociatedFile (Just file)) -> go =<< fileMatchInfo file
|
support findred and --branch with file matching options
* findref: Support file matching options: --include, --exclude,
--want-get, --want-drop, --largerthan, --smallerthan, --accessedwithin
* Commands supporting --branch now apply file matching options --include,
--exclude, --want-get, --want-drop to filenames from the branch.
Previously, combining --branch with those would fail to match anything.
* add, import, findref: Support --time-limit.
This commit was sponsored by Jake Vosloo on Patreon.
2018-12-09 17:38:35 +00:00
|
|
|
(Just key, _) -> go (MatchingKey key afile)
|
2018-08-27 18:47:17 +00:00
|
|
|
_ -> d
|
2014-01-23 20:37:08 +00:00
|
|
|
where
|
2019-05-20 15:54:55 +00:00
|
|
|
go mi = checkMatcher' matcher mi notpresent
|
|
|
|
|
|
|
|
checkMatcher' :: FileMatcher Annex -> MatchInfo -> AssumeNotPresent -> Annex Bool
|
|
|
|
checkMatcher' matcher mi notpresent =
|
|
|
|
matchMrun matcher $ \a -> a notpresent mi
|
2014-01-23 20:37:08 +00:00
|
|
|
|
2019-12-09 17:49:05 +00:00
|
|
|
fileMatchInfo :: RawFilePath -> Annex MatchInfo
|
2014-01-23 20:37:08 +00:00
|
|
|
fileMatchInfo file = do
|
|
|
|
matchfile <- getTopFilePath <$> inRepo (toTopFilePath file)
|
2014-02-11 04:39:50 +00:00
|
|
|
return $ MatchingFile FileInfo
|
2014-01-23 20:37:08 +00:00
|
|
|
{ matchFile = matchfile
|
2015-02-06 20:03:02 +00:00
|
|
|
, currFile = file
|
2014-01-23 20:37:08 +00:00
|
|
|
}
|
2013-03-29 20:17:13 +00:00
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
matchAll :: FileMatcher Annex
|
2013-03-29 20:17:13 +00:00
|
|
|
matchAll = generate []
|
|
|
|
|
2019-05-14 16:44:50 +00:00
|
|
|
parsedToMatcher :: [ParseResult (MatchFiles Annex)] -> Either String (FileMatcher Annex)
|
2013-03-29 20:17:13 +00:00
|
|
|
parsedToMatcher parsed = case partitionEithers parsed of
|
|
|
|
([], vs) -> Right $ generate vs
|
|
|
|
(es, _) -> Left $ unwords $ map ("Parse failure: " ++) es
|
|
|
|
|
2019-05-14 16:44:50 +00:00
|
|
|
data ParseToken t
|
|
|
|
= SimpleToken String (ParseResult t)
|
|
|
|
| ValueToken String (String -> ParseResult t)
|
2013-04-26 03:44:55 +00:00
|
|
|
|
2019-05-14 16:44:50 +00:00
|
|
|
type ParseResult t = Either String (Token t)
|
2016-02-03 18:56:34 +00:00
|
|
|
|
2019-05-14 16:44:50 +00:00
|
|
|
parseToken :: [ParseToken t] -> String -> ParseResult t
|
2019-05-14 17:08:51 +00:00
|
|
|
parseToken l t = case syntaxToken t of
|
|
|
|
Right st -> Right st
|
|
|
|
Left _ -> go l
|
2013-03-29 20:17:13 +00:00
|
|
|
where
|
2016-02-03 18:56:34 +00:00
|
|
|
go [] = Left $ "near " ++ show t
|
|
|
|
go (SimpleToken s r : _) | s == t = r
|
|
|
|
go (ValueToken s mkr : _) | s == k = mkr v
|
|
|
|
go (_ : ps) = go ps
|
2013-03-29 20:17:13 +00:00
|
|
|
(k, v) = separate (== '=') t
|
2016-02-03 18:56:34 +00:00
|
|
|
|
2013-03-29 20:17:13 +00:00
|
|
|
{- This is really dumb tokenization; there's no support for quoted values.
|
|
|
|
- Open and close parens are always treated as standalone tokens;
|
|
|
|
- otherwise tokens must be separated by whitespace. -}
|
|
|
|
tokenizeMatcher :: String -> [String]
|
2019-05-14 17:01:50 +00:00
|
|
|
tokenizeMatcher = filter (not . null) . concatMap splitparens . words
|
2013-03-29 20:17:13 +00:00
|
|
|
where
|
|
|
|
splitparens = segmentDelim (`elem` "()")
|
|
|
|
|
2019-09-30 21:12:47 +00:00
|
|
|
commonKeylessTokens :: LimitBy -> [ParseToken (MatchFiles Annex)]
|
|
|
|
commonKeylessTokens lb =
|
2019-05-14 18:01:09 +00:00
|
|
|
[ SimpleToken "anything" (simply limitAnything)
|
|
|
|
, SimpleToken "nothing" (simply limitNothing)
|
|
|
|
, ValueToken "include" (usev limitInclude)
|
|
|
|
, ValueToken "exclude" (usev limitExclude)
|
2019-09-30 21:12:47 +00:00
|
|
|
, ValueToken "largerthan" (usev $ limitSize lb (>))
|
|
|
|
, ValueToken "smallerthan" (usev $ limitSize lb (<))
|
2019-05-14 18:01:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
commonKeyedTokens :: [ParseToken (MatchFiles Annex)]
|
|
|
|
commonKeyedTokens =
|
|
|
|
[ SimpleToken "unused" (simply limitUnused)
|
|
|
|
]
|
|
|
|
|
|
|
|
data PreferredContentData = PCD
|
2019-05-14 18:59:03 +00:00
|
|
|
{ matchStandard :: Either String (FileMatcher Annex)
|
|
|
|
, matchGroupWanted :: Either String (FileMatcher Annex)
|
2019-05-14 18:01:09 +00:00
|
|
|
, getGroupMap :: Annex GroupMap
|
|
|
|
, configMap :: M.Map UUID RemoteConfig
|
|
|
|
, repoUUID :: Maybe UUID
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Tokens of preferred content expressions that do not need a Key to be
|
|
|
|
-- known.
|
|
|
|
--
|
|
|
|
-- When importing from a special remote, this is used to match
|
|
|
|
-- some preferred content expressions before the content is downloaded,
|
|
|
|
-- so the Key is not known.
|
|
|
|
preferredContentKeylessTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
|
|
|
preferredContentKeylessTokens pcd =
|
2019-05-14 18:59:03 +00:00
|
|
|
[ SimpleToken "standard" (call $ matchStandard pcd)
|
|
|
|
, SimpleToken "groupwanted" (call $ matchGroupWanted pcd)
|
|
|
|
, SimpleToken "inpreferreddir" (simply $ limitInDir preferreddir)
|
2019-09-30 21:12:47 +00:00
|
|
|
] ++ commonKeylessTokens LimitAnnexFiles
|
2016-02-03 18:56:34 +00:00
|
|
|
where
|
2020-01-10 18:10:20 +00:00
|
|
|
preferreddir = maybe "public" fromProposedAccepted $
|
2020-01-15 15:22:36 +00:00
|
|
|
M.lookup preferreddirField =<< (`M.lookup` configMap pcd) =<< repoUUID pcd
|
2019-05-14 18:01:09 +00:00
|
|
|
|
|
|
|
preferredContentKeyedTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
|
|
|
preferredContentKeyedTokens pcd =
|
2019-05-14 18:59:03 +00:00
|
|
|
[ SimpleToken "present" (simply $ limitPresent $ repoUUID pcd)
|
2019-05-14 18:01:09 +00:00
|
|
|
, SimpleToken "securehash" (simply limitSecureHash)
|
|
|
|
, ValueToken "copies" (usev limitCopies)
|
|
|
|
, ValueToken "lackingcopies" (usev $ limitLackingCopies False)
|
|
|
|
, ValueToken "approxlackingcopies" (usev $ limitLackingCopies True)
|
|
|
|
, ValueToken "inbacked" (usev limitInBackend)
|
|
|
|
, ValueToken "metadata" (usev limitMetaData)
|
|
|
|
, ValueToken "inallgroup" (usev $ limitInAllGroup $ getGroupMap pcd)
|
|
|
|
] ++ commonKeyedTokens
|
|
|
|
|
|
|
|
preferredContentTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
|
|
|
preferredContentTokens pcd = concat
|
|
|
|
[ preferredContentKeylessTokens pcd
|
|
|
|
, preferredContentKeyedTokens pcd
|
|
|
|
]
|
|
|
|
|
|
|
|
preferredContentParser :: [ParseToken (MatchFiles Annex)] -> String -> [ParseResult (MatchFiles Annex)]
|
|
|
|
preferredContentParser tokens = map (parseToken tokens) . tokenizeMatcher
|
2016-02-03 18:56:34 +00:00
|
|
|
|
2019-12-20 19:01:34 +00:00
|
|
|
mkMatchExpressionParser :: Annex (String -> [ParseResult (MatchFiles Annex)])
|
|
|
|
mkMatchExpressionParser = do
|
2016-02-03 20:29:34 +00:00
|
|
|
#ifdef WITH_MAGICMIME
|
2019-07-22 15:03:26 +00:00
|
|
|
magicmime <- liftIO initMagicMime
|
2019-04-30 15:58:06 +00:00
|
|
|
let mimer n f = ValueToken n (usev $ f magicmime)
|
2016-02-03 20:29:34 +00:00
|
|
|
#else
|
2019-05-03 15:30:20 +00:00
|
|
|
let mimer n = ValueToken n $
|
|
|
|
const $ Left $ "\""++n++"\" not supported; not built with MagicMime support"
|
2019-04-30 15:58:06 +00:00
|
|
|
#endif
|
2019-09-30 21:12:47 +00:00
|
|
|
let parse = parseToken $
|
|
|
|
commonKeyedTokens ++
|
|
|
|
commonKeylessTokens LimitDiskFiles ++
|
2019-04-30 15:58:06 +00:00
|
|
|
#ifdef WITH_MAGICMIME
|
|
|
|
[ mimer "mimetype" $
|
|
|
|
matchMagic "mimetype" getMagicMimeType providedMimeType
|
|
|
|
, mimer "mimeencoding" $
|
|
|
|
matchMagic "mimeencoding" getMagicMimeEncoding providedMimeEncoding
|
|
|
|
]
|
|
|
|
#else
|
|
|
|
[ mimer "mimetype"
|
|
|
|
, mimer "mimeencoding"
|
|
|
|
]
|
2016-02-03 20:29:34 +00:00
|
|
|
#endif
|
|
|
|
return $ map parse . tokenizeMatcher
|
2016-02-03 18:56:34 +00:00
|
|
|
|
2013-03-29 20:17:13 +00:00
|
|
|
{- Generates a matcher for files large enough (or meeting other criteria)
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
- to be added to the annex, rather than directly to git.
|
|
|
|
-
|
|
|
|
- annex.largefiles is configured in git config, or git attributes,
|
|
|
|
- or global git-annex config, in that order.
|
|
|
|
-}
|
2016-02-02 19:18:17 +00:00
|
|
|
largeFilesMatcher :: Annex GetFileMatcher
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
largeFilesMatcher = go =<< getGitConfigVal' annexLargeFiles
|
2013-03-29 20:17:13 +00:00
|
|
|
where
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
go (HasGitConfig (Just expr)) = do
|
2019-12-20 17:07:10 +00:00
|
|
|
matcher <- mkmatcher expr "git config"
|
2016-02-02 19:18:17 +00:00
|
|
|
return $ const $ return matcher
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
go v = return $ \file -> do
|
2016-02-02 19:18:17 +00:00
|
|
|
expr <- checkAttr "annex.largefiles" file
|
|
|
|
if null expr || expr == unspecifiedAttr
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
then case v of
|
|
|
|
HasGlobalConfig (Just expr') ->
|
2019-12-20 17:07:10 +00:00
|
|
|
mkmatcher expr' "git-annex config"
|
git-annex config annex.largefiles
annex.largefiles can be configured by git-annex config, to more easily set
a default that will also be used by clones, without needing to shoehorn the
expression into the gitattributes file. The git config and gitattributes
override that.
Whenever something is added to git-annex config, we have to consider what
happens if a user puts a purposfully bad value in there. Or, if a new
git-annex adds some new value that an old git-annex can't parse.
In this case, a global annex.largefiles that can't be parsed currently
makes an error be thrown. That might not be ideal, but the gitattribute
behaves the same, and is almost equally repo-global.
Performance notes:
git-annex add and addurl construct a matcher once
and uses it for every file, so the added time penalty for reading the global
config log is minor. If the gitattributes annex.largefiles were deprecated,
git-annex add would get around 2% faster (excluding hashing), because
looking that up for each file is not fast. So this new way of setting
it is progress toward speeding up add.
git-annex smudge does need to load the log every time. As well as checking
the git attribute. Not ideal. Setting annex.gitaddtoannex=false avoids
both overheads.
2019-12-20 16:12:31 +00:00
|
|
|
_ -> return matchAll
|
2019-12-20 17:07:10 +00:00
|
|
|
else mkmatcher expr "gitattributes"
|
2016-02-02 19:18:17 +00:00
|
|
|
|
2019-12-20 17:07:10 +00:00
|
|
|
mkmatcher expr cfgfrom = do
|
2019-12-20 19:01:34 +00:00
|
|
|
parser <- mkMatchExpressionParser
|
2019-12-20 17:07:10 +00:00
|
|
|
either (badexpr cfgfrom) return $ parsedToMatcher $ parser expr
|
|
|
|
badexpr cfgfrom e = giveup $ "bad annex.largefiles configuration in " ++ cfgfrom ++ ": " ++ e
|
2016-02-03 18:56:34 +00:00
|
|
|
|
2019-12-20 19:01:34 +00:00
|
|
|
newtype AddUnlockedMatcher = AddUnlockedMatcher (FileMatcher Annex)
|
|
|
|
|
|
|
|
addUnlockedMatcher :: Annex AddUnlockedMatcher
|
|
|
|
addUnlockedMatcher = AddUnlockedMatcher <$>
|
|
|
|
(go =<< getGitConfigVal' annexAddUnlocked)
|
|
|
|
where
|
|
|
|
go (HasGitConfig (Just expr)) = mkmatcher expr "git config"
|
|
|
|
go (HasGlobalConfig (Just expr)) = mkmatcher expr "git annex config"
|
|
|
|
go _ = matchalways False
|
|
|
|
|
|
|
|
mkmatcher :: String -> String -> Annex (FileMatcher Annex)
|
|
|
|
mkmatcher expr cfgfrom = case Git.Config.isTrueFalse expr of
|
|
|
|
Just b -> matchalways b
|
|
|
|
Nothing -> do
|
|
|
|
parser <- mkMatchExpressionParser
|
|
|
|
either (badexpr cfgfrom) return $ parsedToMatcher $ parser expr
|
|
|
|
badexpr cfgfrom e = giveup $ "bad annex.addunlocked configuration in " ++ cfgfrom ++ ": " ++ e
|
|
|
|
|
|
|
|
matchalways True = return $ MOp limitAnything
|
|
|
|
matchalways False = return $ MOp limitNothing
|
|
|
|
|
|
|
|
checkAddUnlockedMatcher :: AddUnlockedMatcher -> MatchInfo -> Annex Bool
|
|
|
|
checkAddUnlockedMatcher (AddUnlockedMatcher matcher) mi =
|
|
|
|
checkMatcher' matcher mi S.empty
|
|
|
|
|
2019-05-14 16:44:50 +00:00
|
|
|
simply :: MatchFiles Annex -> ParseResult (MatchFiles Annex)
|
2016-02-03 18:56:34 +00:00
|
|
|
simply = Right . Operation
|
|
|
|
|
2019-05-14 16:44:50 +00:00
|
|
|
usev :: MkLimit Annex -> String -> ParseResult (MatchFiles Annex)
|
2016-02-03 18:56:34 +00:00
|
|
|
usev a v = Operation <$> a v
|
|
|
|
|
2019-05-14 18:59:03 +00:00
|
|
|
call :: Either String (FileMatcher Annex) -> ParseResult (MatchFiles Annex)
|
|
|
|
call (Right sub) = Right $ Operation $ \notpresent mi ->
|
2016-02-03 18:56:34 +00:00
|
|
|
matchMrun sub $ \a -> a notpresent mi
|
2019-05-14 18:59:03 +00:00
|
|
|
call (Left err) = Left err
|