Skip to content

Commit

Permalink
Merge pull request dotnet#9236 from drewnoakes/cache-repo-root-path
Browse files Browse the repository at this point in the history
Cache repo root path
  • Loading branch information
drewnoakes committed Aug 23, 2023
2 parents 82e2e6b + 74acaa2 commit 5b2e98f
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Microsoft.VisualStudio.Utilities
{
internal static class RepoUtil
{
private static string? _root;

/// <summary>
/// Gets the absolute path to the checked out location of this repo.
/// </summary>
Expand All @@ -12,18 +14,22 @@ internal static class RepoUtil
/// </remarks>
public static string FindRepoRootPath()
{
// Start with this DLL's location
string path = typeof(RepoUtil).Assembly.Location;

// Walk up the tree until we find the 'artifacts' folder
while (!Path.GetFileName(path).Equals("artifacts", StringComparisons.Paths))
if (_root is null)
{
path = Path.GetDirectoryName(path);
// Start with this DLL's location
string path = typeof(RepoUtil).Assembly.Location;

// Walk up the tree until we find the 'artifacts' folder
while (!Path.GetFileName(path).Equals("artifacts", StringComparisons.Paths))
{
path = Path.GetDirectoryName(path);
}

// Go up one more level
_root = Path.GetDirectoryName(path);
}

// Go up one more level
path = Path.GetDirectoryName(path);
return path;
return _root;
}
}
}

0 comments on commit 5b2e98f

Please sign in to comment.