refix bug in a better way

Always run Git.Config.store, so when the git config gets reloaded,
the override gets re-added to it, and changeGitRepo then calls extractGitConfig
on it and sees the annex.* settings from the override.

Remove any prior occurance of -c v and add it to the end. This way,
-c foo=1 -c foo=2 -c foo=1 will pass -c foo=1 to git, rather than -c foo=2

Note that, if git had some multiline config that got built up by
multiple -c's, this would not work still. But it never worked because
before the bug got fixed in the first place, the -c value was repeated
many times, so the multivalue thing would have been wrong. I don't think
-c can be used with multiline configs anyway, though git-config does
talk about them?
This commit is contained in:
Joey Hess 2020-07-02 13:32:33 -04:00
parent ec0f8a6e74
commit f912f8e5fd
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 38 additions and 5 deletions

View file

@ -31,6 +31,7 @@ module Annex (
overrideGitConfig, overrideGitConfig,
changeGitRepo, changeGitRepo,
adjustGitRepo, adjustGitRepo,
addGitConfigOverride,
getRemoteGitConfig, getRemoteGitConfig,
withCurrentState, withCurrentState,
changeDirectory, changeDirectory,
@ -338,6 +339,21 @@ adjustGitRepo a = do
changeState $ \s -> s { repoadjustment = \r -> repoadjustment s r >>= a } changeState $ \s -> s { repoadjustment = \r -> repoadjustment s r >>= a }
changeGitRepo =<< gitRepo changeGitRepo =<< gitRepo
{- Adds git config setting, like "foo=bar". It will be passed with -c
- to git processes. The config setting is also recorded in the repo,
- and the GitConfig is updated. -}
addGitConfigOverride :: String -> Annex ()
addGitConfigOverride v = adjustGitRepo $ \r ->
Git.Config.store (encodeBS' v) Git.Config.ConfigList $
r { Git.gitGlobalOpts = go (Git.gitGlobalOpts r) }
where
-- Remove any prior occurrance of the setting to avoid
-- building up many of them when the adjustment is run repeatedly,
-- and add the setting to the end.
go [] = [Param "-c", Param v]
go (Param "-c": Param v':rest) | v' == v = go rest
go (c:rest) = c : go rest
{- Changing the git Repo data also involves re-extracting its GitConfig. -} {- Changing the git Repo data also involves re-extracting its GitConfig. -}
changeGitRepo :: Git.Repo -> Annex () changeGitRepo :: Git.Repo -> Annex ()
changeGitRepo r = do changeGitRepo r = do

View file

@ -17,8 +17,8 @@ git-annex (8.20200618) UNRELEASED; urgency=medium
which allows dropping from other special remotes in some situations which allows dropping from other special remotes in some situations
where it was not possible before. where it was not possible before.
S3 (with versioning=yes), git-lfs, tahoe S3 (with versioning=yes), git-lfs, tahoe
* Fix reversion that broke passing git configs with -c. * Fix reversion that broke passing annex.* and remote.*.annex-*
(Since version 8.20200330.) git configs with -c. (Since version 8.20200330.)
-- Joey Hess <id@joeyh.name> Thu, 18 Jun 2020 12:21:14 -0400 -- Joey Hess <id@joeyh.name> Thu, 18 Jun 2020 12:21:14 -0400

View file

@ -94,9 +94,7 @@ gitAnnexGlobalOptions = commonGlobalOptions ++
where where
setnumcopies n = Annex.changeState $ \s -> s { Annex.forcenumcopies = Just $ NumCopies n } setnumcopies n = Annex.changeState $ \s -> s { Annex.forcenumcopies = Just $ NumCopies n }
setuseragent v = Annex.changeState $ \s -> s { Annex.useragent = Just v } setuseragent v = Annex.changeState $ \s -> s { Annex.useragent = Just v }
setgitconfig v = Annex.adjustGitRepo $ \r -> setgitconfig v = Annex.addGitConfigOverride v
Git.Config.store (encodeBS' v) Git.Config.ConfigList $
r { gitGlobalOpts = gitGlobalOpts r ++ [Param "-c", Param v] }
setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v } setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v }
{- Parser that accepts all non-option params. -} {- Parser that accepts all non-option params. -}

View file

@ -51,3 +51,19 @@ worth filing in case there's a simple fix.
> I don't currently understand why, but that prevented the value getting > I don't currently understand why, but that prevented the value getting
> added. > added.
> --[[Joey]] > --[[Joey]]
> > Huh, with that commit's patch, the option is passed to all calls to
> > git.. But not to the call to ssh.
> >
> > Ah.. remoteAnnexSshOptions is populated by parsing the git config,
> > and is what gets passed to ssh. The patch though made it not call
> > Git.Config.Store, so when the git config has been reloaded, it loses
> > the -c config.
> >
> > Also, I notice that c8fec6ab0 had a second bug:
> > If -c foo=1 -c foo=2 -c foo=1 were passed, it would
> > add the first and second, but not add the third.
> >
> > I was really not at even 10% back in March. For obvious reasons.
> >
> > Ok, all fixed, the right way this time. [[done]] --[[Joey]]

View file

@ -45,3 +45,6 @@ dropped, but I haven't made any progress yet.
[[!meta author=kyle]] [[!meta author=kyle]]
[[!tag projects/datalad]] [[!tag projects/datalad]]
> [[fixed|done]] (also re-fixed the original bug in a better way)
> --[[Joey]]