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
12 changes: 0 additions & 12 deletions Scalar.Common/Http/CacheServerResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static string GetUrlFromConfig(Enlistment enlistment)
// TODO 1057500: Remove support for encoded-repo-url cache config setting
return
GetValueFromConfig(git, ScalarConstants.GitConfig.CacheServer, localOnly: true)
?? GetValueFromConfig(git, GetDeprecatedCacheConfigSettingName(enlistment), localOnly: false)
?? enlistment.RepoUrl;
}

Expand Down Expand Up @@ -144,17 +143,6 @@ private static string GetValueFromConfig(GitProcess git, string configName, bool
return value;
}

private static string GetDeprecatedCacheConfigSettingName(Enlistment enlistment)
{
string sectionUrl =
enlistment.RepoUrl.ToLowerInvariant()
.Replace("https://", string.Empty)
.Replace("http://", string.Empty)
.Replace('/', '.');

return ScalarConstants.GitConfig.ScalarPrefix + sectionUrl + ScalarConstants.GitConfig.DeprecatedCacheEndpointSuffix;
}

private CacheServerInfo CreateNone()
{
return new CacheServerInfo(this.enlistment.RepoUrl, CacheServerInfo.ReservedNames.None);
Expand Down
53 changes: 0 additions & 53 deletions Scalar.Common/RepoMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,61 +130,10 @@ public void SaveCloneMetadata(ITracer tracer, ScalarEnlistment enlistment)
{
new KeyValuePair<string, string>(Keys.DiskLayoutMajorVersion, ScalarPlatform.Instance.DiskLayoutUpgrade.Version.CurrentMajorVersion.ToString()),
new KeyValuePair<string, string>(Keys.DiskLayoutMinorVersion, ScalarPlatform.Instance.DiskLayoutUpgrade.Version.CurrentMinorVersion.ToString()),
new KeyValuePair<string, string>(Keys.GitObjectsRoot, enlistment.GitObjectsRoot),
new KeyValuePair<string, string>(Keys.LocalCacheRoot, enlistment.LocalCacheRoot),
new KeyValuePair<string, string>(Keys.EnlistmentId, CreateNewEnlistmentId(tracer)),
});
}

public bool TryGetGitObjectsRoot(out string gitObjectsRoot, out string error)
{
gitObjectsRoot = null;

try
{
if (!this.repoMetadata.TryGetValue(Keys.GitObjectsRoot, out gitObjectsRoot))
{
error = "Git objects root not found";
return false;
}
}
catch (FileBasedCollectionException ex)
{
error = ex.Message;
return false;
}

error = null;
return true;
}

public void SetGitObjectsRoot(string gitObjectsRoot)
{
this.repoMetadata.SetValueAndFlush(Keys.GitObjectsRoot, gitObjectsRoot);
}

public bool TryGetLocalCacheRoot(out string localCacheRoot, out string error)
{
localCacheRoot = null;

try
{
if (!this.repoMetadata.TryGetValue(Keys.LocalCacheRoot, out localCacheRoot))
{
error = "Local cache root not found";
return false;
}
}
catch (FileBasedCollectionException ex)
{
error = ex.Message;
return false;
}

error = null;
return true;
}

