diff --git a/GitCommands/Config/ConfigFile.cs b/GitCommands/Config/ConfigFile.cs index 833f1d2a1eb..821ed9c7566 100644 --- a/GitCommands/Config/ConfigFile.cs +++ b/GitCommands/Config/ConfigFile.cs @@ -10,16 +10,16 @@ namespace GitCommands.Config { public class ConfigFile { - public string FileName { get; } + private readonly List _configSections = new List(); + public string FileName { get; } public bool Local { get; } public ConfigFile(string fileName, bool local) { - ConfigSections = new List(); Local = local; - FileName = fileName; + try { Load(); @@ -31,7 +31,7 @@ public ConfigFile(string fileName, bool local) } } - public IList ConfigSections { get; } + public IReadOnlyList ConfigSections => _configSections; public IEnumerable GetConfigSections(string sectionName) { @@ -214,7 +214,7 @@ public string GetPathValue(string setting) return GetStringValue(setting); } - public IList GetValues(string setting) + public IReadOnlyList GetValues(string setting) { var keyIndex = FindAndCheckKeyIndex(setting); @@ -249,7 +249,7 @@ public IConfigSection FindOrCreateConfigSection(string name) if (result == null) { result = new ConfigSection(name, true); - ConfigSections.Add(result); + _configSections.Add(result); } return result; @@ -262,7 +262,7 @@ public void AddConfigSection(IConfigSection configSection) throw new ArgumentException("Can not add a section that already exists: " + configSection.SectionName); } - ConfigSections.Add(configSection); + _configSections.Add(configSection); } public void RemoveConfigSection(string configSectionName) @@ -274,7 +274,7 @@ public void RemoveConfigSection(string configSectionName) return; } - ConfigSections.Remove(configSection); + _configSections.Remove(configSection); } public IConfigSection FindConfigSection(string name) @@ -336,7 +336,7 @@ private void NewSection() if (_section == null) { _section = new ConfigSection(sectionName, false); - _configFile.ConfigSections.Add(_section); + _configFile._configSections.Add(_section); } } diff --git a/GitCommands/Config/ConfigSection.cs b/GitCommands/Config/ConfigSection.cs index 06d95a67903..865ba1ee760 100644 --- a/GitCommands/Config/ConfigSection.cs +++ b/GitCommands/Config/ConfigSection.cs @@ -18,11 +18,11 @@ namespace GitCommands.Config /// public class ConfigSection : IConfigSection { - private readonly IDictionary> _configKeys; + private readonly IDictionary> _configKeys; internal ConfigSection(string name, bool forceCaseSensitive) { - _configKeys = new Dictionary>(StringComparer.OrdinalIgnoreCase); + _configKeys = new Dictionary>(StringComparer.OrdinalIgnoreCase); if (name.Contains("\"")) { @@ -73,9 +73,9 @@ public static string FixPath(string path) return path.ToPosixPath(); } - public IDictionary> AsDictionary() + public IDictionary> AsDictionary() { - return _configKeys.ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase); + return _configKeys.ToDictionary(kv => kv.Key, kv => (IReadOnlyList)kv.Value, StringComparer.OrdinalIgnoreCase); } public bool HasValue(string key) @@ -128,7 +128,7 @@ public string GetValue(string key, string defaultValue) return defaultValue; } - public IList GetValues(string key) + public IReadOnlyList GetValues(string key) { return _configKeys.ContainsKey(key) ? _configKeys[key] : new List(); } diff --git a/GitCommands/ExternalLinks/ConfiguredLinkDefinitionsProvider.cs b/GitCommands/ExternalLinks/ConfiguredLinkDefinitionsProvider.cs index c72704d7906..1258b8c0d38 100644 --- a/GitCommands/ExternalLinks/ConfiguredLinkDefinitionsProvider.cs +++ b/GitCommands/ExternalLinks/ConfiguredLinkDefinitionsProvider.cs @@ -13,7 +13,7 @@ public interface IConfiguredLinkDefinitionsProvider /// /// Loads all persisted external link definitions across all setting layers. /// - IList Get(RepoDistSettings settings); + IReadOnlyList Get(RepoDistSettings settings); } /// @@ -31,7 +31,7 @@ public ConfiguredLinkDefinitionsProvider(IExternalLinksLoader externalLinksLoade /// /// Loads all persisted external link definitions across all setting layers. /// - public IList Get(RepoDistSettings settings) + public IReadOnlyList Get(RepoDistSettings settings) { if (settings == null) { diff --git a/GitCommands/ExternalLinks/ExternalLinkRevisionParser.cs b/GitCommands/ExternalLinks/ExternalLinkRevisionParser.cs index ea330a3fd66..310c9bdda13 100644 --- a/GitCommands/ExternalLinks/ExternalLinkRevisionParser.cs +++ b/GitCommands/ExternalLinks/ExternalLinkRevisionParser.cs @@ -45,7 +45,7 @@ private static IEnumerable GetMatchingRemotes(ExternalLinkDefinition private IEnumerable ParseRemotes(ExternalLinkDefinition definition) { - IList allMatches = new List(); + var allMatches = new List(); if (definition.RemoteSearchPattern.IsNullOrWhiteSpace() || definition.RemoteSearchPatternRegex.Value == null) { @@ -53,7 +53,7 @@ private IEnumerable ParseRemotes(ExternalLinkDefinition definition) return allMatches; } - IList remoteUrls = new List(); + var remoteUrls = new List(); var remotes = _gitRemoteManager.LoadRemotes(false); var matchingRemotes = GetMatchingRemotes(definition, remotes); @@ -128,7 +128,7 @@ private static IEnumerable ParseRevisionPart(GitRevision revision, yield break; } - IList allMatches = new List(); + var allMatches = new List(); MatchCollection matches = definition.SearchPatternRegex.Value.Matches(part); for (var i = 0; i < matches.Count; i++) diff --git a/GitCommands/ExternalLinks/ExternalLinksLoader.cs b/GitCommands/ExternalLinks/ExternalLinksLoader.cs index 9aefd9527a8..fa6e4c14473 100644 --- a/GitCommands/ExternalLinks/ExternalLinksLoader.cs +++ b/GitCommands/ExternalLinks/ExternalLinksLoader.cs @@ -14,12 +14,12 @@ public interface IExternalLinksLoader /// /// Loads external link definitions from the settings. /// - IList Load(RepoDistSettings settings); + IReadOnlyList Load(RepoDistSettings settings); /// /// Saves the provided external link definitions to the settings. /// - void Save(RepoDistSettings settings, IList definitions); + void Save(RepoDistSettings settings, IReadOnlyList definitions); } public sealed class ExternalLinksLoader : IExternalLinksLoader @@ -29,7 +29,7 @@ public sealed class ExternalLinksLoader : IExternalLinksLoader /// /// Loads external link definitions from the settings. /// - public IList Load(RepoDistSettings settings) + public IReadOnlyList Load(RepoDistSettings settings) { var cachedSettings = new RepoDistSettings(null, settings.SettingsCache); var xml = cachedSettings.GetString(SettingName, null); @@ -39,7 +39,7 @@ public IList Load(RepoDistSettings settings) /// /// Saves the provided external link definitions to the settings. /// - public void Save(RepoDistSettings settings, IList definitions) + public void Save(RepoDistSettings settings, IReadOnlyList definitions) { try { @@ -68,7 +68,7 @@ public void Save(RepoDistSettings settings, IList defini } // TODO: refactor and outsource to the centralised SettingsSerialiser implementations. - private static IList LoadFromXmlString(string xmlString) + private static IReadOnlyList LoadFromXmlString(string xmlString) { if (string.IsNullOrWhiteSpace(xmlString)) { diff --git a/GitCommands/ExternalLinks/ExternalLinksManager.cs b/GitCommands/ExternalLinks/ExternalLinksManager.cs index 72307a1a2ef..808943768ae 100644 --- a/GitCommands/ExternalLinks/ExternalLinksManager.cs +++ b/GitCommands/ExternalLinks/ExternalLinksManager.cs @@ -11,12 +11,12 @@ public sealed class ExternalLinksManager private readonly RepoDistSettings _cachedSettings; private readonly ExternalLinksManager _lowerPriority; private readonly IExternalLinksLoader _externalLinksLoader = new ExternalLinksLoader(); - private readonly IList _definitions; + private readonly List _definitions; public ExternalLinksManager(RepoDistSettings settings) { _cachedSettings = new RepoDistSettings(null, settings.SettingsCache); - _definitions = _externalLinksLoader.Load(_cachedSettings); + _definitions = _externalLinksLoader.Load(_cachedSettings).ToList(); if (settings.LowerPriority != null) { @@ -64,10 +64,11 @@ public bool Contains(string definitionName) /// Loads all settings from all available levels. /// /// A collection of all available definitions. - public IList GetEffectiveSettings() + public IReadOnlyList GetEffectiveSettings() { - var effective = _definitions.Union(_lowerPriority?.GetEffectiveSettings() ?? Enumerable.Empty()).ToList(); - return effective.ToList(); + return _definitions + .Union(_lowerPriority?.GetEffectiveSettings() ?? Enumerable.Empty()) + .ToList(); } /// diff --git a/GitCommands/Git/GitCommandHelpers.cs b/GitCommands/Git/GitCommandHelpers.cs index 0e874ad2fb9..9033792787a 100644 --- a/GitCommands/Git/GitCommandHelpers.cs +++ b/GitCommands/Git/GitCommandHelpers.cs @@ -1095,7 +1095,7 @@ public static GitSubmoduleStatus GetSubmoduleStatus(string text, GitModule modul /* source: https://git-scm.com/docs/git-status */ - public static List GetAllChangedFilesFromString(IGitModule module, string statusString, bool fromDiff = false) + public static IReadOnlyList GetAllChangedFilesFromString(IGitModule module, string statusString, bool fromDiff = false) { var diffFiles = new List(); @@ -1130,7 +1130,7 @@ The file will have its original line endings in your working directory.*/ } // Doesn't work with removed submodules - IList submodules = module.GetSubmodulesLocalPaths(); + var submodules = module.GetSubmodulesLocalPaths(); // Split all files on '\0' (WE NEED ALL COMMANDS TO BE RUN WITH -z! THIS IS ALSO IMPORTANT FOR ENCODING ISSUES!) var files = trimmedStatus.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); diff --git a/GitCommands/Git/GitGpgController.cs b/GitCommands/Git/GitGpgController.cs index f5030dadbd9..891d0c68eab 100644 --- a/GitCommands/Git/GitGpgController.cs +++ b/GitCommands/Git/GitGpgController.cs @@ -230,7 +230,7 @@ private string GetTagVerificationMessage(IGitRef tagRef, bool raw = true) return module.RunGitCmd($"verify-tag {rawFlag} {tagName}"); } - private string EvaluateTagVerifyMessage(IList usefulTagRefs) + private string EvaluateTagVerifyMessage(IReadOnlyList usefulTagRefs) { if (usefulTagRefs.Count == 0) { diff --git a/GitCommands/Git/GitModule.cs b/GitCommands/Git/GitModule.cs index 8c5174efc45..26ca9b03bcd 100644 --- a/GitCommands/Git/GitModule.cs +++ b/GitCommands/Git/GitModule.cs @@ -445,7 +445,7 @@ public bool HasSubmodules() /// This approach is a faster than which /// invokes the git submodule command. /// - public IList GetSubmodulesLocalPaths(bool recursive = true) + public IReadOnlyList GetSubmodulesLocalPaths(bool recursive = true) { var submodules = GetSubmodulePaths(this); @@ -958,7 +958,7 @@ public List GetConflicts(string filename = "") return list; } - public IList GetSortedRefs() + public IReadOnlyList GetSortedRefs() { const string command = "for-each-ref --sort=-committerdate --sort=-taggerdate --format=\"%(refname)\" refs/"; @@ -1903,7 +1903,7 @@ public string ApplyPatch(string dir, string amCommand) } } - public string AssumeUnchangedFiles(IList files, bool assumeUnchanged, out bool wereErrors) + public string AssumeUnchangedFiles(IReadOnlyList files, bool assumeUnchanged, out bool wereErrors) { var output = ""; string error = ""; @@ -1927,7 +1927,7 @@ public string AssumeUnchangedFiles(IList files, bool assumeUnchan return output.Combine(Environment.NewLine, error); } - public string SkipWorktreeFiles(IList files, bool skipWorktree) + public string SkipWorktreeFiles(IReadOnlyList files, bool skipWorktree) { var output = ""; string error = ""; @@ -1950,7 +1950,7 @@ public string SkipWorktreeFiles(IList files, bool skipWorktree) return output.Combine(Environment.NewLine, error); } - public string StageFiles(IList files, out bool wereErrors) + public string StageFiles(IReadOnlyList files, out bool wereErrors) { var output = ""; string error = ""; @@ -1991,7 +1991,7 @@ public string StageFiles(IList files, out bool wereErrors) return output.Combine(Environment.NewLine, error); } - public string UnstageFiles(IList files) + public string UnstageFiles(IReadOnlyList files) { var output = ""; string error = ""; @@ -2092,12 +2092,12 @@ public bool InTheMiddleOfInteractiveRebase() return File.Exists(GetRebaseDir() + "git-rebase-todo"); } - public IList GetInteractiveRebasePatchFiles() + public IReadOnlyList GetInteractiveRebasePatchFiles() { string todoFile = GetRebaseDir() + "git-rebase-todo"; string[] todoCommits = File.Exists(todoFile) ? File.ReadAllText(todoFile).Trim().Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries) : null; - IList patchFiles = new List(); + var patchFiles = new List(); if (todoCommits != null) { @@ -2131,7 +2131,7 @@ public IList GetInteractiveRebasePatchFiles() return patchFiles; } - public IList GetRebasePatchFiles() + public IReadOnlyList GetRebasePatchFiles() { var patchFiles = new List(); @@ -2365,7 +2365,7 @@ public void SetPathSetting(string setting, string value) LocalConfigFile.SetPathValue(setting, value); } - public IList GetStashes() + public IReadOnlyList GetStashes() { var list = RunGitCmd("stash list").Split('\n'); @@ -2456,19 +2456,19 @@ public string GetDiffFilesText(string firstRevision, string secondRevision, bool return noCache ? RunGitCmd(cmd) : RunCacheableCmd(AppSettings.GitCommand, cmd, SystemEncoding); } - public List GetDiffFilesWithSubmodulesStatus(string firstRevision, string secondRevision) + public IReadOnlyList GetDiffFilesWithSubmodulesStatus(string firstRevision, string secondRevision) { var status = GetDiffFiles(firstRevision, secondRevision); GetSubmoduleStatus(status, firstRevision, secondRevision); return status; } - public List GetDiffFiles(string firstRevision, string secondRevision, bool noCache = false) + public IReadOnlyList GetDiffFiles(string firstRevision, string secondRevision, bool noCache = false) { noCache = noCache || firstRevision.IsArtificial() || secondRevision.IsArtificial(); string cmd = DiffCommandWithStandardArgs + "-M -C -z --name-status " + _revisionDiffProvider.Get(firstRevision, secondRevision); string result = noCache ? RunGitCmd(cmd) : RunCacheableCmd(AppSettings.GitCommand, cmd, SystemEncoding); - var resultCollection = GitCommandHelpers.GetAllChangedFilesFromString(this, result, true); + var resultCollection = GitCommandHelpers.GetAllChangedFilesFromString(this, result, true).ToList(); if (firstRevision == GitRevision.UnstagedGuid || secondRevision == GitRevision.UnstagedGuid) { // For unstaged the untracked must be added too @@ -2492,9 +2492,9 @@ public List GetDiffFiles(string firstRevision, string secondRevis return resultCollection; } - public IList GetStashDiffFiles(string stashName) + public IReadOnlyList GetStashDiffFiles(string stashName) { - var resultCollection = GetDiffFiles(stashName + "^", stashName, true); + var resultCollection = GetDiffFiles(stashName + "^", stashName, true).ToList(); // shows untracked files string untrackedTreeHash = RunGitCmd("log " + stashName + "^3 --pretty=format:\"%T\" --max-count=1"); @@ -2507,7 +2507,7 @@ public IList GetStashDiffFiles(string stashName) return resultCollection; } - public IList GetTreeFiles(string treeGuid, bool full) + public IReadOnlyList GetTreeFiles(string treeGuid, bool full) { var tree = GetTree(treeGuid, full); @@ -2536,12 +2536,12 @@ public IList GetTreeFiles(string treeGuid, bool full) return list; } - public IList GetAllChangedFiles(bool excludeIgnoredFiles = true, + public IReadOnlyList GetAllChangedFiles(bool excludeIgnoredFiles = true, bool excludeAssumeUnchangedFiles = true, bool excludeSkipWorktreeFiles = true, UntrackedFilesMode untrackedFiles = UntrackedFilesMode.Default) { var status = RunGitCmd(GitCommandHelpers.GetAllChangedFilesCmd(excludeIgnoredFiles, untrackedFiles)); - List result = GitCommandHelpers.GetAllChangedFilesFromString(this, status); + var result = GitCommandHelpers.GetAllChangedFilesFromString(this, status).ToList(); if (!excludeAssumeUnchangedFiles || !excludeSkipWorktreeFiles) { @@ -2560,7 +2560,7 @@ public IList GetAllChangedFiles(bool excludeIgnoredFiles = true, return result; } - public IList GetAllChangedFilesWithSubmodulesStatus(bool excludeIgnoredFiles = true, + public IReadOnlyList GetAllChangedFilesWithSubmodulesStatus(bool excludeIgnoredFiles = true, bool excludeAssumeUnchangedFiles = true, bool excludeSkipWorktreeFiles = true, UntrackedFilesMode untrackedFiles = UntrackedFilesMode.Default) { @@ -2569,7 +2569,7 @@ public IList GetAllChangedFilesWithSubmodulesStatus(bool excludeI return status; } - private void GetCurrentSubmoduleStatus(IList status) + private void GetCurrentSubmoduleStatus(IReadOnlyList status) { foreach (var item in status) { @@ -2591,7 +2591,7 @@ private void GetCurrentSubmoduleStatus(IList status) } } - private void GetSubmoduleStatus(IList status, string firstRevision, string secondRevision) + private void GetSubmoduleStatus(IReadOnlyList status, string firstRevision, string secondRevision) { status.ForEach(item => { @@ -2614,7 +2614,7 @@ private void GetSubmoduleStatus(IList status, string firstRevisio }); } - public IList GetStagedFiles() + public IReadOnlyList GetStagedFiles() { string status = RunGitCmd(DiffCommandWithStandardArgs + "-M -C -z --cached --name-status", SystemEncoding); @@ -2623,31 +2623,31 @@ public IList GetStagedFiles() // This command is a little more expensive because it will return both staged and unstaged files string command = GitCommandHelpers.GetAllChangedFilesCmd(true, UntrackedFilesMode.No); status = RunGitCmd(command, SystemEncoding); - IList stagedFiles = GitCommandHelpers.GetAllChangedFilesFromString(this, status, false); + IReadOnlyList stagedFiles = GitCommandHelpers.GetAllChangedFilesFromString(this, status, false); return stagedFiles.Where(f => f.IsStaged).ToList(); } return GitCommandHelpers.GetAllChangedFilesFromString(this, status, true); } - public IList GetStagedFilesWithSubmodulesStatus() + public IReadOnlyList GetStagedFilesWithSubmodulesStatus() { var status = GetStagedFiles(); GetCurrentSubmoduleStatus(status); return status; } - public IList GetUnstagedFiles() + public IReadOnlyList GetUnstagedFiles() { return GetAllChangedFiles().Where(x => !x.IsStaged).ToArray(); } - public IList GetUnstagedFilesWithSubmodulesStatus() + public IReadOnlyList GetUnstagedFilesWithSubmodulesStatus() { return GetAllChangedFilesWithSubmodulesStatus().Where(x => !x.IsStaged).ToArray(); } - public IList GitStatus(UntrackedFilesMode untrackedFilesMode, IgnoreSubmodulesMode ignoreSubmodulesMode = 0) + public IReadOnlyList GitStatus(UntrackedFilesMode untrackedFilesMode, IgnoreSubmodulesMode ignoreSubmodulesMode = 0) { string command = GitCommandHelpers.GetAllChangedFilesCmd(true, untrackedFilesMode, ignoreSubmodulesMode); string status = RunGitCmd(command); @@ -2832,9 +2832,9 @@ public IEnumerable GetRemoteBranches() return GetRefs().Where(r => r.IsRemote); } - public RemoteActionResult> GetRemoteServerRefs(string remote, bool tags, bool branches) + public RemoteActionResult> GetRemoteServerRefs(string remote, bool tags, bool branches) { - var result = new RemoteActionResult> + var result = new RemoteActionResult> { AuthenticationFail = false, HostKeyFail = false, @@ -2889,14 +2889,14 @@ private CmdResult GetTreeFromRemoteRefs(string remote, bool tags, bool branches) return GetTreeFromRemoteRefsEx(remote, tags, branches); } - public IList GetRefs(bool tags = true, bool branches = true) + public IReadOnlyList GetRefs(bool tags = true, bool branches = true) { var tree = GetTree(tags, branches); return GetTreeRefs(tree); } /// Ordery by date is slower. - public IList GetTagRefs(GetTagRefsSortOrder option) + public IReadOnlyList GetTagRefs(GetTagRefsSortOrder option) { var list = GetRefs(true, false); @@ -2984,7 +2984,7 @@ private string GetTree(bool tags, bool branches) return ""; } - public IList GetTreeRefs(string tree) + public IReadOnlyList GetTreeRefs(string tree) { var itemsStrings = tree.Split('\n'); @@ -3131,7 +3131,7 @@ public string GetTagMessage(string tag) /// Returns list of filenames which would be ignored /// /// Patterns to ignore (.gitignore syntax) - public IList GetIgnoredFiles(IEnumerable ignorePatterns) + public IReadOnlyList GetIgnoredFiles(IEnumerable ignorePatterns) { var notEmptyPatterns = ignorePatterns .Where(pattern => !pattern.IsNullOrWhiteSpace()) @@ -3157,7 +3157,7 @@ public IList GetIgnoredFiles(IEnumerable ignorePatterns) } } - public string[] GetFullTree(string id) + public IReadOnlyList GetFullTree(string id) { string tree = RunCacheableCmd(AppSettings.GitCommand, string.Format("ls-tree -z -r --name-only {0}", id), SystemEncoding); return tree.Split('\0', '\n'); @@ -3560,7 +3560,7 @@ public static string UnquoteFileName(string fileName) } char[] chars = fileName.ToCharArray(); - IList blist = new List(); + var blist = new List(); int i = 0; StringBuilder sb = new StringBuilder(); while (i < chars.Length) @@ -3785,7 +3785,7 @@ public string GetLocalTrackingBranchName(string remoteName, string branch) return branchName; } - public IList GetCombinedDiffFileList(string shaOfMergeCommit) + public IReadOnlyList GetCombinedDiffFileList(string shaOfMergeCommit) { var fileList = RunGitCmd("diff-tree --name-only -z --cc --no-commit-id " + shaOfMergeCommit); diff --git a/GitCommands/Git/GitVersion.cs b/GitCommands/Git/GitVersion.cs index c910019d14f..84a127cc82e 100644 --- a/GitCommands/Git/GitVersion.cs +++ b/GitCommands/Git/GitVersion.cs @@ -30,7 +30,7 @@ public GitVersion(string version) { Full = Fix(version); - IList numbers = GetNumbers(Full); + var numbers = GetNumbers(Full); _a = Get(numbers, 0); _b = Get(numbers, 1); _c = Get(numbers, 2); @@ -107,12 +107,12 @@ private static string Fix(string version) return version.Trim(); } - private static int Get(IList values, int index) + private static int Get(IReadOnlyList values, int index) { return index < values.Count ? values[index] : 0; } - private static IList GetNumbers(string version) + private static IReadOnlyList GetNumbers(string version) { IEnumerable numbers = ParseNumbers(version); return new List(numbers); diff --git a/GitCommands/Remote/GitRemote.cs b/GitCommands/Remote/GitRemote.cs index 703ab03f49c..fb8ec91f2a6 100644 --- a/GitCommands/Remote/GitRemote.cs +++ b/GitCommands/Remote/GitRemote.cs @@ -19,7 +19,7 @@ public class GitRemote /// /// Gets or sets value stored in .git/config via key. /// - public IList Push { get; set; } + public IReadOnlyList Push { get; set; } /// /// Gets or sets value stored in .git/config via key. diff --git a/GitCommands/RevisionGraph.cs b/GitCommands/RevisionGraph.cs index 6baf873f483..cb4cd4f73ef 100644 --- a/GitCommands/RevisionGraph.cs +++ b/GitCommands/RevisionGraph.cs @@ -273,7 +273,7 @@ private void ProccessGitLogExecuted() Exited?.Invoke(this, EventArgs.Empty); } - private IList GetRefs() + private IReadOnlyList GetRefs() { var result = _module.GetRefs(true); bool validWorkingDir = _module.IsValidGitWorkingDir(); diff --git a/GitCommands/Settings/ConfigFileSettings.cs b/GitCommands/Settings/ConfigFileSettings.cs index a0ed69c18d5..d06a96f3c0f 100644 --- a/GitCommands/Settings/ConfigFileSettings.cs +++ b/GitCommands/Settings/ConfigFileSettings.cs @@ -76,7 +76,7 @@ public string GetValue(string setting) return GetString(setting, string.Empty); } - public IList GetValues(string setting) + public IReadOnlyList GetValues(string setting) { return SettingsCache.GetValues(setting); } @@ -97,7 +97,7 @@ public void SetPathValue(string setting, string value) SetValue(setting, ConfigSection.FixPath(value)); } - public IList GetConfigSections() + public IReadOnlyList GetConfigSections() { return SettingsCache.GetConfigSections(); } diff --git a/GitCommands/Settings/ConfigFileSettingsCache.cs b/GitCommands/Settings/ConfigFileSettingsCache.cs index 153f6ed39de..9daf260b1ee 100644 --- a/GitCommands/Settings/ConfigFileSettingsCache.cs +++ b/GitCommands/Settings/ConfigFileSettingsCache.cs @@ -83,7 +83,7 @@ public void AddConfigSection(IConfigSection configSection) }); } - public IList GetValues(string key) + public IReadOnlyList GetValues(string key) { return LockedAction(() => { @@ -92,7 +92,7 @@ public IList GetValues(string key) }); } - public IList GetConfigSections() + public IReadOnlyList GetConfigSections() { return LockedAction(() => { diff --git a/GitCommands/Statistics/ImpactLoader.cs b/GitCommands/Statistics/ImpactLoader.cs index d7a164b2fb0..8beff4f917f 100644 --- a/GitCommands/Statistics/ImpactLoader.cs +++ b/GitCommands/Statistics/ImpactLoader.cs @@ -128,7 +128,7 @@ private Task[] GetTasks(CancellationToken token) if (ShowSubmodules) { - IList submodules = _module.GetSubmodulesLocalPaths(); + var submodules = _module.GetSubmodulesLocalPaths(); foreach (var submoduleName in submodules) { IGitModule submodule = _module.GetSubmodule(submoduleName); diff --git a/GitUI/CommandsDialogs/BrowseDialog/FormCommitCount.cs b/GitUI/CommandsDialogs/BrowseDialog/FormCommitCount.cs index c7172c8c5ca..56d5ecdfe59 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/FormCommitCount.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/FormCommitCount.cs @@ -35,7 +35,8 @@ private void FetchData() var items = CommitCounter.GroupAllCommitsByContributor(Module).Item1; if (cbIncludeSubmodules.Checked) { - IList submodules = Module.GetSubmodulesLocalPaths(); + var submodules = Module.GetSubmodulesLocalPaths(); + foreach (var submoduleName in submodules) { GitModule submodule = Module.GetSubmodule(submoduleName); diff --git a/GitUI/CommandsDialogs/FormAddToGitIgnore.cs b/GitUI/CommandsDialogs/FormAddToGitIgnore.cs index 5d6964dbd1b..fb7f1ef9139 100644 --- a/GitUI/CommandsDialogs/FormAddToGitIgnore.cs +++ b/GitUI/CommandsDialogs/FormAddToGitIgnore.cs @@ -96,7 +96,7 @@ private void AddToIgnoreClick(object sender, EventArgs e) Close(); } - private void UpdatePreviewPanel(IList ignoredFiles) + private void UpdatePreviewPanel(IReadOnlyList ignoredFiles) { _NO_TRANSLATE_Preview.DataSource = ignoredFiles; _NO_TRANSLATE_filesWillBeIgnored.Text = string.Format(_matchingFilesString.Text, _NO_TRANSLATE_Preview.Items.Count); diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index b43df62342e..f253db9534d 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -1942,8 +1942,7 @@ private void AddBranchesMenuItems() private IEnumerable GetBranchNames() { - IList branches = Module.GetRefs(false); - IEnumerable branchNames = branches.Select(b => b.Name); + IEnumerable branchNames = Module.GetRefs(false).Select(b => b.Name); if (AppSettings.BranchOrderingCriteria == BranchOrdering.Alphabetically) { branchNames = branchNames.OrderBy(b => b); diff --git a/GitUI/CommandsDialogs/FormClone.cs b/GitUI/CommandsDialogs/FormClone.cs index 9dd26c9720f..46c623b889d 100644 --- a/GitUI/CommandsDialogs/FormClone.cs +++ b/GitUI/CommandsDialogs/FormClone.cs @@ -407,7 +407,7 @@ private void ToSelectedIndexChanged(object sender, EventArgs e) private readonly AsyncLoader _branchListLoader = new AsyncLoader(); - private void UpdateBranches(RemoteActionResult> branchList) + private void UpdateBranches(RemoteActionResult> branchList) { Cursor = Cursors.Default; diff --git a/GitUI/CommandsDialogs/FormCommit.cs b/GitUI/CommandsDialogs/FormCommit.cs index 76a8cbb523c..e8a8392edbd 100644 --- a/GitUI/CommandsDialogs/FormCommit.cs +++ b/GitUI/CommandsDialogs/FormCommit.cs @@ -509,9 +509,9 @@ protected override bool ExecuteCommand(int cmd) #endregion - private void ComputeUnstagedFiles(Action> onComputed, bool doAsync) + private void ComputeUnstagedFiles(Action> onComputed, bool doAsync) { - IList GetAllChangedFilesWithSubmodulesStatus() + IReadOnlyList GetAllChangedFilesWithSubmodulesStatus() { return Module.GetAllChangedFilesWithSubmodulesStatus( !showIgnoredFilesToolStripMenuItem.Checked, @@ -778,7 +778,7 @@ private void InitializedStaged() /// This method is passed in to the SetTextCallBack delegate /// to set the Text property of textBox1. /// - private void LoadUnstagedOutput(IList allChangedFiles) + private void LoadUnstagedOutput(IReadOnlyList allChangedFiles) { var lastSelection = new List(); if (_currentFilesList != null) diff --git a/GitUI/CommandsDialogs/FormPull.cs b/GitUI/CommandsDialogs/FormPull.cs index 855e58289a8..eb116ea7dc6 100644 --- a/GitUI/CommandsDialogs/FormPull.cs +++ b/GitUI/CommandsDialogs/FormPull.cs @@ -96,7 +96,7 @@ public partial class FormPull : GitModuleForm #endregion public bool ErrorOccurred { get; private set; } - private IList _heads; + private List _heads; private string _branch; private bool _bInternalUpdate; private const string AllRemotes = "[ All ]"; @@ -235,7 +235,7 @@ private void BranchesDropDown(object sender, EventArgs e) { if (PullFromUrl.Checked) { - _heads = Module.GetRefs(false, true); + _heads = Module.GetRefs(false, true).ToList(); } else { diff --git a/GitUI/CommandsDialogs/FormPush.cs b/GitUI/CommandsDialogs/FormPush.cs index 8837877ef4c..255f4058dcc 100644 --- a/GitUI/CommandsDialogs/FormPush.cs +++ b/GitUI/CommandsDialogs/FormPush.cs @@ -27,7 +27,7 @@ public partial class FormPush : GitModuleForm private string _selectedBranch; private GitRemote _selectedRemote; private string _selectedRemoteBranchName; - private IList _gitRefs; + private IReadOnlyList _gitRefs; private readonly IGitRemoteManager _remoteManager; public bool ErrorOccurred { get; private set; } @@ -906,7 +906,7 @@ private void LoadMultiBranchViewData(string remote) Cursor = Cursors.AppStarting; try { - IList remoteHeads; + IReadOnlyList remoteHeads; if (Module.EffectiveSettings.Detailed.GetRemoteBranchesDirectlyFromRemote.ValueOrDefault) { EnsurePageant(remote); @@ -959,7 +959,7 @@ private static string TakeCommandOutput(string processOutput) return cmdOutput; } - private void ProcessHeads(string remote, IList remoteHeads) + private void ProcessHeads(string remote, IReadOnlyList remoteHeads) { IList localHeads = GetLocalBranches().ToList(); var remoteBranches = remoteHeads.ToHashSet(h => h.LocalName); diff --git a/GitUI/CommandsDialogs/FormStash.cs b/GitUI/CommandsDialogs/FormStash.cs index 7ef7d13170f..23231dfa9c4 100644 --- a/GitUI/CommandsDialogs/FormStash.cs +++ b/GitUI/CommandsDialogs/FormStash.cs @@ -63,7 +63,7 @@ private void FormStashLoad(object sender, EventArgs e) private void Initialize() { - IList stashedItems = Module.GetStashes(); + var stashedItems = Module.GetStashes().ToList(); _currentWorkingDirStashItem = new GitStash("currentWorkingDirStashItem") { @@ -120,7 +120,7 @@ private void InitializeSoft() } } - private void LoadGitItemStatuses(IList gitItemStatuses) + private void LoadGitItemStatuses(IReadOnlyList gitItemStatuses) { Stashed.SetDiffs(items: gitItemStatuses); Loading.Visible = false; diff --git a/GitUI/CommandsDialogs/SubmodulesDialog/FormAddSubmodule.cs b/GitUI/CommandsDialogs/SubmodulesDialog/FormAddSubmodule.cs index a89a7cadc82..9cf29339069 100644 --- a/GitUI/CommandsDialogs/SubmodulesDialog/FormAddSubmodule.cs +++ b/GitUI/CommandsDialogs/SubmodulesDialog/FormAddSubmodule.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; using GitCommands; using GitCommands.Repository; @@ -63,10 +64,10 @@ private void BranchDropDown(object sender, EventArgs e) { GitModule module = new GitModule(Directory.Text); Branch.DisplayMember = "Name"; - IList heads; + List heads; if (module.IsValidGitWorkingDir()) { - heads = module.GetRefs(false); + heads = module.GetRefs(false).ToList(); } else { diff --git a/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs b/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs index 495a970c096..112c8b5717e 100644 --- a/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs +++ b/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs @@ -68,7 +68,7 @@ private void LoadBranchesAsync() }, TaskScheduler.FromCurrentSynchronizationContext()); } - public IList ExistingBranches { get; set; } + public IReadOnlyList ExistingBranches { get; set; } private void comboBoxBranches_KeyUp(object sender, KeyEventArgs e) { diff --git a/GitUI/CommitInfo/CommitInfo.cs b/GitUI/CommitInfo/CommitInfo.cs index 4bc592f68b5..724d6aab91e 100644 --- a/GitUI/CommitInfo/CommitInfo.cs +++ b/GitUI/CommitInfo/CommitInfo.cs @@ -223,7 +223,7 @@ private int GetRevisionHeaderHeight() private void LoadSortedRefs() { - _sortedRefs = Module.GetSortedRefs(); + _sortedRefs = Module.GetSortedRefs().ToList(); this.InvokeAsync(UpdateRevisionInfo); } diff --git a/GitUI/HelperDialogs/FormSelectMultipleBranches.cs b/GitUI/HelperDialogs/FormSelectMultipleBranches.cs index 0dcc9423817..8c3bd3834b2 100644 --- a/GitUI/HelperDialogs/FormSelectMultipleBranches.cs +++ b/GitUI/HelperDialogs/FormSelectMultipleBranches.cs @@ -15,7 +15,7 @@ private FormSelectMultipleBranches() Translate(); } - public FormSelectMultipleBranches(IList branchesToSelect) + public FormSelectMultipleBranches(IReadOnlyList branchesToSelect) { InitializeComponent(); Translate(); @@ -44,9 +44,9 @@ public void SelectBranch(string name) } } - public IList GetSelectedBranches() + public IReadOnlyList GetSelectedBranches() { - IList branches = new List(); + var branches = new List(); foreach (IGitRef head in Branches.CheckedItems) { diff --git a/GitUI/UserControls/BranchComboBox.cs b/GitUI/UserControls/BranchComboBox.cs index 8d4b9d1c92b..ef5b64cbe08 100644 --- a/GitUI/UserControls/BranchComboBox.cs +++ b/GitUI/UserControls/BranchComboBox.cs @@ -21,8 +21,8 @@ public BranchComboBox() branches.DisplayMember = "Name"; } - private IList _branchesToSelect; - public IList BranchesToSelect + private IReadOnlyList _branchesToSelect; + public IReadOnlyList BranchesToSelect { get { @@ -76,7 +76,7 @@ public void SetSelectedText(string text) private void selectMultipleBranchesButton_Click(object sender, EventArgs e) { - using (FormSelectMultipleBranches formSelectMultipleBranches = new FormSelectMultipleBranches(_branchesToSelect)) + using (var formSelectMultipleBranches = new FormSelectMultipleBranches(_branchesToSelect)) { foreach (var branch in GetSelectedBranches()) { diff --git a/GitUI/UserControls/FileStatusList.cs b/GitUI/UserControls/FileStatusList.cs index 64f0cd6b6ea..cc68f000c9f 100644 --- a/GitUI/UserControls/FileStatusList.cs +++ b/GitUI/UserControls/FileStatusList.cs @@ -19,8 +19,8 @@ namespace GitUI { // Parents is used as the "first selected" (not always the parent) for GitItemStatus - using IGitItemsWithParents = IDictionary>; - using GitItemsWithParents = Dictionary>; + using IGitItemsWithParents = IDictionary>; + using GitItemsWithParents = Dictionary>; public delegate string DescribeRevisionDelegate(string sha1); @@ -1117,7 +1117,7 @@ private int SelectFiles(Regex selctionFilter) } } - public void SetDiffs(GitRevision selectedRev = null, GitRevision parentRev = null, IList items = null) + public void SetDiffs(GitRevision selectedRev = null, GitRevision parentRev = null, IReadOnlyList items = null) { Revision = selectedRev; diff --git a/GitUI/UserControls/PatchGrid.cs b/GitUI/UserControls/PatchGrid.cs index 233e4d7cc71..72123c88af9 100644 --- a/GitUI/UserControls/PatchGrid.cs +++ b/GitUI/UserControls/PatchGrid.cs @@ -33,7 +33,7 @@ protected override void OnRuntimeLoad(EventArgs e) public void Initialize() { - IList patchFiles; + IReadOnlyList patchFiles; if (Module.InTheMiddleOfInteractiveRebase()) { diff --git a/Plugins/GitUIPluginInterfaces/IConfigFileSettings.cs b/Plugins/GitUIPluginInterfaces/IConfigFileSettings.cs index 2ab5ed3a361..17edc4088df 100644 --- a/Plugins/GitUIPluginInterfaces/IConfigFileSettings.cs +++ b/Plugins/GitUIPluginInterfaces/IConfigFileSettings.cs @@ -13,7 +13,7 @@ public interface IConfigFileSettings : ISettingsValueGetter /// /// Retrieves configuration sections the .git/config file. /// - IList GetConfigSections(); + IReadOnlyList GetConfigSections(); /// /// Removes the specific configuration section from the .git/config file. diff --git a/Plugins/GitUIPluginInterfaces/IConfigSection.cs b/Plugins/GitUIPluginInterfaces/IConfigSection.cs index f60905968b2..d9e29ec69db 100644 --- a/Plugins/GitUIPluginInterfaces/IConfigSection.cs +++ b/Plugins/GitUIPluginInterfaces/IConfigSection.cs @@ -7,11 +7,11 @@ public interface IConfigSection string SectionName { get; set; } string SubSection { get; set; } - IDictionary> AsDictionary(); + IDictionary> AsDictionary(); void AddValue(string key, string value); bool Equals(IConfigSection other); string GetValue(string key, string defaultValue = ""); - IList GetValues(string key); + IReadOnlyList GetValues(string key); bool HasValue(string key); void SetValue(string key, string value); } diff --git a/Plugins/GitUIPluginInterfaces/IGitModule.cs b/Plugins/GitUIPluginInterfaces/IGitModule.cs index 8100bc526ba..a342d4e14de 100644 --- a/Plugins/GitUIPluginInterfaces/IGitModule.cs +++ b/Plugins/GitUIPluginInterfaces/IGitModule.cs @@ -11,7 +11,7 @@ public interface IGitModule IConfigFileSettings LocalConfigFile { get; } string AddRemote(string remoteName, string path); - IList GetRefs(bool tags = true, bool branches = true); + IReadOnlyList GetRefs(bool tags = true, bool branches = true); IEnumerable GetSettings(string setting); IEnumerable GetTree(string id, bool full); @@ -106,7 +106,7 @@ public interface IGitModule IEnumerable GetSubmodulesInfo(); - IList GetSubmodulesLocalPaths(bool recursive = true); + IReadOnlyList GetSubmodulesLocalPaths(bool recursive = true); IGitModule GetSubmodule(string submoduleName); diff --git a/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs b/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs index 1548015171c..48109061009 100644 --- a/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs +++ b/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs @@ -115,7 +115,7 @@ public void TestGetAllChangedFilesFromString() { // git diff -M -C -z --cached --name-status string statusString = "\r\nwarning: LF will be replaced by CRLF in CustomDictionary.xml.\r\nThe file will have its original line endings in your working directory.\r\nwarning: LF will be replaced by CRLF in FxCop.targets.\r\nThe file will have its original line endings in your working directory.\r\nM\0testfile.txt\0"; - List status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); + var status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); Assert.IsTrue(status.Count == 1); Assert.IsTrue(status[0].Name == "testfile.txt"); } @@ -123,7 +123,7 @@ public void TestGetAllChangedFilesFromString() { // git diff -M -C -z --cached --name-status string statusString = "\0\r\nwarning: LF will be replaced by CRLF in CustomDictionary.xml.\r\nThe file will have its original line endings in your working directory.\r\nwarning: LF will be replaced by CRLF in FxCop.targets.\r\nThe file will have its original line endings in your working directory.\r\nM\0testfile.txt\0"; - List status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); + var status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); Assert.IsTrue(status.Count == 1); Assert.IsTrue(status[0].Name == "testfile.txt"); } @@ -131,7 +131,7 @@ public void TestGetAllChangedFilesFromString() { // git diff -M -C -z --cached --name-status string statusString = "\0\nwarning: LF will be replaced by CRLF in CustomDictionary.xml.\nThe file will have its original line endings in your working directory.\nwarning: LF will be replaced by CRLF in FxCop.targets.\nThe file will have its original line endings in your working directory.\nM\0testfile.txt\0"; - List status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); + var status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); Assert.IsTrue(status.Count == 1); Assert.IsTrue(status[0].Name == "testfile.txt"); } @@ -139,7 +139,7 @@ public void TestGetAllChangedFilesFromString() { // git diff -M -C -z --cached --name-status string statusString = "M testfile.txt\0\nwarning: LF will be replaced by CRLF in CustomDictionary.xml.\nThe file will have its original line endings in your working directory.\nwarning: LF will be replaced by CRLF in FxCop.targets.\nThe file will have its original line endings in your working directory.\n"; - List status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); + var status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, true); Assert.IsTrue(status.Count == 1); Assert.IsTrue(status[0].Name == "testfile.txt"); } @@ -147,7 +147,7 @@ public void TestGetAllChangedFilesFromString() { // git status --porcelain --untracked-files=no -z string statusString = "M adfs.h\0M dir.c\0\r\nwarning: LF will be replaced by CRLF in adfs.h.\nThe file will have its original line endings in your working directory.\nwarning: LF will be replaced by CRLF in dir.c.\nThe file will have its original line endings in your working directory."; - List status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, false); + var status = GitCommandHelpers.GetAllChangedFilesFromString(module, statusString, false); Assert.IsTrue(status.Count == 2); Assert.IsTrue(status[0].Name == "adfs.h"); Assert.IsTrue(status[1].Name == "dir.c");