Skip to content

Conversation

mstv
Copy link
Member

@mstv mstv commented Feb 17, 2025

Fixes #4389

Proposed changes

  • Remove IConfigFileSettings including its implementation so that GE does not rewrite git config files any longer
  • Instead, use "git config" commands (with caching) for reading and writing git config settings
    using IGitModule:
    • GetEffectiveSetting
    • GetEffectiveSetting<T>
    • GetSettings(string setting) (for multi-value settings, kept existing sub-optimal name)
    • SetSetting
    • UnsetSetting
  • Provide new API in IGitModule:
    • GetAllLocalSettings
    • InvalidateGitSettings
    • RemoveConfigSection
  • Remove API:
    • from IGitModule:
      • GetSetting (kept, but declared "deprecated", redirected to GetEffectiveSetting)
      • GetSetting<T> (unused)
      • GetGitSetting
      • GetEffectiveGitSetting
      • EffectiveConfigFile
      • LocalConfigFile
    • fromIGitRef
      • GetTrackingRemote & GetMergeWith (redundant to existing properties)

(Review commit by commit is recommended.)

Screenshots

N/A

Test methodology

  • existing tests (with adaptations)
  • tested with WSL

Please do not squash merge


✒️ I contribute this code under The Developer Certificate of Origin.

@mstv mstv self-assigned this Feb 17, 2025
@mstv mstv marked this pull request as draft February 17, 2025 21:28
@mstv mstv force-pushed the git_config branch 5 times, most recently from db9f16c to f1bc5c2 Compare February 25, 2025 17:24
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
and declare EffectiveConfigFile read-only & private
and fixup signature of IGitModule.PullCmd

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
because it brings insignificant speedup in its current form

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
and SetGitSetting over using LocalConfigFile

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
with EffectiveGitConfigSettings
and remove IGitModule.GetGitSetting & GetEffectiveGitSetting

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
as replacement for IConfigFileSettings.GetValues

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
using extended IGitConfigSettingsGetter

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
mstv added a commit to mstv/gitextensions that referenced this pull request Feb 25, 2025
@mstv mstv force-pushed the git_config branch 2 times, most recently from b3e54f1 to daa8a0d Compare March 3, 2025 17:50
@mstv mstv force-pushed the git_config branch 7 times, most recently from b1e055c to 1473e00 Compare March 10, 2025 22:27
mstv added a commit to mstv/gitextensions that referenced this pull request Mar 11, 2025
and SetGitSetting over using LocalConfigFile

Refs: gitextensions#12201
mstv added a commit to mstv/gitextensions that referenced this pull request Mar 31, 2025
mstv added a commit to mstv/gitextensions that referenced this pull request Mar 31, 2025
mstv added a commit to mstv/gitextensions that referenced this pull request Mar 31, 2025
@mstv mstv requested a review from Copilot April 6, 2025 15:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/app/GitCommands/Settings/GitConfigSettings.cs:145

  • The use of the null-forgiving operator on 'firstValue' assumes it is non-null. Consider adding a safeguard or verifying that 'firstValue' can never be null to avoid potential runtime issues.
_multiValueSettings.Add(name, [firstValue!, value]);

src/app/GitCommands/Git/Commands.Execution.cs:87

  • The introduction of the append flag in SetGitSetting alters the command line arguments for git config settings. Verify that this change aligns with the intended behavior and that all callers supply the appropriate value for the new parameter.
{ isSet && append, newSyntax ? "--append" : "--add" },

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a deep review, but I think this is a good change.
How good is the test coverage?

@vbjay
Copy link
Contributor

vbjay commented Apr 28, 2025

More a point of concern to keep an eye out for is your (with caching) point.

Maybe a test could be added

  1. Generate random number
  2. git config test.number number here
  3. Read test.number
  4. Confirm got expected value
  5. New number and save to config
  6. Read one more time and confirm not cached value.

My concern is the cache may hold onto values that have been changed and annoy people. I love the use of git config. Maybe a watcher on the git config files to invalidate the cache may be needed.

@mstv
Copy link
Member Author

mstv commented Apr 28, 2025

My concern is the cache may hold onto values that have been changed and annoy people.

There are only two locations in GE which change settings:

  • GitModule.SetGitSetting, which is used by all related IGitModule functions.
  • GitConfigSettingsSet.Save is used by the settings dialog.

Both invalidate all sibling caches.
If this would not work well, a lot of integration tests would not pass.

Though you are right. I need to invalidate the caches of GitModule yet after closing the settings dialog.

Maybe a watcher on the git config files to invalidate the cache may be needed.

This would become complex (think of "include") up to not feasible (FileWatcher does not work for WSL).
I have chosen a simple approach, which should be clear and good enough for the user (but does not and does not need to address the invalidation after the settings dialog).

protected override void OnApplicationActivated()
{
base.OnApplicationActivated();
if (_isReactivation)
{
Module.InvalidateGitSettings();
}
else
{
_isReactivation = true;
}
}
.

@vbjay
Copy link
Contributor

vbjay commented Apr 29, 2025

Makes sense. Then maybe a force refresh config button to handle the case of config being altered outside of app.

@mstv mstv removed the status: ready label May 2, 2025
@mstv mstv added this to the v5.3 milestone May 2, 2025
mstv added 11 commits May 2, 2025 14:37
and declare EffectiveConfigFile read-only & private
and fixup signature of IGitModule.PullCmd

Refs: gitextensions#12201
because it brings insignificant speedup in its current form

Refs: gitextensions#12201
and SetGitSetting over using LocalConfigFile

Refs: gitextensions#12201
with EffectiveGitConfigSettings
and remove IGitModule.GetGitSetting & GetEffectiveGitSetting

Refs: gitextensions#12201
as replacement for IConfigFileSettings.GetValues

Refs: gitextensions#12201
using extended IGitConfigSettingsGetter

Refs: gitextensions#12201
@mstv mstv merged commit be7a870 into gitextensions:master May 2, 2025
4 checks passed
@mstv mstv deleted the git_config branch May 2, 2025 16:03
@mstv
Copy link
Member Author

mstv commented May 2, 2025

Then maybe a force refresh config button to handle the case of config being altered outside of app.

Just hit the Windows key twice (in order to trigger OnApplicationActivated) if one really changed git config without GE but not leaving GE.

@vbjay
Copy link
Contributor

vbjay commented May 4, 2025

I'm thinking more along the lines of say Visual Studio changes a config or whatnot. The app calls on git config to get needed settings often and if stale and used cache it will be out of sync. I'd imagine it would be a pain to load settings page to force invalidating cache. If cache had a clock on it that self invalidates after 10 minutes then ok. I'm just saying the cache invalidation needs to be considered.

If ge loads settings at noon and knows x config. If visual studio changes at 12:05 and you do more in ge when does ge catch up to current config is my point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitExtensions rewrites .gitconfig
3 participants