public void SetEntry(string keyName, string valueName)
{
this.repoMetadata.SetValueAndFlush(keyName, valueName);
Expand All @@ -203,8 +152,6 @@ public static class Keys
{
public const string DiskLayoutMajorVersion = "DiskLayoutVersion";
public const string DiskLayoutMinorVersion = "DiskLayoutMinorVersion";
public const string GitObjectsRoot = "GitObjectsRoot";
public const string LocalCacheRoot = "LocalCacheRoot";
public const string EnlistmentId = "EnlistmentId";
}
}
Expand Down
4 changes: 2 additions & 2 deletions Scalar.Common/ScalarConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static class GitConfig
public const string GitStatusCacheBackoffConfig = ScalarPrefix + "status-cache-backoff-seconds";
public const string MountId = ScalarPrefix + "mount-id";
public const string EnlistmentId = ScalarPrefix + "enlistment-id";
public const string CacheServer = ScalarPrefix + "cache-server";
public const string DeprecatedCacheEndpointSuffix = ".cache-server-url";
public const string CacheServer = "gvfs.cache-server";
public const string ObjectCache = "gvfs.sharedCache";
public const string ScalarTelemetryId = GitConfig.ScalarPrefix + "telemetry-id";
public const string ScalarTelemetryPipe = GitConfig.ScalarPrefix + "telemetry-pipe";
public const string IKey = GitConfig.ScalarPrefix + "ikey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CacheServerTests : TestsWithEnlistmentPerFixture
[TestCase]
public void SettingGitConfigChangesCacheServer()
{
ProcessResult result = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "config scalar.cache-server " + CustomUrl);
ProcessResult result = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "config gvfs.cache-server " + CustomUrl);
result.ExitCode.ShouldEqual(0, result.Errors);

this.Enlistment.GetCacheServer().ShouldContain("Using cache server: User Defined (" + CustomUrl + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ public void CloneWithDefaultLocalCacheLocation()

string dotScalarRoot = Path.Combine(newEnlistmentRoot, ScalarTestConfig.DotScalarRoot);
dotScalarRoot.ShouldBeADirectory(fileSystem);
string localCacheRoot = ScalarHelpers.GetPersistedLocalCacheRoot(dotScalarRoot);
string gitObjectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(dotScalarRoot);
string gitObjectsRoot = ScalarHelpers.GetGitObjectsRoot(Path.Combine(newEnlistmentRoot, "src"));

string defaultScalarCacheRoot = Path.Combine(homeDirectory, ".scalarCache");
localCacheRoot.StartsWith(defaultScalarCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Local cache root did not default to using {homeDirectory}");
gitObjectsRoot.StartsWith(defaultScalarCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}");

RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot);
Expand Down
60 changes: 7 additions & 53 deletions Scalar.FunctionalTests/Tests/EnlistmentPerFixture/MountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,60 +119,14 @@ public void MountFailsWhenNoOnDiskVersion()
}

[TestCase]
public void MountFailsWhenNoLocalCacheRootInRepoMetadata()
public void MountFailsWhenNoGitObjectsRootInGitConfig()
{
this.Enlistment.UnmountScalar();
string gitObjectsRoot = ScalarHelpers.GetGitObjectsRoot(this.Enlistment.RepoRoot);

string majorVersion;
string minorVersion;
ScalarHelpers.GetPersistedDiskLayoutVersion(this.Enlistment.DotScalarRoot, out majorVersion, out minorVersion);
majorVersion.ShouldNotBeNull();
minorVersion.ShouldNotBeNull();

string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(this.Enlistment.DotScalarRoot).ShouldNotBeNull();

string metadataPath = Path.Combine(this.Enlistment.DotScalarRoot, ScalarHelpers.RepoMetadataName);
string metadataBackupPath = metadataPath + ".backup";
this.fileSystem.MoveFile(metadataPath, metadataBackupPath);

this.fileSystem.CreateEmptyFile(metadataPath);
ScalarHelpers.SaveDiskLayoutVersion(this.Enlistment.DotScalarRoot, majorVersion, minorVersion);
ScalarHelpers.SaveGitObjectsRoot(this.Enlistment.DotScalarRoot, objectsRoot);

this.MountShouldFail("Failed to determine local cache path from repo metadata");

this.fileSystem.DeleteFile(metadataPath);
this.fileSystem.MoveFile(metadataBackupPath, metadataPath);

this.Enlistment.MountScalar();
}

