annexInsteadOf config

Added config `url.<base>.annexInsteadOf` corresponding to git's
`url.<base>.pushInsteadOf`, to configure the urls to use for accessing the
git-annex repositories on a server without needing to configure
remote.name.annexUrl in each repository.

While one use case for this would be rewriting urls to use annex+http,
I decided not to add any kind of special case for that. So while
git-annex p2phttp, when serving multiple repositories, needs an url
of eg "annex+http://example.com/git-annex/ for each of them, rewriting an
url like "https://example.com/git/foo/bar" with this config set to
"https://example.com/git/" will result in eg
"annex+http://example.com/git-annex/foo/bar", which p2phttp does not
support.

That seems better dealt with in either git-annex p2phttp or a http
middleware, rather than complicating the config with a special case for
annex+http.

Anyway, there are other use cases for this that don't involve annex+http.
This commit is contained in:
Joey Hess 2024-12-03 14:01:35 -04:00
parent 0404968d10
commit dd052dcba1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 79 additions and 41 deletions

View file

@ -98,8 +98,9 @@ locationField = Accepted "location"
list :: Bool -> Annex [Git.Repo]
list autoinit = do
c <- fromRepo Git.config
rs <- mapM (tweakurl c) =<< Annex.getGitRemotes
cfg <- fromRepo Git.config
fullcfg <- fromRepo Git.fullconfig
rs <- mapM (tweakurl cfg fullcfg) =<< Annex.getGitRemotes
rs' <- mapM (configRead autoinit) (filter (not . isGitRemoteAnnex) rs)
proxies <- doQuietAction getProxies
if proxies == mempty
@ -108,17 +109,20 @@ list autoinit = do
proxied <- listProxied proxies rs'
return (proxied++rs')
where
tweakurl c r = do
tweakurl cfg fullcfg r = do
let n = fromJust $ Git.remoteName r
case getAnnexUrl r c of
Just url | not (isP2PHttpProtocolUrl url) ->
case getAnnexUrl r cfg fullcfg of
Just url | not (isP2PHttpProtocolUrl url) ->
inRepo $ \g -> Git.Construct.remoteNamed n $
Git.Construct.fromRemoteLocation url
False g
_ -> return r
getAnnexUrl :: Git.Repo -> M.Map Git.ConfigKey Git.ConfigValue -> Maybe String
getAnnexUrl r c = Git.fromConfigValue <$> M.lookup (annexUrlConfigKey r) c
getAnnexUrl :: Git.Repo -> Git.RepoConfig -> Git.RepoFullConfig -> Maybe String
getAnnexUrl r cfg fullcfg =
(Git.fromConfigValue <$> M.lookup (annexUrlConfigKey r) cfg)
<|>
annexInsteadOfUrl fullcfg (Git.repoLocation r)
annexUrlConfigKey :: Git.Repo -> Git.ConfigKey
annexUrlConfigKey r = remoteConfig r "annexurl"