wip, waitRepo

This commit is contained in:
voidlizard 2025-01-19 22:45:38 +03:00
parent 3b9bb622c5
commit 99bb9c9dba
2 changed files with 32 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import HBS2.Git3.State
import HBS2.Git3.Import import HBS2.Git3.Import
import HBS2.Git3.Export import HBS2.Git3.Export
import HBS2.Git3.Git import HBS2.Git3.Git
import HBS2.Git3.Repo
import Data.Config.Suckless import Data.Config.Suckless
@ -19,6 +20,7 @@ import System.Exit qualified as Exit
import System.Environment (getArgs,lookupEnv) import System.Environment (getArgs,lookupEnv)
import Text.InterpolatedString.Perl6 (qc) import Text.InterpolatedString.Perl6 (qc)
import Data.Text qualified as Text import Data.Text qualified as Text
import Data.Either
import Data.Maybe import Data.Maybe
import Data.Config.Suckless.Script import Data.Config.Suckless.Script
@ -108,7 +110,7 @@ localDict DeferredOps{..} = makeDict @C do
entry $ bindMatch "r:list" $ nil_ $ const $ lift $ connectedDo do entry $ bindMatch "r:list" $ nil_ $ const $ lift $ connectedDo do
reflog <- getGitRemoteKey >>= orThrow GitRepoManifestMalformed reflog <- getGitRemoteKey >>= orThrow GitRepoManifestMalformed
notice $ red "REFLOG" <+> pretty (AsBase58 reflog) debug $ red "REFLOG" <+> pretty (AsBase58 reflog)
importGitRefLog importGitRefLog
@ -118,12 +120,22 @@ localDict DeferredOps{..} = makeDict @C do
debug $ pretty h <+> pretty r debug $ pretty h <+> pretty r
sendLine $ show $ pretty h <+> pretty r sendLine $ show $ pretty h <+> pretty r
let l = lastMay rrefs
for_ l $ \(r,h) -> do
debug $ pretty h <+> pretty "HEAD"
sendLine $ show $ pretty h <+> pretty "HEAD"
sendLine "" sendLine ""
entry $ bindMatch "r:fetch" $ nil_ $ \syn -> do
debug $ "FETCH" <+> pretty syn
sendLine ""
entry $ bindMatch "r:push" $ nil_ $ splitPushArgs $ \pushFrom pushTo -> lift do entry $ bindMatch "r:push" $ nil_ $ splitPushArgs $ \pushFrom pushTo -> lift do
r0 <- for pushFrom gitRevParseThrow r0 <- for pushFrom gitRevParseThrow
notice $ pretty $ [qc|ok {pretty pushTo}|] debug $ pretty $ [qc|ok {pretty pushTo}|]
case (r0, pushTo) of case (r0, pushTo) of
(Nothing, ref) -> do (Nothing, ref) -> do
@ -170,7 +182,7 @@ main = flip runContT pure do
let dict = theDict <> localDict ops let dict = theDict <> localDict ops
git <- liftIO $ lookupEnv "GIT_DIR" git <- liftIO $ lookupEnv "GIT_DIR"
notice $ red "GIT" <+> pretty git debug $ red "GIT" <+> pretty git
void $ lift $ withGit3Env env do void $ lift $ withGit3Env env do
@ -181,7 +193,7 @@ main = flip runContT pure do
case cli of case cli of
[ ListVal [_, RepoURL url ] ] -> do [ ListVal [_, RepoURL url ] ] -> do
notice $ "FUCKING REMOTE" <+> pretty (AsBase58 url) debug $ "FUCKING REMOTE" <+> pretty (AsBase58 url)
setGitRepoKey url setGitRepoKey url
_ -> none _ -> none
@ -190,26 +202,32 @@ main = flip runContT pure do
recover $ connectedDo do recover $ connectedDo do
waitRepo
flip fix Plain $ \next -> \case flip fix Plain $ \next -> \case
Plain -> do Plain -> do
eof <- done inp <- try @_ @IOError getLine <&> fromRight mempty
when eof $ next End
inp <- getLine
when (null (words inp)) $ next End when (null (words inp)) $ next End
notice $ pretty "INPUT" <+> pretty inp debug $ pretty "INPUT" <+> pretty inp
runTop dict ("r:"<>inp) r <- try @_ @SomeException (runTop dict ("r:"<>inp))
>>= \case
Left e -> die (show e)
_ -> none
next Plain next Plain
End -> do
-- sendLine ""
liftIO exitSuccess
_ -> do _ -> do
sendLine "" -- sendLine ""
next Plain next Plain
-- liftIO exitSuccess -- liftIO exitSuccess
-- debugPrefix :: LoggerEntry -> LoggerEntry -- debugPrefix :: LoggerEntry -> LoggerEntry

View File

@ -122,6 +122,8 @@ importGitRefLog = do
>>= orThrowUser "git directory not found" >>= orThrowUser "git directory not found"
<&> (</> "objects/pack") <&> (</> "objects/pack")
mkdir packs
sto <- getStorage sto <- getStorage
prev <- importedCheckpoint prev <- importedCheckpoint