[TestCase]
public void MountFailsWhenNoGitObjectsRootInRepoMetadata()
{
this.Enlistment.UnmountScalar();

string majorVersion;
string minorVersion;
ScalarHelpers.GetPersistedDiskLayoutVersion(this.Enlistment.DotScalarRoot, out majorVersion, out minorVersion);
majorVersion.ShouldNotBeNull();
minorVersion.ShouldNotBeNull();

string localCacheRoot = ScalarHelpers.GetPersistedLocalCacheRoot(this.Enlistment.DotScalarRoot).ShouldNotBeNull();

string metadataPath = Path.Combine(this.Enlistment.DotScalarRoot, ScalarHelpers.RepoMetadataName);
string metadataBackupPath = metadataPath + ".backup";
this.fileSystem.MoveFile(metadataPath, metadataBackupPath);

this.fileSystem.CreateEmptyFile(metadataPath);
ScalarHelpers.SaveDiskLayoutVersion(this.Enlistment.DotScalarRoot, majorVersion, minorVersion);
ScalarHelpers.SaveLocalCacheRoot(this.Enlistment.DotScalarRoot, localCacheRoot);

this.MountShouldFail("Failed to determine git objects root from repo metadata");

this.fileSystem.DeleteFile(metadataPath);
this.fileSystem.MoveFile(metadataBackupPath, metadataPath);

GitProcess.Invoke(this.Enlistment.RepoRoot, $"config --local --unset-all {ScalarHelpers.GitConfigObjectCache}");
this.MountShouldFail("Failed to determine git objects root from git config");
GitProcess.Invoke(this.Enlistment.RepoRoot, $"config--local {ScalarHelpers.GitConfigObjectCache} {gitObjectsRoot}");
this.Enlistment.MountScalar();
}

