Skip to content

Commit 9dc0a9b

Browse files
committed
RepoMetadata: remove LocalCacheRoot and GitObjectsRoot
Update Scalar to depend on the local git config for the git objects root and the local cache root and remove them from RepoMetadata.dat
1 parent e192f53 commit 9dc0a9b

5 files changed

Lines changed: 25 additions & 132 deletions

File tree

Scalar.Common/RepoMetadata.cs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -130,61 +130,10 @@ public void SaveCloneMetadata(ITracer tracer, ScalarEnlistment enlistment)
130130
{
131131
new KeyValuePair<string, string>(Keys.DiskLayoutMajorVersion, ScalarPlatform.Instance.DiskLayoutUpgrade.Version.CurrentMajorVersion.ToString()),
132132
new KeyValuePair<string, string>(Keys.DiskLayoutMinorVersion, ScalarPlatform.Instance.DiskLayoutUpgrade.Version.CurrentMinorVersion.ToString()),
133-
new KeyValuePair<string, string>(Keys.GitObjectsRoot, enlistment.GitObjectsRoot),
134-
new KeyValuePair<string, string>(Keys.LocalCacheRoot, enlistment.LocalCacheRoot),
135133
new KeyValuePair<string, string>(Keys.EnlistmentId, CreateNewEnlistmentId(tracer)),
136134
});
137135
}
138136

139-
public bool TryGetGitObjectsRoot(out string gitObjectsRoot, out string error)
140-
{
141-
gitObjectsRoot = null;
142-
143-
try
144-
{
145-
if (!this.repoMetadata.TryGetValue(Keys.GitObjectsRoot, out gitObjectsRoot))
146-
{
147-
error = "Git objects root not found";
148-
return false;
149-
}
150-
}
151-
catch (FileBasedCollectionException ex)
152-
{
153-
error = ex.Message;
154-
return false;
155-
}
156-
157-
error = null;
158-
return true;
159-
}
160-
161-
public void SetGitObjectsRoot(string gitObjectsRoot)
162-
{
163-
this.repoMetadata.SetValueAndFlush(Keys.GitObjectsRoot, gitObjectsRoot);
164-
}
165-
166-
public bool TryGetLocalCacheRoot(out string localCacheRoot, out string error)
167-
{
168-
localCacheRoot = null;
169-
170-
try
171-
{
172-
if (!this.repoMetadata.TryGetValue(Keys.LocalCacheRoot, out localCacheRoot))
173-
{
174-
error = "Local cache root not found";
175-
return false;
176-
}
177-
}
178-
catch (FileBasedCollectionException ex)
179-
{
180-
error = ex.Message;
181-
return false;
182-
}
183-
184-
error = null;
185-
return true;
186-
}
187-
188137
public void SetEntry(string keyName, string valueName)
189138
{
190139
this.repoMetadata.SetValueAndFlush(keyName, valueName);
@@ -203,8 +152,6 @@ public static class Keys
203152
{
204153
public const string DiskLayoutMajorVersion = "DiskLayoutVersion";
205154
public const string DiskLayoutMinorVersion = "DiskLayoutMinorVersion";
206-
public const string GitObjectsRoot = "GitObjectsRoot";
207-
public const string LocalCacheRoot = "LocalCacheRoot";
208155
public const string EnlistmentId = "EnlistmentId";
209156
}
210157
}

Scalar.FunctionalTests/Tests/EnlistmentPerFixture/MountTests.cs

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -119,60 +119,15 @@ public void MountFailsWhenNoOnDiskVersion()
119119
}
120120

