From 31b9d2dcd1b32f564fa44fe5a7cc6526536a6f8f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 30 Apr 2013 16:35:55 -0400 Subject: assistant: Fix bug that could cause incoming pushes to not get merged into the local tree. Observed that the pushed refs were received, but not merged into master. The merger never saw an add event for these refs. Either git is not writing to a new file and renaming it into place, or the inotify code didn't notice that. Changed it to also watch for modify events and that seems to have fixed it! --- Assistant/Threads/Merger.hs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'Assistant/Threads/Merger.hs') diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs index a1b1693cf..650293e4b 100644 --- a/Assistant/Threads/Merger.hs +++ b/Assistant/Threads/Merger.hs @@ -32,10 +32,11 @@ mergeThread = namedThread "Merger" $ do let dir = Git.localGitDir g "refs" liftIO $ createDirectoryIfMissing True dir let hook a = Just <$> asIO2 (runHandler a) - addhook <- hook onAdd + changehook <- hook onChange errhook <- hook onErr let hooks = mkWatchHooks - { addHook = addhook + { addHook = changehook + , modifyHook = changehook , errHook = errhook } void $ liftIO $ watchDir dir (const False) hooks id @@ -55,19 +56,14 @@ runHandler handler file _filestatus = onErr :: Handler onErr msg = error msg -{- Called when a new branch ref is written. - - - - This relies on git's atomic method of updating branch ref files, - - which is to first write the new file to .lock, and then rename it - - over the old file. So, ignore .lock files, and the rename ensures - - the watcher sees a new file being added on each update. +{- Called when a new branch ref is written, or a branch ref is modified. - - At startup, synthetic add events fire, causing this to run, but that's - ok; it ensures that any changes pushed since the last time the assistant - ran are merged in. -} -onAdd :: Handler -onAdd file +onChange :: Handler +onChange file | ".lock" `isSuffixOf` file = noop | isAnnexBranch file = do branchChanged @@ -75,7 +71,7 @@ onAdd file when diverged $ unlessM handleDesynced $ queueDeferredDownloads "retrying deferred download" Later - | "/synced/" `isInfixOf` file = do + | "/synced/" `isInfixOf` file = mergecurrent =<< liftAnnex (inRepo Git.Branch.current) | otherwise = noop where -- cgit v1.2.3