refector for legibility

This commit is contained in:
Joey Hess 2022-09-23 18:53:06 -04:00
parent 2478e9e03a
commit e62e4eaaf2
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -217,36 +217,21 @@ restagePointerFiles r = unlessM (Annex.getState Annex.insmudgecleanfilter) $ do
liftIO . Database.Keys.Handle.closeDbHandle liftIO . Database.Keys.Handle.closeDbHandle
=<< Annex.getRead Annex.keysdbhandle =<< Annex.getRead Annex.keysdbhandle
realindex <- liftIO $ Git.Index.currentIndexFile r realindex <- liftIO $ Git.Index.currentIndexFile r
numsz@(numfiles, _) <- calcRestageLog (0, 0) $ \(_f, ic) (numfiles, sizefiles) -> numsz@(numfiles, _) <- calcnumsz
(numfiles+1, sizefiles + inodeCacheFileSize ic)
let lock = fromRawFilePath (Git.Index.indexFileLock realindex) let lock = fromRawFilePath (Git.Index.indexFileLock realindex)
lockindex = liftIO $ catchMaybeIO $ Git.LockFile.openLock' lock lockindex = liftIO $ catchMaybeIO $ Git.LockFile.openLock' lock
unlockindex = liftIO . maybe noop Git.LockFile.closeLock unlockindex = liftIO . maybe noop Git.LockFile.closeLock
showwarning = warning $ unableToRestage Nothing showwarning = warning $ unableToRestage Nothing
go Nothing = showwarning go Nothing = showwarning
go (Just _) = withTmpDirIn (fromRawFilePath $ Git.localGitDir r) "annexindex" $ \tmpdir -> do go (Just _) = withtmpdir $ \tmpdir -> do
tsd <- getTSDelta tsd <- getTSDelta
let tmpindex = toRawFilePath (tmpdir </> "index") let tmpindex = toRawFilePath (tmpdir </> "index")
let replaceindex = liftIO $ let replaceindex = liftIO $ moveFile tmpindex realindex
moveFile tmpindex realindex
let updatetmpindex = do let updatetmpindex = do
r' <- liftIO $ Git.Env.addGitEnv r Git.Index.indexEnv r' <- liftIO $ Git.Env.addGitEnv r Git.Index.indexEnv
=<< Git.Index.indexEnvVal tmpindex =<< Git.Index.indexEnvVal tmpindex
-- Avoid git warning about CRLF munging. configfilterprocess numsz $
let r'' = r' { gitGlobalOpts = gitGlobalOpts r' ++ runupdateindex tsd r' replaceindex
[ Param "-c"
, Param $ "core.safecrlf=" ++ boolConfig False
] }
configfilterprocess numsz $ runsGitAnnexChildProcessViaGit' r'' $ \r''' ->
Git.UpdateIndex.refreshIndex r''' $ \feeder -> do
let atend = do
-- wait for index write
liftIO $ feeder Nothing
replaceindex
streamRestageLog atend $ \topf ic -> do
let f = fromTopFilePath topf r'''
liftIO $ whenM (isunmodified tsd f ic) $
feedupdateindex f feeder
return True return True
ok <- liftIO (createLinkOrCopy realindex tmpindex) ok <- liftIO (createLinkOrCopy realindex tmpindex)
<&&> catchBoolIO updatetmpindex <&&> catchBoolIO updatetmpindex
@ -254,11 +239,31 @@ restagePointerFiles r = unlessM (Annex.getState Annex.insmudgecleanfilter) $ do
when (numfiles > 0) $ when (numfiles > 0) $
bracket lockindex unlockindex go bracket lockindex unlockindex go
where where
withtmpdir = withTmpDirIn (fromRawFilePath $ Git.localGitDir r) "annexindex"
isunmodified tsd f orig = isunmodified tsd f orig =
genInodeCache f tsd >>= return . \case genInodeCache f tsd >>= return . \case
Nothing -> False Nothing -> False
Just new -> compareStrong orig new Just new -> compareStrong orig new
{- Avoid git warning about CRLF munging -}
avoidcrlfwarning r' = r' { gitGlobalOpts = gitGlobalOpts r' ++
[ Param "-c"
, Param $ "core.safecrlf=" ++ boolConfig False
] }
runupdateindex tsd r' replaceindex =
runsGitAnnexChildProcessViaGit' (avoidcrlfwarning r') $ \r'' ->
Git.UpdateIndex.refreshIndex r'' $ \feeder -> do
let atend = do
-- wait for index write
liftIO $ feeder Nothing
replaceindex
streamRestageLog atend $ \topf ic -> do
let f = fromTopFilePath topf r''
liftIO $ whenM (isunmodified tsd f ic) $
feedupdateindex f feeder
{- update-index is documented as picky about "./file" and it {- update-index is documented as picky about "./file" and it
- fails on "../../repo/path/file" when cwd is not in the repo - fails on "../../repo/path/file" when cwd is not in the repo
- being acted on. Avoid these problems with an absolute path. - being acted on. Avoid these problems with an absolute path.
@ -267,6 +272,9 @@ restagePointerFiles r = unlessM (Annex.getState Annex.insmudgecleanfilter) $ do
absf <- absPath f absf <- absPath f
feeder (Just absf) feeder (Just absf)
calcnumsz = calcRestageLog (0, 0) $ \(_f, ic) (numfiles, sizefiles) ->
(numfiles+1, sizefiles + inodeCacheFileSize ic)
{- filter.annex.process configured to use git-annex filter-process {- filter.annex.process configured to use git-annex filter-process
- is sometimes faster and sometimes slower than using - is sometimes faster and sometimes slower than using
- git-annex smudge. The latter is run once per file, while - git-annex smudge. The latter is run once per file, while