Skip to content

Commit

Permalink
Merge pull request #41 from PlasticSCM/1001844-fix-checkconnection
Browse files Browse the repository at this point in the history
1001844 Fix checkconnection using the parameter --server=ServerUrl
  • Loading branch information
juliomaqueda authored Oct 13, 2022
2 parents 52a67e7 + 3113ce1 commit fba60ea
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,16 @@ bool FPlasticUpdateStatusWorker::Execute(FPlasticSourceControlCommand& InCommand
PlasticSourceControlUtils::RemoveRedundantErrors(InCommand, TEXT("is not in a workspace."));
if (!InCommand.bCommandSuccessful)
{
TArray<FString> ErrorMessages;
TArray<FString> Parameters;
FString BranchName, RepositoryName, ServerUrl;
if (PlasticSourceControlUtils::GetWorkspaceInfo(BranchName, RepositoryName, ServerUrl, ErrorMessages))
{
Parameters.Add(FString::Printf(TEXT("--server=%s"), *ServerUrl));
}
UE_LOG(LogSourceControl, Error, TEXT("FPlasticUpdateStatusWorker(ErrorMessages.Num()=%d) => checkconnection"), InCommand.ErrorMessages.Num());
// In case of error, execute a 'checkconnection' command to check the connectivity of the server.
InCommand.bConnectionDropped = !PlasticSourceControlUtils::RunCommand(TEXT("checkconnection"), TArray<FString>(), TArray<FString>(), InCommand.Concurrency, InCommand.InfoMessages, InCommand.ErrorMessages);
InCommand.bConnectionDropped = !PlasticSourceControlUtils::RunCommand(TEXT("checkconnection"), Parameters, TArray<FString>(), InCommand.Concurrency, InCommand.InfoMessages, InCommand.ErrorMessages);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ void FPlasticSourceControlProvider::Init(bool bForceConnection)
{
// Execute a 'checkconnection' command to set bServerAvailable based on the connectivity of the server
TArray<FString> InfoMessages, ErrorMessages;
const bool bCommandSuccessful = PlasticSourceControlUtils::RunCommand(TEXT("checkconnection"), TArray<FString>(), TArray<FString>(), EConcurrency::Synchronous, InfoMessages, ErrorMessages);
bServerAvailable = bCommandSuccessful;
if (!bCommandSuccessful)
TArray<FString> Parameters;
if (PlasticSourceControlUtils::GetWorkspaceInfo(BranchName, RepositoryName, ServerUrl, ErrorMessages))
{
Parameters.Add(FString::Printf(TEXT("--server=%s"), *ServerUrl));
}
bServerAvailable = PlasticSourceControlUtils::RunCommand(TEXT("checkconnection"), Parameters, TArray<FString>(), EConcurrency::Synchronous, InfoMessages, ErrorMessages);
if (!bServerAvailable)
{
FMessageLog SourceControlLog("SourceControl");
for (const FString& ErrorMessage : ErrorMessages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static bool ParseWorkspaceInformation(const TArray<FString>& InInfoMessages, int
bResult = false;
}
}
// Get the branch name, in the form "Branch /main@UEPlasticPluginDev" (enabled by the "--wkconfig" flag)
// Get the branch name, in the form "Branch /main@UE5PlasticPluginDev@test@cloud" (enabled by the "--wkconfig" flag)
if (InInfoMessages.Num() > 1)
{
static const FString BranchPrefix(TEXT("Branch "));
Expand Down Expand Up @@ -560,6 +560,50 @@ bool GetWorkspaceInformation(int32& OutChangeset, FString& OutRepositoryName, FS
return bResult;
}

static bool ParseWorkspaceInfo(const TArray<FString>& InInfoMessages, FString& OutBranchName, FString& OutRepositoryName, FString& OutServerUrl)
{
if (InInfoMessages.Num() == 0)
{
return false;
}

// Get workspace information, in the form "Branch /main@UE5PlasticPluginDev@localhost:8087"
// or "Branch /main@UE5PlasticPluginDev@test@cloud" (when connected directly to the cloud)
static const FString BranchPrefix(TEXT("Branch "));
if (!InInfoMessages[0].StartsWith(BranchPrefix, ESearchCase::CaseSensitive))
{
return false;
}
FString Temp = InInfoMessages[0].RightChop(BranchPrefix.Len());
int32 SeparatorIndex;
if (!Temp.FindChar(TEXT('@'), SeparatorIndex))
{
return false;
}
OutBranchName = Temp.Left(SeparatorIndex);
Temp.RightChopInline(SeparatorIndex + 1);
if (!Temp.FindChar(TEXT('@'), SeparatorIndex))
{
return false;
}
OutRepositoryName = Temp.Left(SeparatorIndex);
OutServerUrl = Temp.RightChop(SeparatorIndex + 1);

return true;
}

bool GetWorkspaceInfo(FString& OutRepositoryName, FString& OutServerUrl, FString& OutBranchName, TArray<FString>& OutErrorMessages)
{
TArray<FString> InfoMessages;
bool bResult = RunCommand(TEXT("workspaceinfo"), TArray<FString>(), TArray<FString>(), EConcurrency::Synchronous, InfoMessages, OutErrorMessages);
if (bResult)
{
bResult = ParseWorkspaceInfo(InfoMessages, OutRepositoryName, OutServerUrl, OutBranchName);
}

return bResult;
}

FString UserNameToDisplayName(const FString& InUserName)
{
if (const FString* Result = GetDefault<UPlasticSourceControlProjectSettings>()->UserNameToDisplayName.Find(InUserName))
Expand Down
12 changes: 12 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ bool GetWorkspaceName(const FString& InWorkspaceRoot, FString& OutWorkspaceName,
*/
bool GetWorkspaceInformation(int32& OutChangeset, FString& OutRepositoryName, FString& OutServerUrl, FString& OutBranchName, TArray<FString>& OutErrorMessages);

/**
* Get Plastic repository name, server URL, and branch name
*
* Note: this is a local fast variant, not making network call to the server.
*
* @param OutBranchName Name of the current checked-out branch
* @param OutRepositoryName Name of the repository of the current workspace
* @param OutServerUrl URL/Port of the server of the repository
* @param OutErrorMessages Any errors (from StdErr) as an array per-line
*/
bool GetWorkspaceInfo(FString& OutBranchName, FString& OutRepositoryName, FString& OutServerUrl, TArray<FString>& OutErrorMessages);

/**
* Use the Project Settings to replace Plastic SCM full username/e-mail by a shorter version for display.
*
Expand Down

0 comments on commit fba60ea

Please sign in to comment.