Expand All @@ -181,7 +135,7 @@ public void MountRegeneratesAlternatesFileWhenMissingGitObjectsRoot()
{
this.Enlistment.UnmountScalar();

string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(this.Enlistment.DotScalarRoot).ShouldNotBeNull();
string objectsRoot = ScalarHelpers.GetGitObjectsRoot(this.Enlistment.RepoRoot);

string alternatesFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "objects", "info", "alternates");
alternatesFilePath.ShouldBeAFile(this.fileSystem).WithContents(objectsRoot);
Expand All @@ -197,7 +151,7 @@ public void MountRegeneratesAlternatesFileWhenMissingFromDisk()
{
this.Enlistment.UnmountScalar();

string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(this.Enlistment.DotScalarRoot).ShouldNotBeNull();
string objectsRoot = ScalarHelpers.GetGitObjectsRoot(this.Enlistment.RepoRoot);

string alternatesFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "objects", "info", "alternates");
alternatesFilePath.ShouldBeAFile(this.fileSystem).WithContents(objectsRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void DeleteObjectsCacheAndCacheMappingBeforeMount()

enlistment1.UnmountScalar();

string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(enlistment1.DotScalarRoot).ShouldNotBeNull();
string objectsRoot = ScalarHelpers.GetGitObjectsRoot(enlistment1.RepoRoot);
objectsRoot.ShouldBeADirectory(this.fileSystem);
RepositoryHelpers.DeleteTestDirectory(objectsRoot);

Expand Down Expand Up @@ -153,7 +153,7 @@ public void MountReusesLocalCacheKeyWhenGitObjectsRootDeleted()
enlistment.UnmountScalar();

// Find the current git objects root and ensure it's on disk
string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(enlistment.DotScalarRoot).ShouldNotBeNull();
string objectsRoot = ScalarHelpers.GetGitObjectsRoot(enlistment.RepoRoot);
objectsRoot.ShouldBeADirectory(this.fileSystem);

string mappingFilePath = Path.Combine(enlistment.LocalCacheRoot, "mapping.dat");
Expand All @@ -165,7 +165,7 @@ public void MountReusesLocalCacheKeyWhenGitObjectsRootDeleted()

enlistment.MountScalar();

ScalarHelpers.GetPersistedGitObjectsRoot(enlistment.DotScalarRoot).ShouldEqual(objectsRoot);
ScalarHelpers.GetGitObjectsRoot(enlistment.RepoRoot).ShouldEqual(objectsRoot);
objectsRoot.ShouldBeADirectory(this.fileSystem);
mappingFilePath.ShouldBeAFile(this.fileSystem).WithContents(mappingFileContents);

Expand All @@ -180,7 +180,7 @@ public void MountUsesNewLocalCacheKeyWhenLocalCacheDeleted()
enlistment.UnmountScalar();

// Find the current git objects root and ensure it's on disk
string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(enlistment.DotScalarRoot).ShouldNotBeNull();
string objectsRoot = ScalarHelpers.GetGitObjectsRoot(enlistment.RepoRoot);
objectsRoot.ShouldBeADirectory(this.fileSystem);

string mappingFilePath = Path.Combine(enlistment.LocalCacheRoot, "mapping.dat");
Expand All @@ -204,7 +204,7 @@ public void MountUsesNewLocalCacheKeyWhenLocalCacheDeleted()

// Validate the new objects root is on disk and uses the new key
objectsRoot.ShouldNotExistOnDisk(this.fileSystem);
string newObjectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(enlistment.DotScalarRoot);
string newObjectsRoot = ScalarHelpers.GetGitObjectsRoot(enlistment.RepoRoot);
newObjectsRoot.ShouldNotEqual(objectsRoot);
newObjectsRoot.ShouldContain(newCacheKey);
newObjectsRoot.ShouldBeADirectory(this.fileSystem);
Expand Down Expand Up @@ -247,7 +247,7 @@ private ScalarFunctionalTestEnlistment CloneAndMountEnlistment(string branch = n

private void AlternatesFileShouldHaveGitObjectsRoot(ScalarFunctionalTestEnlistment enlistment)
{
string objectsRoot = ScalarHelpers.GetPersistedGitObjectsRoot(enlistment.DotScalarRoot);
string objectsRoot = ScalarHelpers.GetGitObjectsRoot(enlistment.RepoRoot);
string alternatesFileContents = Path.Combine(enlistment.RepoRoot, ".git", "objects", "info", "alternates").ShouldBeAFile(this.fileSystem).WithContents();
alternatesFileContents.ShouldEqual(objectsRoot);
}
Expand Down
29 changes: 7 additions & 22 deletions Scalar.FunctionalTests/Tools/ScalarHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ public static class ScalarHelpers
public const string ModifiedPathsNewLine = "\r\n";
public const string PlaceholderFieldDelimiter = "\0";

public const string GitConfigObjectCache = "gvfs.sharedCache";

public static readonly string BackgroundOpsFile = Path.Combine("databases", "BackgroundGitOperations.dat");
public static readonly string PlaceholderListFile = Path.Combine("databases", "PlaceholderList.dat");
public static readonly string RepoMetadataName = Path.Combine("databases", "RepoMetadata.dat");

private const string ModifedPathsLineAddPrefix = "A ";
private const string ModifedPathsLineDeletePrefix = "D ";

private const string DiskLayoutMajorVersionKey = "DiskLayoutVersion";
private const string DiskLayoutMinorVersionKey = "DiskLayoutMinorVersion";
private const string LocalCacheRootKey = "LocalCacheRoot";
private const string GitObjectsRootKey = "GitObjectsRoot";
private const string BlobSizesRootKey = "BlobSizesRoot";

public static string ConvertPathToGitFormat(string path)
Expand All @@ -44,24 +41,12 @@ public static void GetPersistedDiskLayoutVersion(string dotScalarRoot, out strin
minorVersion = GetPersistedValue(dotScalarRoot, DiskLayoutMinorVersionKey);
}

public static void SaveLocalCacheRoot(string dotScalarRoot, string value)
{
SavePersistedValue(dotScalarRoot, LocalCacheRootKey, value);
}

public static string GetPersistedLocalCacheRoot(string dotScalarRoot)
{
return GetPersistedValue(dotScalarRoot, LocalCacheRootKey);
}

public static void SaveGitObjectsRoot(string dotScalarRoot, string value)
{
SavePersistedValue(dotScalarRoot, GitObjectsRootKey, value);
}

public static string GetPersistedGitObjectsRoot(string dotScalarRoot)
public static string GetGitObjectsRoot(string repoRoot)
{
return GetPersistedValue(dotScalarRoot, GitObjectsRootKey);
ProcessResult result = GitProcess.InvokeProcess(repoRoot, $"config --local {ScalarHelpers.GitConfigObjectCache}");
result.ExitCode.ShouldEqual(0, $"Failed to read git object root from config, error: {result.ExitCode}");
string.IsNullOrWhiteSpace(result.Output).ShouldBeFalse($"{ScalarHelpers.GitConfigObjectCache} should be set");
return result.Output.TrimEnd('\n');
}

public static string GetPersistedBlobSizesRoot(string dotScalarRoot)
Expand Down
13 changes: 5 additions & 8 deletions Scalar.Mount/InProcessMount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,14 @@ public void Mount(EventLevel verbosity, Keywords keywords)
}

string gitObjectsRoot;
if (!RepoMetadata.Instance.TryGetGitObjectsRoot(out gitObjectsRoot, out error))
GitProcess process = new GitProcess(this.enlistment);
GitProcess.ConfigResult result = process.GetFromLocalConfig(ScalarConstants.GitConfig.ObjectCache);
if (!result.TryParseAsString(out gitObjectsRoot, out error))
{
this.FailMountAndExit("Failed to determine git objects root from repo metadata: " + error);
}

string localCacheRoot;
if (!RepoMetadata.Instance.TryGetLocalCacheRoot(out localCacheRoot, out error))
{
this.FailMountAndExit("Failed to determine local cache path from repo metadata: " + error);
this.FailMountAndExit("Failed to determine git objects root from git config: " + error);
}

string localCacheRoot = Path.GetDirectoryName(gitObjectsRoot);
this.tracer.RelatedEvent(
EventLevel.Informational,
"CachePathsLoaded",
Expand Down
12 changes: 1 addition & 11 deletions Scalar.UnitTests/Common/CacheServerResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ public void CanGetCacheServerFromNewConfig()
CacheServerResolver.GetUrlFromConfig(enlistment).ShouldEqual(CacheServerUrl);
}

[TestCase]
public void CanGetCacheServerFromOldConfig()
{
MockScalarEnlistment enlistment = this.CreateEnlistment(null, CacheServerUrl);
CacheServerInfo cacheServer = CacheServerResolver.GetCacheServerFromConfig(enlistment);

cacheServer.Url.ShouldEqual(CacheServerUrl);
CacheServerResolver.GetUrlFromConfig(enlistment).ShouldEqual(CacheServerUrl);
}

[TestCase]
public void CanGetCacheServerWithNoConfig()
{
Expand Down Expand Up @@ -195,7 +185,7 @@ private MockScalarEnlistment CreateEnlistment(string newConfigValue = null, stri
{
MockGitProcess gitProcess = new MockGitProcess();
gitProcess.SetExpectedCommandResult(
"config --local scalar.cache-server",
"config --local gvfs.cache-server",
() => new GitProcess.Result(newConfigValue ?? string.Empty, string.Empty, newConfigValue != null ? GitProcess.Result.SuccessCode : GitProcess.Result.GenericFailureCode));
gitProcess.SetExpectedCommandResult(
"config scalar.mock:..repourl.cache-server-url",
Expand Down
2 changes: 1 addition & 1 deletion Scalar/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private Result CreateClone()
}

string errorMessage;
if (!this.TryCreateAlternatesFile(this.fileSystem, this.enlistment, out errorMessage))
if (!this.TrySetObjectCacheLocation(this.fileSystem, this.enlistment, out errorMessage))
{
return new Result("Error configuring alternate: " + errorMessage);
}
Expand Down
Loading