Skip to content

Commit 0d38953

Browse files
authored
Merge pull request microsoft#1895 from tyrielv/tyrielv/hydration-flag
Config flag for showing hydration status
2 parents 0ddb3fa + da88dca commit 0d38953

6 files changed

Lines changed: 50 additions & 8 deletions

File tree

GVFS/GVFS.Common/Enlistment.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,18 @@ public bool GetTrustPackIndexesConfig()
122122

123123
return trustPackIndexes;
124124
}
125+
126+
public bool GetStatusHydrationConfig()
127+
{
128+
var gitProcess = this.CreateGitProcess();
129+
130+
if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.ShowHydrationStatus, forceOutsideEnlistment: false, out var valueString)
131+
&& bool.TryParse(valueString, out var statusHydrationConfig))
132+
{
133+
return statusHydrationConfig;
134+
}
135+
136+
return GVFSConstants.GitConfig.ShowHydrationStatusDefault;
137+
}
125138
}
126139
}

GVFS/GVFS.Common/GVFSConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static class GitConfig
4242
/* Intended to be a temporary config to allow testing of distrusting pack indexes from cache server
4343
* before it is enabled by default. */
4444
public const string TrustPackIndexes = GVFSPrefix + "trust-pack-indexes";
45+
46+
public const string ShowHydrationStatus = GVFSPrefix + "show-hydration-status";
47+
public const bool ShowHydrationStatusDefault = false;
4548
}
4649

4750
public static class LocalGVFSConfig

GVFS/GVFS.Common/GitStatusCache.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class GitStatusCache : IDisposable
5252

5353
private object cacheFileLock = new object();
5454

55-
internal static bool TEST_EnableHydrationSummary = true;
55+
internal static bool? TEST_EnableHydrationSummaryOverride = null;
5656

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

342342
private void UpdateHydrationSummary()
343343
{
344-
if (!TEST_EnableHydrationSummary)
344+
bool enabled = TEST_EnableHydrationSummaryOverride ?? this.context.Enlistment.GetStatusHydrationConfig();
345+
if (!enabled)
345346
{
346347
return;
347348
}

GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public string ToMessage()
2828
{
2929
if (!IsValid)
3030
{
31-
return "Error calculating hydration. Run 'gvfs health' for details.";
31+
return "Error calculating hydration summary. Run 'gvfs health' at the repository root for hydration status details.";
3232
}
3333

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

3939
public static EnlistmentHydrationSummary CreateSummary(

GVFS/GVFS.Hooks/Program.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ private static void RunPreCommands(string[] args)
8888
ProcessHelper.Run("gvfs", "prefetch --commits", redirectOutput: false);
8989
break;
9090
case "status":
91-
/* If status is being run to serialize for caching, skip the health display */
92-
if (!args.Any(arg => arg.StartsWith("--serialize", StringComparison.OrdinalIgnoreCase)))
91+
/* If status is being run to serialize for caching, or if --porcelain is specified, skip the health display */
92+
if (!ArgsBlockHydrationStatus(args)
93+
&& ConfigurationAllowsHydrationStatus())
9394
{
9495
/* Display a message about the hydration status of the repo */
9596
ProcessHelper.Run("gvfs", "health --status", redirectOutput: false);
@@ -98,6 +99,30 @@ private static void RunPreCommands(string[] args)
9899
}
99100
}
100101

102+
private static bool ArgsBlockHydrationStatus(string[] args)
103+
{
104+
return args.Any(arg =>
105+
arg.StartsWith("--serialize", StringComparison.OrdinalIgnoreCase)
106+
|| arg.StartsWith("--porcelain", StringComparison.OrdinalIgnoreCase));
107+
}
108+
109+
private static bool ConfigurationAllowsHydrationStatus()
110+
{
111+
try
112+
{
113+
ProcessResult result = ProcessHelper.Run("git", $"config --get {GVFSConstants.GitConfig.ShowHydrationStatus}");
114+
bool hydrationStatusEnabled;
115+
if (bool.TryParse(result.Output.Trim(), out hydrationStatusEnabled))
116+
{
117+
return hydrationStatusEnabled;
118+
}
119+
}
120+
catch (Exception)
121+
{
122+
}
123+
return GVFSConstants.GitConfig.ShowHydrationStatusDefault;
124+
}
125+
101126
private static void ExitWithError(params string[] messages)
102127
{
103128
foreach (string message in messages)

GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void SetUp()
7373
this.fileSystem,
7474
new MockGitRepo(tracer, enlistment, this.fileSystem),
7575
enlistment);
76-
GitStatusCache.TEST_EnableHydrationSummary = false;
76+
GitStatusCache.TEST_EnableHydrationSummaryOverride = false;
7777
}
7878

7979
[TearDown]
@@ -85,7 +85,7 @@ public void TearDown()
8585
this.gitParentPath = null;
8686
this.gvfsMetadataPath = null;
8787
this.enlistmentDirectory = null;
88-
GitStatusCache.TEST_EnableHydrationSummary = true;
88+
GitStatusCache.TEST_EnableHydrationSummaryOverride = null;
8989
}
9090

9191
[TestCase]

0 commit comments

Comments
 (0)