From f912f8e5fd44a52fa19d74fabe649e4000e9759a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 2 Jul 2020 13:32:33 -0400 Subject: [PATCH] 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? --- Annex.hs | 16 ++++++++++++++++ CHANGELOG | 4 ++-- CmdLine/GitAnnex/Options.hs | 4 +--- ...Some_calls_to_git_repeat_--config_values.mdwn | 16 ++++++++++++++++ ...nex-ssh-options_dropped_since_8.20200330.mdwn | 3 +++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Annex.hs b/Annex.hs index 96d55452ee..64ab9c0d74 100644 --- a/Annex.hs +++ b/Annex.hs @@ -31,6 +31,7 @@ module Annex ( overrideGitConfig, changeGitRepo, adjustGitRepo, + addGitConfigOverride, getRemoteGitConfig, withCurrentState, changeDirectory, @@ -338,6 +339,21 @@ adjustGitRepo a = do changeState $ \s -> s { repoadjustment = \r -> repoadjustment s r >>= a } 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. -} changeGitRepo :: Git.Repo -> Annex () changeGitRepo r = do diff --git a/CHANGELOG b/CHANGELOG index 6cddc4ea92..e6ea084c91 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,8 +17,8 @@ git-annex (8.20200618) UNRELEASED; urgency=medium which allows dropping from other special remotes in some situations where it was not possible before. S3 (with versioning=yes), git-lfs, tahoe - * Fix reversion that broke passing git configs with -c. - (Since version 8.20200330.) + * Fix reversion that broke passing annex.* and remote.*.annex-* + git configs with -c. (Since version 8.20200330.) -- Joey Hess Thu, 18 Jun 2020 12:21:14 -0400 diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 6bb2285578..00b0befced 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -94,9 +94,7 @@ gitAnnexGlobalOptions = commonGlobalOptions ++ where setnumcopies n = Annex.changeState $ \s -> s { Annex.forcenumcopies = Just $ NumCopies n } setuseragent v = Annex.changeState $ \s -> s { Annex.useragent = Just v } - setgitconfig v = Annex.adjustGitRepo $ \r -> - Git.Config.store (encodeBS' v) Git.Config.ConfigList $ - r { gitGlobalOpts = gitGlobalOpts r ++ [Param "-c", Param v] } + setgitconfig v = Annex.addGitConfigOverride v setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v } {- Parser that accepts all non-option params. -} diff --git a/doc/bugs/Some_calls_to_git_repeat_--config_values.mdwn b/doc/bugs/Some_calls_to_git_repeat_--config_values.mdwn index 09ebf715da..370031ef6e 100644 --- a/doc/bugs/Some_calls_to_git_repeat_--config_values.mdwn +++ b/doc/bugs/Some_calls_to_git_repeat_--config_values.mdwn @@ -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 > added. > --[[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]] diff --git a/doc/bugs/annex-ssh-options_dropped_since_8.20200330.mdwn b/doc/bugs/annex-ssh-options_dropped_since_8.20200330.mdwn index 64a0214c09..084eacd001 100644 --- a/doc/bugs/annex-ssh-options_dropped_since_8.20200330.mdwn +++ b/doc/bugs/annex-ssh-options_dropped_since_8.20200330.mdwn @@ -45,3 +45,6 @@ dropped, but I haven't made any progress yet. [[!meta author=kyle]] [[!tag projects/datalad]] + +> [[fixed|done]] (also re-fixed the original bug in a better way) +> --[[Joey]]