2018-08-28 14:26:51 +00:00
|
|
|
{- Git smudge filter configuration
|
|
|
|
-
|
enable filter.annex.process in v9
This has tradeoffs, but is generally a win, and users who it causes git add to
slow down unacceptably for can just disable it again.
It needed to happen in an upgrade, since there are git-annex versions
that do not support it, and using such an old version with a v8
repository with filter.annex.process set will cause bad behavior.
By enabling it in v9, it's guaranteed that any git-annex version that
can use the repository does support it. Although, this is not a perfect
protection against problems, since an old git-annex version, if it's
used with a v9 repository, will cause git add to try to run
git-annex filter-process, which will fail. But at least, the user is
unlikely to have an old git-annex in path if they are using a v9
repository, since it won't work in that repository.
Sponsored-by: Dartmouth College's Datalad project
2022-01-21 17:11:18 +00:00
|
|
|
- Copyright 2011-2022 Joey Hess <id@joeyh.name>
|
2018-08-28 14:26:51 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2018-08-28 14:26:51 +00:00
|
|
|
-}
|
|
|
|
|
2019-11-27 20:54:11 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2018-08-28 14:26:51 +00:00
|
|
|
module Config.Smudge where
|
|
|
|
|
|
|
|
import Annex.Common
|
|
|
|
import qualified Annex
|
|
|
|
import qualified Git
|
|
|
|
import qualified Git.Command
|
2019-12-02 14:57:09 +00:00
|
|
|
import Git.Types
|
2018-08-28 14:26:51 +00:00
|
|
|
import Config
|
2020-10-28 21:25:59 +00:00
|
|
|
import Utility.Directory.Create
|
enable filter.annex.process in v9
This has tradeoffs, but is generally a win, and users who it causes git add to
slow down unacceptably for can just disable it again.
It needed to happen in an upgrade, since there are git-annex versions
that do not support it, and using such an old version with a v8
repository with filter.annex.process set will cause bad behavior.
By enabling it in v9, it's guaranteed that any git-annex version that
can use the repository does support it. Although, this is not a perfect
protection against problems, since an old git-annex version, if it's
used with a v9 repository, will cause git add to try to run
git-annex filter-process, which will fail. But at least, the user is
unlikely to have an old git-annex in path if they are using a v9
repository, since it won't work in that repository.
Sponsored-by: Dartmouth College's Datalad project
2022-01-21 17:11:18 +00:00
|
|
|
import Annex.Version
|
2020-10-28 21:25:59 +00:00
|
|
|
|
|
|
|
import qualified System.FilePath.ByteString as P
|
2018-08-28 14:26:51 +00:00
|
|
|
|
|
|
|
configureSmudgeFilter :: Annex ()
|
2018-08-29 13:20:25 +00:00
|
|
|
configureSmudgeFilter = unlessM (fromRepo Git.repoIsLocalBare) $ do
|
2018-08-28 14:26:51 +00:00
|
|
|
-- If this is run in a newly cloned repository, git may not have
|
|
|
|
-- cached file information in the index yet, and so after
|
|
|
|
-- configuring the clean filter, the next git status would want to
|
|
|
|
-- run it on every file. That is expensive and can also result in
|
|
|
|
-- unexpected changes when the file is checked into git or annex
|
|
|
|
-- counter to the annex.largefiles configuration.
|
|
|
|
-- Avoid that problem by running git status now.
|
2022-12-20 20:02:42 +00:00
|
|
|
inRepo $ Git.Command.runQuiet
|
|
|
|
[ Param "status"
|
|
|
|
, Param "--porcelain"
|
|
|
|
, Param "--ignore-submodules"
|
|
|
|
]
|
2018-08-28 14:26:51 +00:00
|
|
|
|
2019-03-18 18:12:13 +00:00
|
|
|
setConfig (ConfigKey "filter.annex.smudge") "git-annex smudge -- %f"
|
|
|
|
setConfig (ConfigKey "filter.annex.clean") "git-annex smudge --clean -- %f"
|
enable filter.annex.process in v9
This has tradeoffs, but is generally a win, and users who it causes git add to
slow down unacceptably for can just disable it again.
It needed to happen in an upgrade, since there are git-annex versions
that do not support it, and using such an old version with a v8
repository with filter.annex.process set will cause bad behavior.
By enabling it in v9, it's guaranteed that any git-annex version that
can use the repository does support it. Although, this is not a perfect
protection against problems, since an old git-annex version, if it's
used with a v9 repository, will cause git add to try to run
git-annex filter-process, which will fail. But at least, the user is
unlikely to have an old git-annex in path if they are using a v9
repository, since it won't work in that repository.
Sponsored-by: Dartmouth College's Datalad project
2022-01-21 17:11:18 +00:00
|
|
|
whenM (versionSupportsFilterProcess <$> getVersion)
|
|
|
|
configureSmudgeFilterProcess
|
2018-08-28 14:26:51 +00:00
|
|
|
lf <- Annex.fromRepo Git.attributesLocal
|
|
|
|
gf <- Annex.fromRepo Git.attributes
|
|
|
|
lfs <- readattr lf
|
|
|
|
gfs <- readattr gf
|
2020-10-28 21:25:59 +00:00
|
|
|
gittop <- Git.localGitDir <$> gitRepo
|
2018-08-28 14:26:51 +00:00
|
|
|
liftIO $ unless ("filter=annex" `isInfixOf` (lfs ++ gfs)) $ do
|
2022-08-12 16:45:46 +00:00
|
|
|
createDirectoryUnder [gittop] (P.takeDirectory lf)
|
2020-10-28 21:25:59 +00:00
|
|
|
writeFile (fromRawFilePath lf) (lfs ++ "\n" ++ unlines stdattr)
|
2018-08-28 14:26:51 +00:00
|
|
|
where
|
2020-10-28 21:25:59 +00:00
|
|
|
readattr = liftIO . catchDefaultIO "" . readFileStrict . fromRawFilePath
|
2019-10-08 18:34:00 +00:00
|
|
|
|
enable filter.annex.process in v9
This has tradeoffs, but is generally a win, and users who it causes git add to
slow down unacceptably for can just disable it again.
It needed to happen in an upgrade, since there are git-annex versions
that do not support it, and using such an old version with a v8
repository with filter.annex.process set will cause bad behavior.
By enabling it in v9, it's guaranteed that any git-annex version that
can use the repository does support it. Although, this is not a perfect
protection against problems, since an old git-annex version, if it's
used with a v9 repository, will cause git add to try to run
git-annex filter-process, which will fail. But at least, the user is
unlikely to have an old git-annex in path if they are using a v9
repository, since it won't work in that repository.
Sponsored-by: Dartmouth College's Datalad project
2022-01-21 17:11:18 +00:00
|
|
|
configureSmudgeFilterProcess :: Annex ()
|
|
|
|
configureSmudgeFilterProcess =
|
|
|
|
setConfig (ConfigKey "filter.annex.process") "git-annex filter-process"
|
|
|
|
|
2019-10-08 18:34:00 +00:00
|
|
|
stdattr :: [String]
|
|
|
|
stdattr =
|
|
|
|
[ "* filter=annex"
|
|
|
|
]
|
|
|
|
|
|
|
|
-- Note that this removes the local git attributes for filtering,
|
|
|
|
-- which is what git-annex installed, but it does not change anything
|
|
|
|
-- that may have been committed to a .gitattributes in the repository.
|
|
|
|
-- git-annex does not commit that.
|
|
|
|
deconfigureSmudgeFilter :: Annex ()
|
|
|
|
deconfigureSmudgeFilter = do
|
2020-10-28 21:25:59 +00:00
|
|
|
lf <- fromRawFilePath <$> Annex.fromRepo Git.attributesLocal
|
2019-10-08 18:34:00 +00:00
|
|
|
ls <- liftIO $ catchDefaultIO [] $ lines <$> readFileStrict lf
|
|
|
|
liftIO $ writeFile lf $ unlines $
|
|
|
|
filter (\l -> l `notElem` stdattr && not (null l)) ls
|
|
|
|
unsetConfig (ConfigKey "filter.annex.smudge")
|
|
|
|
unsetConfig (ConfigKey "filter.annex.clean")
|
2021-01-04 17:12:28 +00:00
|
|
|
|
|
|
|
-- Params to pass to git to temporarily avoid using the smudge/clean
|
|
|
|
-- filters.
|
|
|
|
bypassSmudgeConfig :: [CommandParam]
|
|
|
|
bypassSmudgeConfig = map Param
|
|
|
|
[ "-c", "filter.annex.smudge="
|
|
|
|
, "-c", "filter.annex.clean="
|
2021-11-04 19:23:07 +00:00
|
|
|
, "-c", "filter.annex.process="
|
2021-01-04 17:12:28 +00:00
|
|
|
]
|