2015-12-04 17:02:56 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2022-02-23 19:17:08 +00:00
|
|
|
- Copyright 2015-2022 Joey Hess <id@joeyh.name>
|
2015-12-04 17:02:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-12-04 17:02:56 +00:00
|
|
|
-}
|
|
|
|
|
filter out control characters in warning messages
Converted warning and similar to use StringContainingQuotedPath. Most
warnings are static strings, some do refer to filepaths that need to be
quoted, and others don't need quoting.
Note that, since quote filters out control characters of even
UnquotedString, this makes all warnings safe, even when an attacker
sneaks in a control character in some other way.
When json is being output, no quoting is done, since json gets its own
quoting.
This does, as a side effect, make warning messages in json output not
be indented. The indentation is only needed to offset warning messages
underneath the display of the file they apply to, so that's ok.
Sponsored-by: Brett Eisenberg on Patreon
2023-04-10 18:47:32 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2015-12-04 17:02:56 +00:00
|
|
|
module Command.Smudge where
|
|
|
|
|
|
|
|
import Command
|
2015-12-04 19:30:06 +00:00
|
|
|
import Annex.Content
|
2015-12-09 18:25:33 +00:00
|
|
|
import Annex.Link
|
2015-12-04 19:30:06 +00:00
|
|
|
import Annex.FileMatcher
|
2015-12-24 17:15:26 +00:00
|
|
|
import Annex.Ingest
|
2016-06-09 19:17:08 +00:00
|
|
|
import Annex.CatFile
|
2021-06-08 15:34:46 +00:00
|
|
|
import Annex.WorkTree
|
2018-10-25 18:43:13 +00:00
|
|
|
import Logs.Smudge
|
2015-12-04 19:30:06 +00:00
|
|
|
import Logs.Location
|
2015-12-09 21:00:37 +00:00
|
|
|
import qualified Database.Keys
|
2018-08-09 22:17:46 +00:00
|
|
|
import qualified Git.BuildVersion
|
2016-01-05 21:22:19 +00:00
|
|
|
import Git.FilePath
|
2019-12-27 18:58:10 +00:00
|
|
|
import Git.Types
|
|
|
|
import Git.HashObject
|
2018-11-15 17:04:40 +00:00
|
|
|
import qualified Git
|
2019-12-27 18:58:10 +00:00
|
|
|
import qualified Git.Ref
|
2019-10-23 19:20:00 +00:00
|
|
|
import qualified Annex
|
2016-06-09 19:17:08 +00:00
|
|
|
import Backend
|
2019-06-25 15:37:52 +00:00
|
|
|
import Utility.Metered
|
2019-10-23 18:37:51 +00:00
|
|
|
import Annex.InodeSentinal
|
|
|
|
import Utility.InodeCache
|
2019-12-26 20:24:40 +00:00
|
|
|
import Config.GitConfig
|
2021-01-25 21:34:58 +00:00
|
|
|
import qualified Types.Backend
|
2021-09-24 18:15:20 +00:00
|
|
|
import qualified Annex.BranchState
|
2015-12-04 18:03:10 +00:00
|
|
|
|
2019-01-14 19:19:20 +00:00
|
|
|
import qualified Data.ByteString as S
|
|
|
|
import qualified Data.ByteString.Lazy as L
|
2015-12-04 17:02:56 +00:00
|
|
|
|
|
|
|
cmd :: Command
|
2015-12-04 19:30:06 +00:00
|
|
|
cmd = noCommit $ noMessages $
|
2015-12-04 17:02:56 +00:00
|
|
|
command "smudge" SectionPlumbing
|
|
|
|
"git smudge filter"
|
2015-12-04 19:30:06 +00:00
|
|
|
paramFile (seek <$$> optParser)
|
2015-12-04 17:02:56 +00:00
|
|
|
|
2018-10-25 18:43:13 +00:00
|
|
|
data SmudgeOptions = UpdateOption | SmudgeOptions
|
2015-12-04 19:30:06 +00:00
|
|
|
{ smudgeFile :: FilePath
|
|
|
|
, cleanOption :: Bool
|
|
|
|
}
|
2015-12-04 17:02:56 +00:00
|
|
|
|
2015-12-04 19:30:06 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser SmudgeOptions
|
2018-10-25 18:43:13 +00:00
|
|
|
optParser desc = smudgeoptions <|> updateoption
|
|
|
|
where
|
|
|
|
smudgeoptions = SmudgeOptions
|
|
|
|
<$> argument str ( metavar desc )
|
|
|
|
<*> switch ( long "clean" <> help "clean filter" )
|
|
|
|
updateoption = flag' UpdateOption
|
|
|
|
( long "update" <> help "populate annexed worktree files" )
|
2015-12-04 19:30:06 +00:00
|
|
|
|
|
|
|
seek :: SmudgeOptions -> CommandSeek
|
2018-10-25 18:43:13 +00:00
|
|
|
seek (SmudgeOptions f False) = commandAction (smudge f)
|
2020-11-02 20:31:28 +00:00
|
|
|
seek (SmudgeOptions f True) = commandAction (clean (toRawFilePath f))
|
2018-10-25 18:43:13 +00:00
|
|
|
seek UpdateOption = commandAction update
|
2015-12-04 19:30:06 +00:00
|
|
|
|
2015-12-04 21:18:26 +00:00
|
|
|
-- Smudge filter is fed git file content, and if it's a pointer to an
|
2018-10-25 18:43:13 +00:00
|
|
|
-- available annex object, git expects it to output its content.
|
|
|
|
--
|
|
|
|
-- However, this does not do that. It outputs the pointer, and records
|
|
|
|
-- the filename in the smudge log. Git hooks run after commands like checkout
|
|
|
|
-- then run git annex smudge --update which populates the work tree files
|
|
|
|
-- with annex content. This is done for several reasons:
|
|
|
|
--
|
|
|
|
-- * To support annex.thin
|
|
|
|
-- * Because git currently buffers the whole object received from the
|
|
|
|
-- smudge filter in memory, which is a problem with large files.
|
2015-12-04 19:30:06 +00:00
|
|
|
smudge :: FilePath -> CommandStart
|
2015-12-07 18:35:46 +00:00
|
|
|
smudge file = do
|
2019-01-14 19:19:20 +00:00
|
|
|
b <- liftIO $ L.hGetContents stdin
|
2021-11-04 19:02:36 +00:00
|
|
|
smudge' file b
|
2019-01-14 19:19:20 +00:00
|
|
|
liftIO $ L.putStr b
|
2015-12-04 18:03:10 +00:00
|
|
|
stop
|
2015-12-04 19:30:06 +00:00
|
|
|
|
2021-11-04 19:02:36 +00:00
|
|
|
-- Handles everything except the IO of the file content.
|
|
|
|
smudge' :: FilePath -> L.ByteString -> Annex ()
|
|
|
|
smudge' file b = case parseLinkTargetOrPointerLazy b of
|
|
|
|
Nothing -> noop
|
|
|
|
Just k -> do
|
|
|
|
topfile <- inRepo (toTopFilePath (toRawFilePath file))
|
|
|
|
Database.Keys.addAssociatedFile k topfile
|
|
|
|
void $ smudgeLog k topfile
|
|
|
|
|
2015-12-09 19:24:32 +00:00
|
|
|
-- Clean filter is fed file content on stdin, decides if a file
|
|
|
|
-- should be stored in the annex, and outputs a pointer to its
|
2018-08-09 22:17:46 +00:00
|
|
|
-- injested content if so. Otherwise, the original content.
|
2020-11-02 20:31:28 +00:00
|
|
|
clean :: RawFilePath -> CommandStart
|
2015-12-04 19:30:06 +00:00
|
|
|
clean file = do
|
2021-09-24 18:15:20 +00:00
|
|
|
Annex.BranchState.disableUpdate -- optimisation
|
2019-01-14 19:19:20 +00:00
|
|
|
b <- liftIO $ L.hGetContents stdin
|
2021-11-04 19:02:36 +00:00
|
|
|
let passthrough = liftIO $ L.hPut stdout b
|
|
|
|
-- Before git 2.5, failing to consume all stdin here would
|
|
|
|
-- cause a SIGPIPE and crash it.
|
|
|
|
-- Newer git catches the signal and stops sending, which is
|
|
|
|
-- much faster. (Also, git seems to forget to free memory
|
|
|
|
-- when sending the file, so the less we let it send, the
|
|
|
|
-- less memory it will waste.)
|
|
|
|
let discardreststdin = if Git.BuildVersion.older "2.5"
|
|
|
|
then L.length b `seq` return ()
|
|
|
|
else liftIO $ hClose stdin
|
|
|
|
let emitpointer = liftIO . S.hPut stdout . formatPointer
|
2022-02-23 19:17:08 +00:00
|
|
|
clean' file (parseLinkTargetOrPointerLazy' b)
|
2021-11-04 19:02:36 +00:00
|
|
|
passthrough
|
|
|
|
discardreststdin
|
|
|
|
emitpointer
|
2015-12-04 19:30:06 +00:00
|
|
|
stop
|
2016-01-01 18:16:40 +00:00
|
|
|
where
|
2021-11-04 19:02:36 +00:00
|
|
|
|
|
|
|
-- Handles everything except the IO of the file content.
|
|
|
|
clean'
|
|
|
|
:: RawFilePath
|
2022-02-23 19:17:08 +00:00
|
|
|
-> Either InvalidAppendedPointerFile (Maybe Key)
|
2021-11-04 19:02:36 +00:00
|
|
|
-- ^ If the content provided by git is an annex pointer,
|
|
|
|
-- this is the key it points to.
|
|
|
|
-> Annex ()
|
|
|
|
-- ^ passthrough: Feed the content provided by git back out to git.
|
|
|
|
-> Annex ()
|
|
|
|
-- ^ discardreststdin: Called when passthrough will not be called,
|
|
|
|
-- this has to take care of reading the content provided by git, or
|
|
|
|
-- otherwise dealing with it.
|
|
|
|
-> (Key -> Annex ())
|
|
|
|
-- ^ emitpointer: Emit a pointer file for the key.
|
|
|
|
-> Annex ()
|
|
|
|
clean' file mk passthrough discardreststdin emitpointer =
|
|
|
|
ifM (fileOutsideRepo file)
|
|
|
|
( passthrough
|
|
|
|
, inSmudgeCleanFilter go
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
go = case mk of
|
2022-02-23 19:17:08 +00:00
|
|
|
Right (Just k) -> do
|
2020-11-10 16:10:51 +00:00
|
|
|
addingExistingLink file k $ do
|
|
|
|
getMoveRaceRecovery k file
|
2021-11-04 19:02:36 +00:00
|
|
|
passthrough
|
2022-02-23 19:17:08 +00:00
|
|
|
Right Nothing -> notpointer
|
|
|
|
Left InvalidAppendedPointerFile -> do
|
|
|
|
toplevelWarning False $
|
filter out control characters in warning messages
Converted warning and similar to use StringContainingQuotedPath. Most
warnings are static strings, some do refer to filepaths that need to be
quoted, and others don't need quoting.
Note that, since quote filters out control characters of even
UnquotedString, this makes all warnings safe, even when an attacker
sneaks in a control character in some other way.
When json is being output, no quoting is done, since json gets its own
quoting.
This does, as a side effect, make warning messages in json output not
be indented. The indentation is only needed to offset warning messages
underneath the display of the file they apply to, so that's ok.
Sponsored-by: Brett Eisenberg on Patreon
2023-04-10 18:47:32 +00:00
|
|
|
"The file " <> QuotedPath file <> " looks like git-annex pointer file that has had other content appended to it"
|
2022-02-23 19:17:08 +00:00
|
|
|
notpointer
|
|
|
|
|
|
|
|
notpointer = inRepo (Git.Ref.fileRef file) >>= \case
|
|
|
|
Just fileref -> do
|
|
|
|
indexmeta <- catObjectMetaData fileref
|
|
|
|
oldkey <- case indexmeta of
|
|
|
|
Just (_, sz, _) -> catKey' fileref sz
|
|
|
|
Nothing -> return Nothing
|
|
|
|
notpointer' indexmeta oldkey
|
|
|
|
Nothing -> passthrough
|
|
|
|
|
|
|
|
notpointer' indexmeta oldkey = ifM (shouldAnnex file indexmeta oldkey)
|
2018-08-27 18:47:17 +00:00
|
|
|
( do
|
2021-11-04 19:02:36 +00:00
|
|
|
discardreststdin
|
2018-10-25 20:38:04 +00:00
|
|
|
|
2018-10-30 04:40:17 +00:00
|
|
|
-- Optimization for the case when the file is already
|
|
|
|
-- annexed and is unmodified.
|
2018-10-25 20:38:04 +00:00
|
|
|
case oldkey of
|
2021-01-25 21:34:58 +00:00
|
|
|
Nothing -> doingest Nothing
|
2020-11-02 20:31:28 +00:00
|
|
|
Just ko -> ifM (isUnmodifiedCheap ko file)
|
2021-11-04 19:02:36 +00:00
|
|
|
( emitpointer ko
|
2021-01-25 21:34:58 +00:00
|
|
|
, updateingest ko
|
2018-10-25 20:38:04 +00:00
|
|
|
)
|
2021-11-04 19:02:36 +00:00
|
|
|
, passthrough
|
2018-08-27 18:47:17 +00:00
|
|
|
)
|
2018-10-25 20:38:04 +00:00
|
|
|
|
2021-01-25 21:34:58 +00:00
|
|
|
-- Use the same backend that was used before, when possible.
|
|
|
|
-- If the old key's backend does not support generating keys,
|
|
|
|
-- use the default backend.
|
|
|
|
updateingest oldkey =
|
|
|
|
maybeLookupBackendVariety (fromKey keyVariety oldkey) >>= \case
|
|
|
|
Nothing -> doingest Nothing
|
|
|
|
Just oldbackend -> case Types.Backend.genKey oldbackend of
|
|
|
|
Just _ -> doingest (Just oldbackend)
|
|
|
|
Nothing -> doingest Nothing
|
|
|
|
|
|
|
|
doingest preferredbackend = do
|
2018-10-25 20:38:04 +00:00
|
|
|
-- Can't restage associated files because git add
|
|
|
|
-- runs this and has the index locked.
|
|
|
|
let norestage = Restage False
|
2021-11-04 19:02:36 +00:00
|
|
|
emitpointer
|
2018-10-25 20:38:04 +00:00
|
|
|
=<< postingest
|
2021-01-25 21:34:58 +00:00
|
|
|
=<< (\ld -> ingest' preferredbackend nullMeterUpdate ld Nothing norestage)
|
2020-11-02 20:31:28 +00:00
|
|
|
=<< lockDown cfg (fromRawFilePath file)
|
2018-08-27 18:47:17 +00:00
|
|
|
|
|
|
|
postingest (Just k, _) = do
|
2024-08-23 20:35:12 +00:00
|
|
|
logStatus NoLiveUpdate k InfoPresent
|
2016-01-01 18:16:40 +00:00
|
|
|
return k
|
2023-04-10 17:38:14 +00:00
|
|
|
postingest _ = giveup "could not add file to the annex"
|
2018-08-27 18:47:17 +00:00
|
|
|
|
2016-01-07 21:39:59 +00:00
|
|
|
cfg = LockDownConfig
|
|
|
|
{ lockingFile = False
|
2019-05-07 17:04:39 +00:00
|
|
|
, hardlinkFileTmpDir = Nothing
|
2021-09-02 17:45:21 +00:00
|
|
|
, checkWritePerms = True
|
2016-01-07 21:39:59 +00:00
|
|
|
}
|
2015-12-04 19:30:06 +00:00
|
|
|
|
2021-11-04 19:02:36 +00:00
|
|
|
-- git diff can run the clean filter on files outside the
|
|
|
|
-- repository; can't annex those
|
|
|
|
fileOutsideRepo :: RawFilePath -> Annex Bool
|
|
|
|
fileOutsideRepo file = do
|
|
|
|
repopath <- liftIO . absPath =<< fromRepo Git.repoPath
|
|
|
|
filepath <- liftIO $ absPath file
|
|
|
|
return $ not $ dirContains repopath filepath
|
|
|
|
|
|
|
|
-- Avoid a potential deadlock.
|
|
|
|
inSmudgeCleanFilter :: Annex a -> Annex a
|
|
|
|
inSmudgeCleanFilter = bracket setup cleanup . const
|
|
|
|
where
|
|
|
|
setup = Annex.changeState $ \s -> s
|
|
|
|
{ Annex.insmudgecleanfilter = True }
|
|
|
|
cleanup () = Annex.changeState $ \s -> s
|
|
|
|
{ Annex.insmudgecleanfilter = False }
|
2018-11-15 17:04:40 +00:00
|
|
|
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
-- If annex.largefiles is configured (and not disabled by annex.gitaddtoannex
|
|
|
|
-- being set to false), matching files are added to the annex and the rest to
|
|
|
|
-- git.
|
2019-10-23 18:37:51 +00:00
|
|
|
--
|
2019-10-24 18:10:48 +00:00
|
|
|
-- When annex.largefiles is not configured, files are normally not
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
-- added to the annex, so will be added to git. However, if the file
|
|
|
|
-- is annexed in the index, keep it annexed. This prevents accidental
|
|
|
|
-- conversions when previously annexed files get modified and added.
|
2019-10-23 18:37:51 +00:00
|
|
|
--
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
-- In either case, if the file's inode is the same as one that was used
|
|
|
|
-- for annexed content before, annex it. And if the file is not annexed
|
|
|
|
-- in the index, and has the same content, leave it in git.
|
|
|
|
-- This handles cases such as renaming a file followed by git add,
|
|
|
|
-- which the user naturally expects to behave the same as git mv.
|
2020-11-02 20:31:28 +00:00
|
|
|
shouldAnnex :: RawFilePath -> Maybe (Sha, FileSize, ObjectType) -> Maybe Key -> Annex Bool
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
shouldAnnex file indexmeta moldkey = do
|
|
|
|
ifM (annexGitAddToAnnex <$> Annex.getGitConfig)
|
|
|
|
( checkunchanged $ checkmatcher checkwasannexed
|
|
|
|
, checkunchanged checkwasannexed
|
|
|
|
)
|
2018-08-27 18:47:17 +00:00
|
|
|
where
|
2019-12-26 20:24:40 +00:00
|
|
|
checkmatcher d
|
|
|
|
| dotfile file = ifM (getGitConfigVal annexDotFiles)
|
|
|
|
( go
|
2020-03-09 18:20:02 +00:00
|
|
|
, d
|
2019-12-26 20:24:40 +00:00
|
|
|
)
|
|
|
|
| otherwise = go
|
|
|
|
where
|
|
|
|
go = do
|
|
|
|
matcher <- largeFilesMatcher
|
2024-08-23 20:35:12 +00:00
|
|
|
checkFileMatcher' NoLiveUpdate matcher file d
|
2019-10-23 19:20:00 +00:00
|
|
|
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
checkwasannexed = pure $ isJust moldkey
|
2019-10-24 18:10:48 +00:00
|
|
|
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
isknownannexedinode = withTSDelta (liftIO . genInodeCache file) >>= \case
|
2019-10-24 18:10:48 +00:00
|
|
|
Nothing -> pure False
|
|
|
|
Just ic -> Database.Keys.isInodeKnown ic =<< sentinalStatus
|
2015-12-04 19:30:06 +00:00
|
|
|
|
smudge: check for known annexed inodes before checking annex.largefiles
smudge: Fix a case where an unlocked annexed file that annex.largefiles
does not match could get its unchanged content checked into git, due to git
running the smudge filter unecessarily.
When the file has the same inodecache as an already annexed file,
we can assume that the user is not intending to change how it's stored in
git.
Note that checkunchangedgitfile already handled the inverse case, where the
file was added to git previously. That goes further and actually sha1
hashes the new file and checks if it's the same hash in the index.
It would be possible to generate a key for the file and see if it's the
same as the old key, however that could be considerably more expensive than
sha1 of a small file is, and it is not necessary for the case I have, at
least, where the file is not modified or touched, and so its inode will
match the cache.
git-annex add was changed, when adding a small file, to remove the inode
cache for it. This is necessary to keep the recipe in
doc/tips/largefiles.mdwn for converting from annex to git working.
It also avoids bugs/case_where_using_pathspec_with_git-commit_leaves_s.mdwn
which the earlier try at this change introduced.
2021-05-10 17:05:08 +00:00
|
|
|
-- If the inode matches one known used for annexed content,
|
|
|
|
-- keep the file annexed. This handles a case where the file
|
|
|
|
-- has been annexed before, and the git is running the clean filter
|
|
|
|
-- again on it for whatever reason.
|
|
|
|
checkunchanged cont = ifM isknownannexedinode
|
|
|
|
( return True
|
|
|
|
, checkunchangedgitfile cont
|
|
|
|
)
|
|
|
|
|
2019-12-27 18:58:10 +00:00
|
|
|
-- This checks for a case where the file had been added to git
|
|
|
|
-- previously, not to the annex before, and its content is not
|
|
|
|
-- changed, but git is running the clean filter again on it
|
|
|
|
-- (eg because its mtime or inode changed, or just because git feels
|
|
|
|
-- like it). Such a file should not be added to the annex, even if
|
|
|
|
-- annex.largefiles now matches it, because the content is not
|
|
|
|
-- changed.
|
|
|
|
checkunchangedgitfile cont = case (moldkey, indexmeta) of
|
2020-11-05 15:26:34 +00:00
|
|
|
(Nothing, Just (sha, sz, _)) -> liftIO (catchMaybeIO (getFileSize file)) >>= \case
|
2019-12-27 18:58:10 +00:00
|
|
|
Just sz' | sz' == sz -> do
|
|
|
|
-- The size is the same, so the file
|
|
|
|
-- is not much larger than what was stored
|
|
|
|
-- in git before, so it won't be out of
|
|
|
|
-- line to hash it. However, the content
|
|
|
|
-- is prevented from being stored in git
|
|
|
|
-- when hashing.
|
|
|
|
h <- inRepo $ hashObjectStart False
|
|
|
|
sha' <- liftIO $ hashFile h file
|
|
|
|
liftIO $ hashObjectStop h
|
|
|
|
if sha' == sha
|
|
|
|
then return False
|
|
|
|
else cont
|
|
|
|
_ -> cont
|
|
|
|
_ -> cont
|
|
|
|
|
2018-08-22 20:01:50 +00:00
|
|
|
-- Recover from a previous race between eg git mv and git-annex get.
|
|
|
|
-- That could result in the file remaining a pointer file, while
|
|
|
|
-- its content is present in the annex. Populate the pointer file.
|
|
|
|
--
|
|
|
|
-- This also handles the case where a copy of a pointer file is made,
|
|
|
|
-- then git-annex gets the content, and later git add is run on
|
|
|
|
-- the pointer copy. It will then be populated with the content.
|
2019-12-05 15:40:10 +00:00
|
|
|
getMoveRaceRecovery :: Key -> RawFilePath -> Annex ()
|
2018-08-22 20:01:50 +00:00
|
|
|
getMoveRaceRecovery k file = void $ tryNonAsync $
|
2018-10-25 18:31:45 +00:00
|
|
|
whenM (inAnnex k) $ do
|
2019-12-11 18:12:22 +00:00
|
|
|
obj <- calcRepo (gitAnnexLocation k)
|
2018-10-25 18:31:45 +00:00
|
|
|
-- Cannot restage because git add is running and has
|
|
|
|
-- the index locked.
|
|
|
|
populatePointerFile (Restage False) k obj file >>= \case
|
|
|
|
Nothing -> return ()
|
|
|
|
Just ic -> Database.Keys.addInodeCaches k [ic]
|
2018-10-25 18:43:13 +00:00
|
|
|
|
|
|
|
update :: CommandStart
|
|
|
|
update = do
|
2021-06-08 15:34:46 +00:00
|
|
|
-- This gets run after a git checkout or merge, so it's a good
|
|
|
|
-- point to refresh the keys database for changes to annexed files.
|
|
|
|
-- Doing it explicitly here avoids a later pause in the middle of
|
|
|
|
-- some other action.
|
2021-07-30 21:46:11 +00:00
|
|
|
scanAnnexedFiles
|
2018-10-25 18:43:13 +00:00
|
|
|
updateSmudged (Restage True)
|
|
|
|
stop
|
|
|
|
|
|
|
|
updateSmudged :: Restage -> Annex ()
|
|
|
|
updateSmudged restage = streamSmudged $ \k topf -> do
|
2019-12-09 17:49:05 +00:00
|
|
|
f <- fromRepo (fromTopFilePath topf)
|
2018-10-25 18:43:13 +00:00
|
|
|
whenM (inAnnex k) $ do
|
2019-12-11 18:12:22 +00:00
|
|
|
obj <- calcRepo (gitAnnexLocation k)
|
2021-01-26 01:19:07 +00:00
|
|
|
objic <- withTSDelta (liftIO . genInodeCache obj)
|
2021-01-25 21:25:42 +00:00
|
|
|
populatePointerFile restage k obj f >>= \case
|
2021-01-26 01:19:07 +00:00
|
|
|
Just ic -> do
|
|
|
|
cs <- Database.Keys.getInodeCaches k
|
|
|
|
if null cs
|
|
|
|
then Database.Keys.addInodeCaches k (catMaybes [Just ic, objic])
|
|
|
|
else Database.Keys.addInodeCaches k [ic]
|
2021-01-25 21:25:42 +00:00
|
|
|
Nothing -> liftIO (isPointerFile f) >>= \case
|
2018-10-25 18:43:13 +00:00
|
|
|
Just k' | k' == k -> toplevelWarning False $
|
filter out control characters in warning messages
Converted warning and similar to use StringContainingQuotedPath. Most
warnings are static strings, some do refer to filepaths that need to be
quoted, and others don't need quoting.
Note that, since quote filters out control characters of even
UnquotedString, this makes all warnings safe, even when an attacker
sneaks in a control character in some other way.
When json is being output, no quoting is done, since json gets its own
quoting.
This does, as a side effect, make warning messages in json output not
be indented. The indentation is only needed to offset warning messages
underneath the display of the file they apply to, so that's ok.
Sponsored-by: Brett Eisenberg on Patreon
2023-04-10 18:47:32 +00:00
|
|
|
"unable to populate worktree file " <> QuotedPath f
|
2018-10-25 18:43:13 +00:00
|
|
|
_ -> noop
|