ByteString Ref continued

Several nice speed wins I think.

At 340/633 files converted.
This commit is contained in:
Joey Hess 2020-04-07 13:27:11 -04:00
parent d5d8259937
commit 6c81e0c8f1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
16 changed files with 124 additions and 99 deletions

View file

@ -232,7 +232,7 @@ getAllRefs r = getAllRefs' (fromRawFilePath (localGitDir r) </> "refs")
getAllRefs' :: FilePath -> IO [Ref]
getAllRefs' refdir = do
let topsegs = length (splitPath refdir) - 1
let toref = Ref . joinPath . drop topsegs . splitPath
let toref = Ref . encodeBS' . joinPath . drop topsegs . splitPath
map toref <$> dirContentsRecursive refdir
explodePackedRefsFile :: Repo -> IO ()
@ -257,8 +257,8 @@ packedRefsFile r = fromRawFilePath (localGitDir r) </> "packed-refs"
parsePacked :: String -> Maybe (Sha, Ref)
parsePacked l = case words l of
(sha:ref:[])
| isJust (extractSha sha) && Ref.legal True ref ->
Just (Ref sha, Ref ref)
| isJust (extractSha (encodeBS' sha)) && Ref.legal True ref ->
Just (Ref (encodeBS' sha), Ref (encodeBS' ref))
_ -> Nothing
{- git-branch -d cannot be used to remove a branch that is directly
@ -279,13 +279,13 @@ findUncorruptedCommit missing goodcommits branch r = do
if ok
then return (Just branch, goodcommits')
else do
(ls, cleanup) <- pipeNullSplit
(ls, cleanup) <- pipeNullSplit'
[ Param "log"
, Param "-z"
, Param "--format=%H"
, Param (fromRef branch)
] r
let branchshas = catMaybes $ map (extractSha . decodeBL) ls
let branchshas = catMaybes $ map extractSha ls
reflogshas <- RefLog.get branch r
-- XXX Could try a bit harder here, and look
-- for uncorrupted old commits in branches in the
@ -328,8 +328,8 @@ verifyCommit missing goodcommits commit r
where
parse l = case words l of
(commitsha:treesha:[]) -> (,)
<$> extractSha commitsha
<*> extractSha treesha
<$> extractSha (encodeBS' commitsha)
<*> extractSha (encodeBS' treesha)
_ -> Nothing
check [] = return True
check ((c, t):rest)
@ -448,7 +448,8 @@ preRepair g = do
void $ tryIO $ allowWrite f
where
headfile = fromRawFilePath (localGitDir g) </> "HEAD"
validhead s = "ref: refs/" `isPrefixOf` s || isJust (extractSha s)
validhead s = "ref: refs/" `isPrefixOf` s
|| isJust (extractSha (encodeBS' s))
{- Put it all together. -}
runRepair :: (Ref -> Bool) -> Bool -> Repo -> IO (Bool, [Branch])