121121
[TestCase]
122-
public void MountFailsWhenNoLocalCacheRootInRepoMetadata()
122+
public void MountFailsWhenNoGitObjectsRootInGitConfig()
123123
{
124124
this.Enlistment.UnmountScalar();
125+
string gitObjectsRoot = GitProcess.Invoke(this.Enlistment.RepoRoot, "config --local gvfs.sharedCache");
126+
string.IsNullOrWhiteSpace(gitObjectsRoot).ShouldBeFalse("gitObjects root should be set");
125127

126-
string majorVersion;
127-
string minorVersion;
128-
ScalarHelpers.GetPersistedDiskLayoutVersion(this.Enlistment.DotScalarRoot, out majorVersion, out minorVersion);
129-
majorVersion.ShouldNotBeNull();
130-
minorVersion.ShouldNotBeNull();
131-
132-
string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(this.Enlistment.DotScalarRoot).ShouldNotBeNull();
133-
134-
string metadataPath = Path.Combine(this.Enlistment.DotScalarRoot, ScalarHelpers.RepoMetadataName);
135-
string metadataBackupPath = metadataPath + ".backup";
136-
this.fileSystem.MoveFile(metadataPath, metadataBackupPath);
137-
138-
this.fileSystem.CreateEmptyFile(metadataPath);
139-
ScalarHelpers.SaveDiskLayoutVersion(this.Enlistment.DotScalarRoot, majorVersion, minorVersion);
140-
ScalarHelpers.SaveGitObjectsRoot(this.Enlistment.DotScalarRoot, objectsRoot);
141-
142-
this.MountShouldFail("Failed to determine local cache path from repo metadata");
143-
144-
this.fileSystem.DeleteFile(metadataPath);
145-
this.fileSystem.MoveFile(metadataBackupPath, metadataPath);
146-
147-
this.Enlistment.MountScalar();
148-
}
149-
150-
[TestCase]
151-
public void MountFailsWhenNoGitObjectsRootInRepoMetadata()
152-
{
153-
this.Enlistment.UnmountScalar();
154-
155-
string majorVersion;
156-
string minorVersion;
157-
ScalarHelpers.GetPersistedDiskLayoutVersion(this.Enlistment.DotScalarRoot, out majorVersion, out minorVersion);
158-
majorVersion.ShouldNotBeNull();
159-
minorVersion.ShouldNotBeNull();
160-
161-
string localCacheRoot = ScalarHelpers.GetPersistedLocalCacheRoot(this.Enlistment.DotScalarRoot).ShouldNotBeNull();
162-
163-
string metadataPath = Path.Combine(this.Enlistment.DotScalarRoot, ScalarHelpers.RepoMetadataName);
164-
string metadataBackupPath = metadataPath + ".backup";
165-
this.fileSystem.MoveFile(metadataPath, metadataBackupPath);
166-
167-
this.fileSystem.CreateEmptyFile(metadataPath);
168-
ScalarHelpers.SaveDiskLayoutVersion(this.Enlistment.DotScalarRoot, majorVersion, minorVersion);
169-
ScalarHelpers.SaveLocalCacheRoot(this.Enlistment.DotScalarRoot, localCacheRoot);
170-
171-
this.MountShouldFail("Failed to determine git objects root from repo metadata");
172-
173-
this.fileSystem.DeleteFile(metadataPath);
174-
this.fileSystem.MoveFile(metadataBackupPath, metadataPath);
175-
128+
GitProcess.Invoke(this.Enlistment.RepoRoot, "config --local --unset-all gvfs.sharedCache");
129+
this.MountShouldFail("Failed to determine git objects root from git config");
130+
GitProcess.Invoke(this.Enlistment.RepoRoot, $"config--local gvfs.sharedCache {gitObjectsRoot}");
176131
this.Enlistment.MountScalar();
177132
}
178133

Scalar.Mount/InProcessMount.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,14 @@ public void Mount(EventLevel verbosity, Keywords keywords)
6464
}
6565

6666
string gitObjectsRoot;
67-
if (!RepoMetadata.Instance.TryGetGitObjectsRoot(out gitObjectsRoot, out error))
67+
GitProcess process = new GitProcess(this.enlistment);
68+
GitProcess.ConfigResult result = process.GetFromLocalConfig(ScalarConstants.GitConfig.ObjectCache);
69+
if (!result.TryParseAsString(out gitObjectsRoot, out error))
6870
{
69-
this.FailMountAndExit("Failed to determine git objects root from repo metadata: " + error);
70-
}
71-
72-
string localCacheRoot;
73-
if (!RepoMetadata.Instance.TryGetLocalCacheRoot(out localCacheRoot, out error))
74-
{
75-
this.FailMountAndExit("Failed to determine local cache path from repo metadata: " + error);
71+
this.FailMountAndExit("Failed to determine git objects root from git config: " + error);
7672
}
7773

