diff options
author | Joey Hess <joey@kitenet.net> | 2012-12-25 15:48:15 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-12-25 15:48:15 -0400 |
commit | 7a9f9fd6b81126a73a85ea7dab68260df36279b1 (patch) | |
tree | 6fc3177d163afd0e94d1624f3537fbe252d1c0f0 /Assistant | |
parent | 8602e201f2ac5dd9ab851e8023af080f77a9bd55 (diff) |
assistant direct mode file add/change bookkeeping
When a file is changed in direct mode, the old content is probably lost
(at least from the local repo), and bookeeping needs to be updated to
reflect this.
Also, synthetic add events are generated at assistant startup, so
make it detect when the file has not really changed, and avoid re-adding
it.
This does add the overhead of querying the runing git cat-file for the
key that's recorded in git for the file, each time a file is added or
modified in direct mode.
Diffstat (limited to 'Assistant')
-rw-r--r-- | Assistant/Threads/Watcher.hs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs index fd59f1b27..507362dd8 100644 --- a/Assistant/Threads/Watcher.hs +++ b/Assistant/Threads/Watcher.hs @@ -33,6 +33,8 @@ import qualified Git.HashObject import qualified Git.LsFiles as LsFiles import qualified Backend import Annex.Content +import Annex.Direct +import Annex.Content.Direct import Annex.CatFile import Git.Types import Config @@ -60,7 +62,7 @@ watchThread :: NamedThread watchThread = NamedThread "Watcher" $ do startup <- asIO1 startupScan direct <- liftAnnex isDirect - addhook <- hook $ onAdd direct + addhook <- hook $ if direct then onAddDirect else onAdd delhook <- hook onDel addsymlinkhook <- hook onAddSymlink deldirhook <- hook onDelDir @@ -126,12 +128,27 @@ runHandler handler file filestatus = void $ do liftAnnex $ Annex.Queue.flushWhenFull recordChange change -onAdd :: Bool -> Handler -onAdd isdirect file filestatus - | isdirect = pendingAddChange file +onAdd :: Handler +onAdd file filestatus | maybe False isRegularFile filestatus = pendingAddChange file | otherwise = noChange +{- In direct mode, add events are received for both new files, and + - modified existing files. Or, in some cases, existing files that have not + - really been modified. -} +onAddDirect :: Handler +onAddDirect file fs = do + v <- liftAnnex $ catKey (Ref $ ':':file) + case (v, fs) of + (Just key, Just filestatus) -> + ifM (liftAnnex $ changedFileStatus key filestatus) + ( noChange + , do + liftAnnex $ changedDirect key file + pendingAddChange file + ) + _ -> pendingAddChange file + {- A symlink might be an arbitrary symlink, which is just added. - Or, if it is a git-annex symlink, ensure it points to the content - before adding it. |