Skip to content

Commit

Permalink
fixup! Cache Git commands related to submodules
Browse files Browse the repository at this point in the history
* Cache commands with sha input and no variable input like Git Notes
Only fetch Git Notes for commands that are not cached

* Cache GetCommitRangeDiffCount (for rev-diff)

* Increase Git command cache to 50
  • Loading branch information
gerhardol committed Feb 22, 2021
1 parent e0dfb54 commit 8cafaa3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GitCommands/CommitDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private bool TryGetCommitLog(string commitId, string format, [NotNullWhen(return
};

// This command can be cached if commitId is a git sha and Notes are ignored
Debug.Assert(!cache || ObjectId.TryParse(commitId, out _), $"Cache should be used only for sha");
Debug.Assert(!cache || ObjectId.TryParse(commitId, out _), $"git-log cache should be used only for sha ({commitId})");

data = GetModule().GitExecutable.GetOutput(arguments,
outputEncoding: GitModule.LosslessEncoding,
Expand Down
4 changes: 2 additions & 2 deletions GitUI/Editor/FileViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public Task ViewGitItemAsync(GitItemStatus file, [CanBeNull] Action openWithDiff
isSubmodule,
getImage: GetImage,
getFileText: GetFileTextIfBlobExists,
getSubmoduleText: () => LocalizationHelpers.GetSubmoduleText(Module, file.Name.TrimEnd('/'), sha),
getSubmoduleText: () => LocalizationHelpers.GetSubmoduleText(Module, file.Name.TrimEnd('/'), sha, cache: true),
openWithDifftool: openWithDifftool);

string GetFileTextIfBlobExists()
Expand Down Expand Up @@ -599,7 +599,7 @@ public Task ViewFileAsync(string fileName, bool isSubmodule = false, [CanBeNull]
isSubmodule,
getImage: GetImage,
getFileText: GetFileText,
getSubmoduleText: () => LocalizationHelpers.GetSubmoduleText(Module, fileName.TrimEnd('/'), ""),
getSubmoduleText: () => LocalizationHelpers.GetSubmoduleText(Module, fileName.TrimEnd('/'), "", cache: false),
openWithDifftool));

Image GetImage()
Expand Down
4 changes: 2 additions & 2 deletions ResourceManager/LocalizationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static string GetFullDateString(DateTimeOffset datetime)
return datetime.LocalDateTime.ToString("G");
}

public static string GetSubmoduleText(GitModule superproject, string name, string hash)
public static string GetSubmoduleText(GitModule superproject, string name, string hash, bool cache)
{
var sb = new StringBuilder();
sb.AppendLine("Submodule " + name);
Expand All @@ -91,7 +91,7 @@ public static string GetSubmoduleText(GitModule superproject, string name, strin
// TEMP, will be moved in the follow up refactor
ICommitDataManager commitDataManager = new CommitDataManager(() => module);

CommitData data = commitDataManager.GetCommitData(hash, out _, cache: true);
CommitData data = commitDataManager.GetCommitData(hash, out _, cache);
if (data is null)
{
sb.AppendLine("Commit hash:\t" + hash);
Expand Down

0 comments on commit 8cafaa3

Please sign in to comment.