Skip to content

Commit

Permalink
Replace FindRootDirectory() that was searching the directory tree for…
Browse files Browse the repository at this point in the history
… a .plastic folder by GetWorkspacePath() calling cm getworkspacefrompath
  • Loading branch information
SRombautsU committed Oct 14, 2022
1 parent ffdeeb5 commit 5ab783e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ void FPlasticSourceControlProvider::CheckPlasticAvailability()
{
// Find the path to the root Plastic directory (if any, else uses the ProjectDir)
const FString PathToProjectDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
bWorkspaceFound = PlasticSourceControlUtils::FindRootDirectory(PathToProjectDir, PathToWorkspaceRoot);

// Launch the Plastic SCM cli shell on the background to issue all commands during this session
bPlasticAvailable = PlasticSourceControlShell::Launch(PathToPlasticBinary, PathToWorkspaceRoot);
bPlasticAvailable = PlasticSourceControlShell::Launch(PathToPlasticBinary, PathToProjectDir);
if (!bPlasticAvailable)
{
return;
}

bWorkspaceFound = PlasticSourceControlUtils::GetWorkspacePath(PathToProjectDir, PathToWorkspaceRoot);

bPlasticAvailable = PlasticSourceControlUtils::GetPlasticScmVersion(PlasticScmVersion);
if (!bPlasticAvailable)
{
Expand Down
47 changes: 12 additions & 35 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,44 +68,21 @@ FString FindPlasticBinaryPath()
}

// Find the root of the Plastic workspace, looking from the provided path and upward in its parent directories.
bool FindRootDirectory(const FString& InPath, FString& OutWorkspaceRoot)
bool GetWorkspacePath(const FString& InPath, FString& OutWorkspaceRoot)
{
bool bFound = false;
FString PathToPlasticSubdirectory;
OutWorkspaceRoot = InPath;

auto TrimTrailing = [](FString& Str, const TCHAR Char)
{
int32 Len = Str.Len();
while (Len && Str[Len - 1] == Char)
{
Str.LeftChopInline(1);
Len = Str.Len();
}
};

TrimTrailing(OutWorkspaceRoot, '\\');
TrimTrailing(OutWorkspaceRoot, '/');

while (!bFound && !OutWorkspaceRoot.IsEmpty())
TArray<FString> InfoMessages;
TArray<FString> ErrorMessages;
TArray<FString> Parameters;
Parameters.Add(TEXT("--format={wkpath}"));
Parameters.Add(TEXT("."));
const bool bFound = RunCommand(TEXT("getworkspacefrompath"), Parameters, TArray<FString>(), EConcurrency::Synchronous, InfoMessages, ErrorMessages);
if (bFound && InfoMessages.Num() > 0)
{
// Look for the ".plastic" subdirectory present at the root of every Plastic workspace
PathToPlasticSubdirectory = OutWorkspaceRoot / TEXT(".plastic");
bFound = FPaths::DirectoryExists(*PathToPlasticSubdirectory);
if (!bFound)
{
int32 LastSlashIndex;
if (OutWorkspaceRoot.FindLastChar(TEXT('/'), LastSlashIndex))
{
OutWorkspaceRoot = OutWorkspaceRoot.Left(LastSlashIndex);
}
else
{
OutWorkspaceRoot.Empty();
}
}
OutWorkspaceRoot = MoveTemp(InfoMessages[0]);
FPaths::NormalizeDirectoryName(OutWorkspaceRoot);
OutWorkspaceRoot.AppendChar(TEXT('/'));
}
if (!bFound)
else
{
OutWorkspaceRoot = InPath; // If not found, return the provided dir as best possible root.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FString FindPlasticBinaryPath();
* @param OutWorkspaceRoot The path to the root directory of the Plastic workspace if found, else the path to the GameDir
* @returns true if the command succeeded and returned no errors
*/
bool FindRootDirectory(const FString& InPathToGameDir, FString& OutWorkspaceRoot);
bool GetWorkspacePath(const FString& InPathToGameDir, FString& OutWorkspaceRoot);

/**
* Get Plastic SCM cli version
Expand Down

0 comments on commit 5ab783e

Please sign in to comment.