1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Filter out blob paths that do not exist

This commit is contained in:
Timothy Clem 2017-03-15 12:38:41 -07:00
parent 04ecf13120
commit 9eba1e812b

View File

@ -61,30 +61,29 @@ instance ToJSON ParseJSON where
toJSON IndexProgram{..} = object [ "filePath" .= filePath, "programNodes" .= programNodes ]
sourceBlobs :: Arguments -> Text -> IO [SourceBlob]
sourceBlobs Arguments{..} commitSha' =
withRepository lgFactory gitDir $ do
sourceBlobs Arguments{..} commitSha' = do
maybeBlobs <- withRepository lgFactory gitDir $ do
repo <- getRepository
object <- parseObjOid commitSha'
commit <- lookupCommit object
tree <- lookupTree (commitTree commit)
lift $ runReaderT (getBlobs tree) repo
lift $ runReaderT (sequence $ fmap (toSourceBlob tree) filePaths) repo
pure $ catMaybes maybeBlobs
where
toSourceBlob :: Git.Tree LgRepo -> FilePath -> ReaderT LgRepo IO SourceBlob
getBlobs tree = traverse (toSourceBlob tree) filePaths
toSourceBlob :: Git.Tree LgRepo -> FilePath -> ReaderT LgRepo IO (Maybe SourceBlob)
toSourceBlob tree filePath = do
entry <- treeEntry tree (toS filePath)
(bytestring, oid, mode) <- case entry of
case entry of
Just (BlobEntry entryOid entryKind) -> do
blob <- lookupBlob entryOid
s <- blobToByteString blob
bytestring <- blobToByteString blob
let oid = renderObjOid $ blobOid blob
pure (s, oid, Just entryKind)
Nothing -> pure (mempty, mempty, Nothing)
_ -> pure (mempty, mempty, Nothing)
s <- liftIO $ transcode bytestring
lift $ pure $ SourceBlob s (toS oid) filePath (toSourceKind <$> mode)
s <- liftIO $ transcode bytestring
pure . Just $ SourceBlob s (toS oid) filePath (Just (toSourceKind entryKind))
_ -> pure Nothing
where
toSourceKind :: Git.BlobKind -> SourceKind
toSourceKind (Git.PlainBlob mode) = Source.PlainBlob mode