74+
string localCacheRoot = Path.GetDirectoryName(gitObjectsRoot);
7875
this.tracer.RelatedEvent(
7976
EventLevel.Informational,
8077
"CachePathsLoaded",

Scalar/CommandLine/DiagnoseVerb.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,14 @@ private void GetLocalCachePaths(ScalarEnlistment enlistment, out string localCac
271271
using (ITracer tracer = new JsonTracer(ScalarConstants.ScalarEtwProviderName, "DiagnoseVerb"))
272272
{
273273
string error;
274-
if (RepoMetadata.TryInitialize(tracer, Path.Combine(enlistment.EnlistmentRoot, ScalarPlatform.Instance.Constants.DotScalarRoot), out error))
274+
GitProcess process = new GitProcess(enlistment);
275+
GitProcess.ConfigResult result = process.GetFromLocalConfig(ScalarConstants.GitConfig.ObjectCache);
276+
if (!result.TryParseAsString(out gitObjectsRoot, out error))
275277
{
276-
RepoMetadata.Instance.TryGetLocalCacheRoot(out localCacheRoot, out error);
277-
RepoMetadata.Instance.TryGetGitObjectsRoot(out gitObjectsRoot, out error);
278-
}
279-
else
280-
{
281-
this.WriteMessage("Failed to determine local cache path and git objects root, RepoMetadata error: " + error);
278+
this.WriteMessage("Failed to determine local cache path and git objects root: " + error);
282279
}
280+
281+
localCacheRoot = Path.GetDirectoryName(gitObjectsRoot);
283282
}
284283
}
285284
catch (Exception e)

Scalar/CommandLine/ScalarVerb.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -806,33 +806,31 @@ protected void InitializeLocalCacheAndObjectsPaths(
806806
this.ReportErrorAndExit(tracer, "Failed to initialize repo metadata: " + error);
807807
}
808808

809-
this.InitializeCachePathsFromRepoMetadata(tracer, enlistment);
809+
this.InitializeCachePaths(tracer, enlistment);
810810
this.EnsureLocalCacheIsHealthy(tracer, enlistment, retryConfig, serverScalarConfig, cacheServer);
811811

812812
RepoMetadata.Shutdown();
813813
}
814814

815-
private void InitializeCachePathsFromRepoMetadata(
815+
private void InitializeCachePaths(
816816
ITracer tracer,
817817
ScalarEnlistment enlistment)
818818
{
819819
string error;
820820
string gitObjectsRoot;
821-
if (!RepoMetadata.Instance.TryGetGitObjectsRoot(out gitObjectsRoot, out error))
821+
GitProcess process = new GitProcess(enlistment);
822+
GitProcess.ConfigResult result = process.GetFromLocalConfig(ScalarConstants.GitConfig.ObjectCache);
823+
if (!result.TryParseAsString(out gitObjectsRoot, out error))
822824
{
823-
this.ReportErrorAndExit(tracer, "Failed to determine git objects root from repo metadata: " + error);
825+
this.ReportErrorAndExit("Failed to determine git objects root from git config: " + error);
824826
}
825827

826828
if (string.IsNullOrWhiteSpace(gitObjectsRoot))
827829
{
828830
this.ReportErrorAndExit(tracer, "Invalid git objects root (empty or whitespace)");
829831
}
830832

831-
string localCacheRoot;
832-
if (!RepoMetadata.Instance.TryGetLocalCacheRoot(out localCacheRoot, out error))
833-
{
834-
this.ReportErrorAndExit(tracer, "Failed to determine local cache path from repo metadata: " + error);
835-
}
833+
string localCacheRoot = Path.GetDirectoryName(gitObjectsRoot);
836834

837835
if (string.IsNullOrWhiteSpace(localCacheRoot))
838836
{
@@ -984,14 +982,11 @@ private void EnsureLocalCacheIsHealthy(
984982
this.ReportErrorAndExit(tracer, "Failed to create objects, pack, and sizes folders");
985983
}
986984

987-
tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Creating new alternates file");
985+
tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Creating new alternates file and setting object cache in git config");
988986
if (!this.TrySetObjectCacheLocation(fileSystem, enlistment, out error))
989987
{
990988
this.ReportErrorAndExit(tracer, $"Failed to update alterates file with new objects path: {error}");
991989
}
992-
993-
tracer.RelatedInfo($"{nameof(this.EnsureLocalCacheIsHealthy)}: Saving git objects root ({enlistment.GitObjectsRoot}) in repo metadata");
994-
RepoMetadata.Instance.SetGitObjectsRoot(enlistment.GitObjectsRoot);
995990
}
996991
}
997992

0 commit comments

Comments
 (0)