mirror of
https://github.com/github/semantic.git
synced 2024-11-25 21:43:07 +03:00
Capture and carry around blob oid
This commit is contained in:
parent
275f45d190
commit
23920a04cd
@ -33,6 +33,7 @@ data Blob = Blob
|
||||
{ blobSource :: Source -- ^ The UTF-8 encoded source text of the blob.
|
||||
, blobPath :: FilePath -- ^ The file path to the blob.
|
||||
, blobLanguage :: Language -- ^ The language of this blob.
|
||||
, blobOid :: Text -- ^ Git OID for this blob, mempty if blob is not from a git db.
|
||||
}
|
||||
deriving (Show, Eq, Generic)
|
||||
|
||||
@ -49,12 +50,12 @@ nullBlob :: Blob -> Bool
|
||||
nullBlob Blob{..} = nullSource blobSource
|
||||
|
||||
sourceBlob :: FilePath -> Language -> Source -> Blob
|
||||
sourceBlob filepath language source = Blob source filepath language
|
||||
sourceBlob filepath language source = Blob source filepath language mempty
|
||||
|
||||
inferringLanguage :: Source -> FilePath -> Language -> Blob
|
||||
inferringLanguage src pth lang
|
||||
| knownLanguage lang = Blob src pth lang
|
||||
| otherwise = Blob src pth (languageForFilePath pth)
|
||||
| knownLanguage lang = Blob src pth lang mempty
|
||||
| otherwise = Blob src pth (languageForFilePath pth) mempty
|
||||
|
||||
decodeBlobs :: BL.ByteString -> Either String [Blob]
|
||||
decodeBlobs = fmap blobs <$> eitherDecode
|
||||
|
@ -32,7 +32,7 @@ file path = File path (languageForFilePath path)
|
||||
-- This is kind of a wart; Blob and File should be two views of
|
||||
-- the same higher-kinded datatype.
|
||||
toFile :: Blob -> File
|
||||
toFile (Blob _ p l) = File p l
|
||||
toFile (Blob _ p l _) = File p l
|
||||
|
||||
-- | Read a utf8-encoded file to a 'Blob'.
|
||||
readBlobFromFile :: forall m. MonadIO m => File -> m (Maybe Blob)
|
||||
|
@ -98,7 +98,7 @@ instance APIBridge T.Text Data.Language where
|
||||
instance APIBridge API.Blob Data.Blob where
|
||||
bridging = iso apiBlobToBlob blobToApiBlob where
|
||||
blobToApiBlob Data.Blob{..} = API.Blob (toText blobSource) (T.pack blobPath) (bridging # blobLanguage)
|
||||
apiBlobToBlob API.Blob{..} = Data.Blob (fromText content) (T.unpack path) (language ^. bridging)
|
||||
apiBlobToBlob API.Blob{..} = Data.Blob (fromText content) (T.unpack path) (language ^. bridging) mempty
|
||||
|
||||
|
||||
instance APIConvert API.BlobPair Data.BlobPair where
|
||||
|
Loading…
Reference in New Issue
Block a user