Skip to content

Commit

Permalink
Submodule status: Throttle instead of drop frequent updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardol committed May 31, 2020
1 parent 71a6164 commit 8267e9a
Show file tree
Hide file tree
Showing 8 changed files with 827 additions and 233 deletions.
3 changes: 1 addition & 2 deletions GitCommands/Submodules/SubmoduleInfoResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class SubmoduleInfoResult
public IList<SubmoduleInfo> OurSubmodules { get; } = new List<SubmoduleInfo>();

// List of SubmoduleInfo for all submodules under TopProject.
// Only populated if current module is a submodule (i.e. is not TopProject)
public IList<SubmoduleInfo> SuperSubmodules { get; } = new List<SubmoduleInfo>();
public IList<SubmoduleInfo> AllSubmodules { get; } = new List<SubmoduleInfo>();

// Always set to the top-most module.
[NotNull]
Expand Down
304 changes: 140 additions & 164 deletions GitCommands/Submodules/SubmoduleStatusProvider.cs

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,8 @@ private Nodes FillSubmoduleTree(SubmoduleInfoResult result)

var submoduleNodes = new List<SubmoduleNode>();

// We always want to display submodules rooted from the top project. If the currently open project is the top project,
// OurSubmodules contains all child submodules recursively; otherwise, if we're currently in a submodule, SuperSubmodules
// contains all submodule info relative to the top project.
if (result.SuperSubmodules?.Count > 0)
{
CreateSubmoduleNodes(result.SuperSubmodules, threadModule, ref submoduleNodes);
}
else
{
CreateSubmoduleNodes(result.OurSubmodules, threadModule, ref submoduleNodes);
}
// We always want to display submodules rooted from the top project.
CreateSubmoduleNodes(result.AllSubmodules, threadModule, ref submoduleNodes);

var nodes = new Nodes(this);
AddNodesToTree(ref nodes, submoduleNodes, threadModule, result.TopProject);
Expand All @@ -281,7 +272,7 @@ private Nodes FillSubmoduleTree(SubmoduleInfoResult result)

private void CreateSubmoduleNodes(IEnumerable<SubmoduleInfo> submodules, GitModule threadModule, ref List<SubmoduleNode> nodes)
{
// result.OurSubmodules/SuperSubmodules contain a recursive list of submodules, but don't provide info about the super
// result.OurSubmodules/AllSubmodules contain a recursive list of submodules, but don't provide info about the super
// project path. So we deduce these by substring matching paths against an ordered list of all paths.
var modulePaths = submodules.Select(info => info.Path).ToList();

Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ Image GetSubmoduleItemImage(DetailedSubmoduleInfo details)
private void UpdateSubmodulesStructure()
{
// Submodule status is updated on git-status updates. To make sure supermodule status is updated, update immediately (once)
var updateStatus = AppSettings.ShowSubmoduleStatus && _gitStatusMonitor.Active && (Module.SuperprojectModule != null);
var updateStatus = AppSettings.ShowSubmoduleStatus && _gitStatusMonitor.Active;

toolStripButtonLevelUp.ToolTipText = "";

Expand Down Expand Up @@ -2628,7 +2628,7 @@ private async Task PopulateToolbarAsync(SubmoduleInfoResult result, Cancellation
}

newItems.Add(CreateSubmoduleMenuItem(cancelToken, result.SuperProject, _superprojectModuleFormat.Text));
newItems.AddRange(result.SuperSubmodules.Select(submodule => CreateSubmoduleMenuItem(cancelToken, submodule)));
newItems.AddRange(result.AllSubmodules.Select(submodule => CreateSubmoduleMenuItem(cancelToken, submodule)));
toolStripButtonLevelUp.ToolTipText = _goToSuperProject.Text;
}

Expand Down
39 changes: 25 additions & 14 deletions UnitTests/CommonTestUtils/GitModuleTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public GitModuleTestHelper(string repositoryName = "repo1")
Module = module;

// Don't assume global user/email
Module.LocalConfigFile.SetString(SettingKeyString.UserName, "author");
Module.LocalConfigFile.SetString(SettingKeyString.UserEmail, "author@mail.com");
Module.LocalConfigFile.FilesEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
Module.LocalConfigFile.Save();
SetDummyUserEmail(module);

return;

Expand Down Expand Up @@ -111,20 +108,29 @@ public string CreateRepoFile(string fileName, string fileContent)
}

/// <summary>
/// Adds 'helper' as a submodule of the current helper.
/// Set dummy user and email locally for the module, no global setting in AppVeyor
/// Must also be set on the submodule, local settings are not included when adding it
/// </summary>
/// <param name="helper">GitModuleTestHelper to add as a submodule of this.</param>
private void SetDummyUserEmail(GitModule module)
{
module.LocalConfigFile.SetString(SettingKeyString.UserName, "author");
module.LocalConfigFile.SetString(SettingKeyString.UserEmail, "author@mail.com");
module.LocalConfigFile.FilesEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
module.LocalConfigFile.Save();
}

