lfs endpoint discovery and caching in git-lfs special remote

This commit is contained in:
Joey Hess 2019-08-02 12:38:14 -04:00
parent 03a765909c
commit 6c1130a3bb
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 129 additions and 28 deletions

View file

@ -14,6 +14,7 @@
module Utility.GitLFS (
-- * transfer requests
TransferRequest(..),
TransferRequestOperation(..),
TransferAdapter(..),
TransferRequestObject(..),
startTransferRequest,
@ -303,24 +304,24 @@ parseSshDiscoverEndpointResponse resp = EndpointDiscovered <$> decode resp
-- | Guesses the LFS endpoint from the http url of a git remote.
--
-- https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md
guessEndpoint :: Url -> Maybe Endpoint
guessEndpoint remoteurl = do
uri <- URI.parseURI (T.unpack remoteurl)
let guessedpath
guessEndpoint :: URI.URI -> Maybe Endpoint
guessEndpoint uri = case URI.uriScheme uri of
"https:" -> Just endpoint
"http:" -> Just endpoint
_ -> Nothing
where
endpoint = EndpointURI $ uri
{ URI.uriScheme = "https"
, URI.uriPath = guessedpath
}
guessedpath
| ".git" `isSuffixOf` URI.uriPath uri =
URI.uriPath uri ++ "/info/lfs"
| ".git/" `isSuffixOf` URI.uriPath uri =
URI.uriPath uri ++ "info/lfs"
| otherwise = (droptrailing '/' (URI.uriPath uri)) ++ ".git/info/lfs"
let endpoint = EndpointURI $ uri
{ URI.uriScheme = "https"
, URI.uriPath = guessedpath
}
case URI.uriScheme uri of
"https:" -> Just endpoint
"http:" -> Just endpoint
_ -> Nothing
where
droptrailing c = reverse . dropWhile (== c) . reverse
-- | Makes a Request that will start the process of making a transfer to or