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 /Annex | |
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 'Annex')
-rw-r--r-- | Annex/CatFile.hs | 6 | ||||
-rw-r--r-- | Annex/Content/Direct.hs | 7 | ||||
-rw-r--r-- | Annex/Direct.hs | 8 |
3 files changed, 18 insertions, 3 deletions
diff --git a/Annex/CatFile.hs b/Annex/CatFile.hs index 161554f29..ffac4fccd 100644 --- a/Annex/CatFile.hs +++ b/Annex/CatFile.hs @@ -44,6 +44,6 @@ catFileHandle = maybe startup return =<< Annex.getState Annex.catfilehandle Annex.changeState $ \s -> s { Annex.catfilehandle = Just h } return h -{- From the Sha of a symlink back to the key. -} -catKey :: Sha -> Annex (Maybe Key) -catKey sha = fileKey . takeFileName . encodeW8 . L.unpack <$> catObject sha +{- From the Sha or Ref of a symlink back to the key. -} +catKey :: Ref -> Annex (Maybe Key) +catKey ref = fileKey . takeFileName . encodeW8 . L.unpack <$> catObject ref diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs index 75a32e3fc..75cdaad79 100644 --- a/Annex/Content/Direct.hs +++ b/Annex/Content/Direct.hs @@ -10,6 +10,7 @@ module Annex.Content.Direct ( removeAssociatedFile, addAssociatedFile, goodContent, + changedFileStatus, updateCache, recordedCache, compareCache, @@ -79,6 +80,12 @@ goodContent key file = do old <- recordedCache key compareCache file old +changedFileStatus :: Key -> FileStatus -> Annex Bool +changedFileStatus key status = do + old <- recordedCache key + let curr = toCache status + return $ curr == old + {- Gets the recorded cache for a key. -} recordedCache :: Key -> Annex (Maybe Cache) recordedCache key = withCacheFile key $ \cachefile -> diff --git a/Annex/Direct.hs b/Annex/Direct.hs index 77a544257..e44081639 100644 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -209,3 +209,11 @@ removeDirect k f = do liftIO $ do nukeFile f void $ catchMaybeIO $ removeDirectory $ parentDir f + +{- Called when a direct mode file has been changed. Its old content may be + - lost. -} +changedDirect :: Key -> FilePath -> Annex () +changedDirect oldk f = do + locs <- removeAssociatedFile oldk f + whenM (pure (null locs) <&&> not <$> inAnnex oldk) $ + logStatus oldk InfoMissing |