fixed refs deleting

This commit is contained in:
Dmitry Zuikov 2024-04-21 08:19:37 +03:00
parent ed30d09693
commit 8e27d5c039
6 changed files with 27 additions and 11 deletions

View File

@ -171,7 +171,7 @@ pShowRef = do
(_,rh) <- TX.readRepoHeadFromTx sto tx >>= toMPlus (_,rh) <- TX.readRepoHeadFromTx sto tx >>= toMPlus
liftIO $ print $ vcat (fmap formatRef (_repoHeadRefs rh)) liftIO $ print $ vcat (fmap formatRef (view repoHeadRefs rh))
pManifest :: GitPerks m => Parser (GitCLI m ()) pManifest :: GitPerks m => Parser (GitCLI m ())

View File

@ -9,6 +9,7 @@ import HBS2.Git.Client.Export
import HBS2.Git.Client.State import HBS2.Git.Client.State
import HBS2.Git.Client.Progress import HBS2.Git.Client.Progress
import HBS2.Git.Client.Config import HBS2.Git.Client.Config
import HBS2.Git.Data.RepoHead
import HBS2.Git.Data.RefLog import HBS2.Git.Data.RefLog
import HBS2.Git.Data.Tx.Git qualified as TX import HBS2.Git.Data.Tx.Git qualified as TX
import HBS2.Git.Data.Tx.Git (RepoHead(..)) import HBS2.Git.Data.Tx.Git (RepoHead(..))
@ -178,7 +179,7 @@ main = do
tx <- selectMaxAppliedTx >>= lift . toMPlus <&> fst tx <- selectMaxAppliedTx >>= lift . toMPlus <&> fst
(_,rh) <- TX.readRepoHeadFromTx sto tx >>= lift . toMPlus (_,rh) <- TX.readRepoHeadFromTx sto tx >>= lift . toMPlus
pure (_repoHeadRefs rh) pure (view repoHeadRefs rh)
let r = fromMaybe mempty r' let r = fromMaybe mempty r'

View File

@ -110,7 +110,7 @@ refsForExport forPushL = do
[val,name] -> (GitRef (LBS8.toStrict name),) <$> fromStringMay @GitHash (LBS8.unpack val) [val,name] -> (GitRef (LBS8.toStrict name),) <$> fromStringMay @GitHash (LBS8.unpack val)
_ -> Nothing _ -> Nothing
<&> HashMap.fromList <&> HashMap.fromList
<&> HashMap.filterWithKey (\k _ -> not (HashSet.member k deleted)) <&> HashMap.mapWithKey (\k v -> if k `HashSet.member` deleted then gitHashTomb else v)
<&> mappend forPush <&> mappend forPush
<&> mappend (HashMap.singleton currentBranch currentVal) <&> mappend (HashMap.singleton currentBranch currentVal)
<&> HashMap.toList <&> HashMap.toList
@ -217,7 +217,7 @@ export key refs = do
repohead <- makeRepoHeadSimple name brief mf gk0 myrefs repohead <- makeRepoHeadSimple name brief mf gk0 myrefs
let oldRefs = maybe mempty _repoHeadRefs rh0 let oldRefs = maybe mempty repoHeadRefs' rh0
trace $ "TX0" <+> pretty tx0 trace $ "TX0" <+> pretty tx0

View File

@ -9,6 +9,7 @@ import HBS2.Git.Client.Progress
import HBS2.Git.Data.RefLog import HBS2.Git.Data.RefLog
import HBS2.Git.Data.Tx.Git import HBS2.Git.Data.Tx.Git
import HBS2.Git.Data.LWWBlock import HBS2.Git.Data.LWWBlock
import HBS2.Git.Data.RepoHead
import Data.ByteString.Lazy qualified as LBS import Data.ByteString.Lazy qualified as LBS
@ -291,7 +292,7 @@ applyTx h = do
applyHeads rh = do applyHeads rh = do
let refs = _repoHeadRefs rh let refs = view repoHeadRefs rh
withGitFastImport $ \ps -> do withGitFastImport $ \ps -> do
let psin = getStdin ps let psin = getStdin ps

View File

@ -30,7 +30,7 @@ data RepoHead =
, _repoHeadName :: Text , _repoHeadName :: Text
, _repoHeadBrief :: Text , _repoHeadBrief :: Text
, _repoManifest :: Maybe Text , _repoManifest :: Maybe Text
, _repoHeadRefs :: [(GitRef, GitHash)] , repoHeadRefs' :: [(GitRef, GitHash)]
, _repoHeadExt :: [RepoHeadExt] , _repoHeadExt :: [RepoHeadExt]
} }
deriving stock (Generic) deriving stock (Generic)
@ -39,18 +39,29 @@ makeLenses ''RepoHead
repoHeadTags :: SimpleGetter RepoHead [Text] repoHeadTags :: SimpleGetter RepoHead [Text]
repoHeadTags = repoHeadTags =
to \RepoHeadSimple{..} -> do to \h@RepoHeadSimple{} -> do
catMaybes [ lastMay (B8.split '/' s) <&> (Text.pack . B8.unpack) catMaybes [ lastMay (B8.split '/' s) <&> (Text.pack . B8.unpack)
| (GitRef s, _) <- _repoHeadRefs, B8.isPrefixOf "refs/tags" s | (GitRef s, _) <- view repoHeadRefs h, B8.isPrefixOf "refs/tags" s
] & Set.fromList & Set.toList ] & Set.fromList & Set.toList
repoHeadHeads :: SimpleGetter RepoHead [Text] repoHeadHeads :: SimpleGetter RepoHead [Text]
repoHeadHeads = repoHeadHeads =
to \RepoHeadSimple{..} -> do to \h@RepoHeadSimple{} -> do
catMaybes [ lastMay (B8.split '/' s) <&> (Text.pack . B8.unpack) catMaybes [ lastMay (B8.split '/' s) <&> (Text.pack . B8.unpack)
| (GitRef s, _) <- _repoHeadRefs, B8.isPrefixOf "refs/heads" s | (GitRef s, v) <- view repoHeadRefs h, B8.isPrefixOf "refs/heads" s
] & Set.fromList & Set.toList ] & Set.fromList & Set.toList
repoHeadRefs :: Lens RepoHead
RepoHead
[(GitRef, GitHash)]
[(GitRef, GitHash)]
repoHeadRefs = lens g s
where
s rh r = rh { repoHeadRefs' = r }
g rh = [ (r,v) | (r,v) <- repoHeadRefs' rh, v /= gitHashTomb ]
instance Serialise RepoHeadType instance Serialise RepoHeadType
instance Serialise RepoHeadExt instance Serialise RepoHeadExt

View File

@ -16,6 +16,9 @@ newtype GitHash = GitHash ByteString
deriving stock (Eq,Ord,Data,Generic,Show) deriving stock (Eq,Ord,Data,Generic,Show)
deriving newtype Hashable deriving newtype Hashable
gitHashTomb :: GitHash
gitHashTomb = fromString "0000000000000000000000000000000000"
instance Serialise GitHash instance Serialise GitHash
instance IsString GitHash where instance IsString GitHash where