make git add only annex when configured by annex.largefiles

This commit is contained in:
Joey Hess 2019-10-24 14:10:48 -04:00
parent 31a5b58b2c
commit 4a3f3a2cb5
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 26 additions and 25 deletions

View file

@ -19,7 +19,6 @@ import qualified Database.Keys
import qualified Git.BuildVersion import qualified Git.BuildVersion
import Git.FilePath import Git.FilePath
import qualified Git import qualified Git
import qualified Git.Ref
import qualified Annex import qualified Annex
import Backend import Backend
import Utility.Metered import Utility.Metered
@ -146,43 +145,37 @@ clean file = do
filepath <- liftIO $ absPath file filepath <- liftIO $ absPath file
return $ not $ dirContains repopath filepath return $ not $ dirContains repopath filepath
-- New files are annexed as configured by annex.gitaddtoannex and -- If annex.largefiles is configured, matching files are added to the
-- annex.largefiles. -- annex. But annex.gitaddtoannex can be set to false to disable that.
-- --
-- If annex.gitaddtoannex is false, or it's true and annex.largefiles -- When annex.largefiles is not configured, files are normally not
-- is not configured for a file, some heuristics are used to avoid bad -- added to the annex, so will be added to git. But some heuristics
-- behavior: -- are used to avoid bad behavior:
-- --
-- When the file's inode is the same as one that was used for annexed -- If the index already contains the file, preserve its annexed/not annexed
-- content before, annex it. This handles cases such as renaming an -- state. This prevents accidental conversions.
--
-- Otherwise, when the file's inode is the same as one that was used for
-- annexed content before, annex it. This handles cases such as renaming an
-- unlocked annexed file followed by git add, which the user naturally -- unlocked annexed file followed by git add, which the user naturally
-- expects to behave the same as git mv. -- expects to behave the same as git mv.
--
-- Otherwise, if the index already contains the file, preserve its
-- annexed/not annexed state. This prevents accidental conversions.
shouldAnnex :: FilePath -> Maybe Key -> Annex Bool shouldAnnex :: FilePath -> Maybe Key -> Annex Bool
shouldAnnex file moldkey = ifM (annexGitAddToAnnex <$> Annex.getGitConfig) shouldAnnex file moldkey = ifM (annexGitAddToAnnex <$> Annex.getGitConfig)
( checkmatcher (checkheuristics checkwasingit) ( checkmatcher checkheuristics
, checkheuristics (pure False) , checkheuristics
) )
where where
checkmatcher d = do checkmatcher d = do
matcher <- largeFilesMatcher matcher <- largeFilesMatcher
checkFileMatcher' matcher file d checkFileMatcher' matcher file d
checkheuristics d = case moldkey of checkheuristics = case moldkey of
Just _ -> return True Just _ -> return True
Nothing -> do Nothing -> checkknowninode
isknown <- withTSDelta (liftIO . genInodeCache file) >>= \case
Nothing -> pure False checkknowninode = withTSDelta (liftIO . genInodeCache file) >>= \case
Just ic -> Database.Keys.isInodeKnown ic =<< sentinalStatus Nothing -> pure False
if isknown Just ic -> Database.Keys.isInodeKnown ic =<< sentinalStatus
then return True
else d
checkwasingit = case moldkey of
Just _ -> return False
Nothing -> isNothing <$> catObjectMetaData (Git.Ref.fileRef file)
emitPointer :: Key -> IO () emitPointer :: Key -> IO ()
emitPointer = S.putStr . formatPointer emitPointer = S.putStr . formatPointer

View file

@ -0,0 +1,8 @@
[[!comment format=mdwn
username="joey"
subject="""comment 32"""
date="2019-10-24T18:17:05Z"
content="""
Futher, current master now only makes git add add to annex when
annex.largefiles has been configured.
"""]]