/// <summary>
/// Adds 'subModuleHelper' as a submodule of the current subModuleHelper.
/// </summary>
/// <param name="subModuleHelper">GitModuleTestHelper to add as a submodule of this.</param>
/// <param name="path">Relative submodule path.</param>
/// <returns>Module of added submodule</returns>
public GitModule AddSubmodule(GitModuleTestHelper helper, string path)
public void AddSubmodule(GitModuleTestHelper subModuleHelper, string path)
{
// Submodules require at least one commit
helper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Empty commit""");
subModuleHelper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Initial empty commit""");

Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(helper.Module.WorkingDir.ToPosixPath(), path, null, true));
Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(subModuleHelper.Module.WorkingDir.ToPosixPath(), path, null, true));
Module.GitExecutable.GetOutput(@"commit -am ""Add submodule""");

return new GitModule(Path.Combine(Module.WorkingDir, path).ToPosixPath());
}

/// <summary>
Expand All @@ -135,7 +141,12 @@ public IEnumerable<GitModule> GetSubmodulesRecursive()
{
Module.GitExecutable.GetOutput(@"submodule update --init --recursive");
var paths = Module.GetSubmodulesLocalPaths(recursive: true);
return paths.Select(path => new GitModule(Path.Combine(Module.WorkingDir, path).ToNativePath()));
return paths.Select(path =>
{
var module = new GitModule(Path.Combine(Module.WorkingDir, path).ToNativePath());
SetDummyUserEmail(module);
return module;
});
}

public void Dispose()
Expand Down Expand Up @@ -190,4 +201,4 @@ private void EnsureCreatedInTempFolder(string path)
}
}
}
}
}
6 changes: 3 additions & 3 deletions UnitTests/CommonTestUtils/SubmoduleTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CommonTestUtils
{
public class SubmoduleTestHelpers
{
public static async Task<SubmoduleInfoResult> UpdateSubmoduleStructureAndWaitForResultAsync(ISubmoduleStatusProvider provider, GitModule module, bool updateStatus = false)
public static async Task<SubmoduleInfoResult> UpdateSubmoduleStructureAndWaitForResultAsync(ISubmoduleStatusProvider provider, GitModule module, bool updateStatus = true)
{
SubmoduleInfoResult result = null;
provider.StatusUpdated += ProviderStatusUpdated;
Expand All @@ -33,14 +33,14 @@ void ProviderStatusUpdated(object sender, SubmoduleStatusEventArgs e)
}
}

public static async Task UpdateSubmoduleStatusAndWaitForResultAsync(ISubmoduleStatusProvider provider, GitModule module, IReadOnlyList<GitItemStatus> gitStatus)
public static async Task UpdateSubmoduleStatusAndWaitForResultAsync(ISubmoduleStatusProvider provider, GitModule module, IReadOnlyList<GitItemStatus> gitStatus, bool forceUpdate = true)
{
provider.StatusUpdated += Provider_StatusUpdated;

await provider.UpdateSubmodulesStatusAsync(
workingDirectory: module.WorkingDir,
gitStatus: gitStatus,
forceUpdate: true);
forceUpdate: forceUpdate);

await AsyncTestHelper.JoinPendingOperationsAsync(AsyncTestHelper.UnexpectedTimeout);

Expand Down
16 changes: 3 additions & 13 deletions UnitTests/GitCommands.Tests/GitModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,19 +705,9 @@ public void GetSuperprojectCurrentCheckout()
using (CommonTestUtils.GitModuleTestHelper moduleTestHelperSuper = new CommonTestUtils.GitModuleTestHelper("super repo"),
moduleTestHelperSub = new CommonTestUtils.GitModuleTestHelper("sub repo"))
{
// Inital commit in super project
moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Initial commit""");

// Submodules require at least one commit
moduleTestHelperSub.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Empty commit""");

// Add submodule
moduleTestHelperSuper.Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(moduleTestHelperSub.Module.WorkingDir.ToPosixPath(), "sub repo", null, true));
moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"commit -am ""Add submodule""");
GitModule moduleSub = new GitModule(Path.Combine(moduleTestHelperSuper.Module.WorkingDir, "sub repo").ToPosixPath());

// Init submodule
moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"submodule update --init --recursive");
// Add and init the submodule
moduleTestHelperSuper.AddSubmodule(moduleTestHelperSub, "sub repo");
var moduleSub = moduleTestHelperSuper.GetSubmodulesRecursive().ElementAt(0);

// Commit in submodule
moduleSub.GitExecutable.GetOutput(@"commit --allow-empty -am ""First commit""");
Expand Down
Loading

0 comments on commit 8267e9a

Please sign in to comment.