Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions GVFS/GVFS.Common/Enlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,18 @@ public bool GetTrustPackIndexesConfig()

return trustPackIndexes;
}

public bool GetStatusHydrationConfig()
{
var gitProcess = this.CreateGitProcess();

if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.ShowHydrationStatus, forceOutsideEnlistment: false, out var valueString)
&& bool.TryParse(valueString, out var statusHydrationConfig))
{
return statusHydrationConfig;
}

return GVFSConstants.GitConfig.ShowHydrationStatusDefault;
}
}
}
3 changes: 3 additions & 0 deletions GVFS/GVFS.Common/GVFSConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static class GitConfig
/* Intended to be a temporary config to allow testing of distrusting pack indexes from cache server
* before it is enabled by default. */
public const string TrustPackIndexes = GVFSPrefix + "trust-pack-indexes";

public const string ShowHydrationStatus = GVFSPrefix + "show-hydration-status";
public const bool ShowHydrationStatusDefault = false;
}

public static class LocalGVFSConfig
Expand Down
5 changes: 3 additions & 2 deletions GVFS/GVFS.Common/GitStatusCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class GitStatusCache : IDisposable

private object cacheFileLock = new object();

internal static bool TEST_EnableHydrationSummary = true;
internal static bool? TEST_EnableHydrationSummaryOverride = null;

public GitStatusCache(GVFSContext context, GitStatusCacheConfig config)
: this(context, config.BackoffTime)
Expand Down Expand Up @@ -341,7 +341,8 @@ private void RebuildStatusCacheIfNeeded(bool ignoreBackoff)

private void UpdateHydrationSummary()
{
if (!TEST_EnableHydrationSummary)
bool enabled = TEST_EnableHydrationSummaryOverride ?? this.context.Enlistment.GetStatusHydrationConfig();
if (!enabled)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public string ToMessage()
{
if (!IsValid)
{
return "Error calculating hydration. Run 'gvfs health' for details.";
return "Error calculating hydration summary. Run 'gvfs health' at the repository root for hydration status details.";
}

int fileHydrationPercent = TotalFileCount == 0 ? 0 : (100 * HydratedFileCount) / TotalFileCount;
int folderHydrationPercent = TotalFolderCount == 0 ? 0 : ((100 * HydratedFolderCount) / TotalFolderCount);
return $"{fileHydrationPercent}% of files and {folderHydrationPercent}% of folders hydrated. Run 'gvfs health' for details.";
return $"{fileHydrationPercent}% of files and {folderHydrationPercent}% of folders hydrated. Run 'gvfs health' at the repository root for details.";
}

public static EnlistmentHydrationSummary CreateSummary(
Expand Down
29 changes: 27 additions & 2 deletions GVFS/GVFS.Hooks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ private static void RunPreCommands(string[] args)
ProcessHelper.Run("gvfs", "prefetch --commits", redirectOutput: false);
break;
case "status":
/* If status is being run to serialize for caching, skip the health display */
if (!args.Any(arg => arg.StartsWith("--serialize", StringComparison.OrdinalIgnoreCase)))
/* If status is being run to serialize for caching, or if --porcelain is specified, skip the health display */
if (!ArgsBlockHydrationStatus(args)
&& ConfigurationAllowsHydrationStatus())
{
/* Display a message about the hydration status of the repo */
ProcessHelper.Run("gvfs", "health --status", redirectOutput: false);
Expand All @@ -98,6 +99,30 @@ private static void RunPreCommands(string[] args)
}
}

private static bool ArgsBlockHydrationStatus(string[] args)
{
return args.Any(arg =>
arg.StartsWith("--serialize", StringComparison.OrdinalIgnoreCase)
|| arg.StartsWith("--porcelain", StringComparison.OrdinalIgnoreCase));
}

private static bool ConfigurationAllowsHydrationStatus()
{
try
{
ProcessResult result = ProcessHelper.Run("git", $"config --get {GVFSConstants.GitConfig.ShowHydrationStatus}");
bool hydrationStatusEnabled;
if (bool.TryParse(result.Output.Trim(), out hydrationStatusEnabled))
{
return hydrationStatusEnabled;
}
}
catch (Exception)
{
}
return GVFSConstants.GitConfig.ShowHydrationStatusDefault;
}

private static void ExitWithError(params string[] messages)
{
foreach (string message in messages)
Expand Down
4 changes: 2 additions & 2 deletions GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void SetUp()
this.fileSystem,
new MockGitRepo(tracer, enlistment, this.fileSystem),
enlistment);
GitStatusCache.TEST_EnableHydrationSummary = false;
GitStatusCache.TEST_EnableHydrationSummaryOverride = false;
}

[TearDown]
Expand All @@ -85,7 +85,7 @@ public void TearDown()
this.gitParentPath = null;
this.gvfsMetadataPath = null;
this.enlistmentDirectory = null;
GitStatusCache.TEST_EnableHydrationSummary = true;
GitStatusCache.TEST_EnableHydrationSummaryOverride = null;
}

[TestCase]
Expand Down
Loading