Skip to content

Conversation

RussKie
Copy link
Member

@RussKie RussKie commented Oct 12, 2023

Proposed changes

This PR removes the direct dependency on the concrete implementation of GitModule and replaces all callsites with the IGitModule interface. The change is somewhat crude to made the code compile. IGitModule interface has been updated with the required signature (almost) without any consideration on the quality of the API it provides.

This PR is about setting the foundation for using the abstractions, and the follow up work will concentrate on individual aspects such as

  • cleaning (or "beautifying") the interface,
  • adding xml-docs,
  • moving the abstractions to GitExtensions.Extensibility project and introducing the dependency on the said project, etc.

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


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

@ghost ghost assigned RussKie Oct 12, 2023
@RussKie RussKie changed the title Use IGitModule `in signatures Use IGitModule in signatures Oct 12, 2023
@@ -4,7 +4,7 @@

namespace GitCommands.Config
{
public class ConfigFile
public class ConfigFile : ISubmodulesConfigFile
Copy link
Member

Choose a reason for hiding this comment

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

❓ I read this as "Every config file is a submodules config file". This feels wrong.
The interface ISubmodulesConfigFile does not contain anything submodule-specific at a first glance.

Copy link
Member

Choose a reason for hiding this comment

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

It is the data in .gitmodules
The interface needs some comments...

Copy link
Member

Choose a reason for hiding this comment

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

I have added IConfigFile: ISubmodulesConfigFile and synchronized the method name GetSubmodulesConfigFile with the interface name in c3418e3 (after resolving the MC).

@gerhardol

This comment was marked as resolved.

@RussKie
Copy link
Member Author

RussKie commented Oct 15, 2023

This PR is about removing direct use of GitModule implementation and using IGitModule interface instead. So this PR will create some churn.

I found (and keep finding) implementations in GitModule that either have no real relation to git module or have a single callsite.
This PR isn't meant to make everything perfect, this is a mere first step to getting our head around what GitModule contains. It will also enable us to have a discussion what should be on IGitModule interface and what should be moved to other interfaces (e.g., submodule related implementations can probably be all grouped together under an interface).

@RussKie RussKie force-pushed the use_IGitModule_in_signatures branch 2 times, most recently from 4354a2d to 90ed824 Compare November 18, 2023 05:58
Comment on lines 404 to 437
CancellationToken cancellationToken = _branchLoaderSequence.Next();
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await TaskScheduler.Default;

RemoteActionResult<IReadOnlyList<IGitRef>> branchList;

IReadOnlyList<IGitRef> refs = Module.GetRemoteServerRefs(from, false, true, out string? errorOutput, cancellationToken);

if (string.IsNullOrEmpty(errorOutput))
{
branchList = new(result: refs, authenticationFail: false, hostKeyFail: false);
}
else if (errorOutput.Contains("FATAL ERROR") && errorOutput.Contains("authentication"))
{
// If the authentication failed because of a missing key, ask the user to supply one.
branchList = new(result: null, authenticationFail: true, hostKeyFail: false);
}
else if (errorOutput.Contains("the server's host key is not cached in the registry", StringComparison.InvariantCultureIgnoreCase))
{
branchList = new(result: null, authenticationFail: false, hostKeyFail: true);
}
else
{
throw new NotImplementedException();
}

await this.SwitchToMainThreadAsync(cancellationToken);
if (!cancellationToken.IsCancellationRequested)
{
UpdateBranches(branchList);
}
}).FileAndForget();
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the implementation from GitModule.

@RussKie RussKie requested a review from pmiossec November 18, 2023 06:57
@RussKie RussKie marked this pull request as ready for review November 18, 2023 06:57
@RussKie
Copy link
Member Author

RussKie commented Nov 18, 2023

I believe this is largely ready for review and for being taken in.

@RussKie
Copy link
Member Author

RussKie commented Nov 22, 2023

Friendly ping @gerhardol @mstv @pmiossec

@mstv

This comment was marked as resolved.

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

I need to continue the review of the middle commit "Compile" yet.
No comments on the first and third commits.

@@ -4,7 +4,7 @@

namespace GitCommands.Config
{
public class ConfigFile
public class ConfigFile : ISubmodulesConfigFile
Copy link
Member

Choose a reason for hiding this comment

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

I have added IConfigFile: ISubmodulesConfigFile and synchronized the method name GetSubmodulesConfigFile with the interface name in c3418e3 (after resolving the MC).

RussKie referenced this pull request Nov 23, 2023
that return the checked out branch
or the commit hash if detached HEAD.

+ a little less misleading help
+ Invert `GetSelectedBranch()` boolean param logic from `setDefaultIfEmpty` to `emptyIfDetached`
@mstv mstv force-pushed the use_IGitModule_in_signatures branch from 7eef38d to cf5b521 Compare November 23, 2023 21:04
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

I force pushed by mistake because I forgot to update the tracking reference.

@RussKie
Copy link
Member Author

RussKie commented Nov 23, 2023

I force pushed by mistake because I forgot to update the tracking reference.

All good

@RussKie RussKie force-pushed the use_IGitModule_in_signatures branch from cf5b521 to e5e5e38 Compare November 23, 2023 23:03
@RussKie
Copy link
Member Author

RussKie commented Nov 23, 2023

@mstv I believe I address the feedback. Thank you for your reviews.

Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

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

+1 only brief review

@RussKie RussKie force-pushed the use_IGitModule_in_signatures branch 2 times, most recently from 4d754ac to 7773123 Compare November 26, 2023 08:43
@mstv
Copy link
Member

mstv commented Nov 26, 2023

RussKie force-pushed

still MC

@RussKie
Copy link
Member Author

RussKie commented Nov 26, 2023 via email

@mstv mstv force-pushed the use_IGitModule_in_signatures branch from 7773123 to be47ed9 Compare November 26, 2023 11:45
@RussKie
Copy link
Member Author

RussKie commented Nov 26, 2023

Thank you @mstv for rebasing this and getting the build green again.

Is there anything else outstanding that I missed? Or can we get this merged?

@gerhardol
Copy link
Member

Or can we get this merged?

fine for me

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.

3 participants