diff --git a/hbs2-git/git-hbs2/GitRemoteMain.hs b/hbs2-git/git-hbs2/GitRemoteMain.hs index fe0d3269..418df693 100644 --- a/hbs2-git/git-hbs2/GitRemoteMain.hs +++ b/hbs2-git/git-hbs2/GitRemoteMain.hs @@ -107,18 +107,6 @@ loop args = do warn "trying to init reference --- may be it's ours" liftIO $ runApp WithLog (runExport Nothing ref) - refs <- withDB db stateGetActualRefs - - let heads = [ h | h@GitHash{} <- universeBi refs ] - - missed <- try (mapM (gitReadObject Nothing) heads) <&> either (\(_::SomeException) -> True) (const False) - - let force = missed || List.null heads - - debug $ "THIS MIGHT BE CLONE!" <+> pretty force - - -- sync state first - traceTime "TIMING: importRefLogNew" $ importRefLogNew force ref refsNew <- withDB db stateGetActualRefs let possibleHead = listToMaybe $ List.take 1 $ List.sortOn guessHead (fmap fst refsNew) @@ -190,6 +178,18 @@ loop args = do other -> die $ show other + refs <- withDB db stateGetActualRefs + + let heads = [ h | h@GitHash{} <- universeBi refs ] + + missed <- try (mapM (gitReadObject Nothing) heads) <&> either (\(_::SomeException) -> True) (const False) + + let force = missed || List.null heads + + when force do + -- sync state first + traceTime "TIMING: importRefLogNew" $ importRefLogNew True ref + shutUp where diff --git a/hbs2-git/lib/HBS2Git/State.hs b/hbs2-git/lib/HBS2Git/State.hs index c3cf75ea..e0332ffb 100644 --- a/hbs2-git/lib/HBS2Git/State.hs +++ b/hbs2-git/lib/HBS2Git/State.hs @@ -31,6 +31,8 @@ import Control.Concurrent.STM import Data.Graph (graphFromEdges, topSort) import Lens.Micro.Platform +import System.IO (stderr) + -- FIXME: move-orphans-to-separate-module instance ToField Cookie where @@ -267,7 +269,7 @@ readOrCreateCookie = do liftIO $ Text.writeFile cfn (fromCookie cookie) pure cookie else do - let cookie = Cookie (fromString cf) + let cookie@(Cookie co) = Cookie (fromString cf) statePutCookie cookie pure cookie @@ -421,6 +423,7 @@ statePutTranImported :: MonadIO m => HashRef -> DB m () statePutTranImported h = do conn <- stateConnection cookie <- asks (view dbCookie) + debug $ "statePutTranImported" <+> pretty h <+> viaShow cookie liftIO $ execute conn [qc| insert into tranimported (hash, cookie) values(?, ?) on conflict (hash, cookie) do nothing