Skip to content

Commit

Permalink
Merge pull request #52 from PlasticSCM/1002225-fix-sync-in-partial-wo…
Browse files Browse the repository at this point in the history
…rkspace

Fix sync/update workspace in partial workspace
  • Loading branch information
juliomaqueda committed Nov 29, 2022
2 parents d99d848 + d47029d commit 59a901e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ bool FPlasticSyncWorker::Execute(FPlasticSourceControlCommand& InCommand)
TRACE_CPUPROFILER_EVENT_SCOPE(FPlasticSyncWorker::Execute);

TArray<FString> UpdatedFiles;
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunSync(InCommand.Files, GetProvider().IsPartialWorkspace(), UpdatedFiles, InCommand.ErrorMessages);
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdate(InCommand.Files, GetProvider().IsPartialWorkspace(), UpdatedFiles, InCommand.ErrorMessages);

// now update the status of the corresponding files
if (UpdatedFiles.Num())
Expand Down
53 changes: 45 additions & 8 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,9 +1395,9 @@ bool RunGetHistory(const bool bInUpdateHistory, TArray<FPlasticSourceControlStat
</List>
</UpdatedItems>
*/
static bool ParseSyncResults(const FXmlFile& InXmlResult, TArray<FString>& OutFiles)
static bool ParseUpdateResults(const FXmlFile& InXmlResult, TArray<FString>& OutFiles)
{
TRACE_CPUPROFILER_EVENT_SCOPE(PlasticSourceControlUtils::ParseHistoryResults);
TRACE_CPUPROFILER_EVENT_SCOPE(PlasticSourceControlUtils::ParseUpdateResults);

static const FString UpdatedItems(TEXT("UpdatedItems"));
static const FString List(TEXT("List"));
Expand Down Expand Up @@ -1430,18 +1430,48 @@ static bool ParseSyncResults(const FXmlFile& InXmlResult, TArray<FString>& OutFi
return true;
}


/* Parse results of the 'cm partial update --report --machinereadable' command.
*
* Results of the update command looks like that:
STAGE Plastic is updating your workspace. Wait a moment, please...
STAGE Updated 63.01 KB of 63.01 KB (12 of 12 files to download / 16 of 21 operations to apply) /Content/Collections/SebSharedCollection.collection
AD c:\Workspace\UE5PlasticPluginDev\Content\LevelPrototyping\Materials\MI_Solid_Red.uasset
CH c:\Workspace\UE5PlasticPluginDev\Config\DefaultEditor.ini
DE c:\Workspace\UE5PlasticPluginDev\Content\Collections\SebSharedCollection.collection
*/
static bool ParseUpdateResults(const TArray<FString>& InResults, TArray<FString>& OutFiles)
{
TRACE_CPUPROFILER_EVENT_SCOPE(PlasticSourceControlUtils::ParseUpdateResultsString);

static const FString Stage = TEXT("STAGE ");
static const int32 PrefixLen = 3; // "XX " typically "CH ", "AD " or "DE "

for (const FString& Result : InResults)
{
if (Result.StartsWith(Stage))
continue;

FString Filename = Result.RightChop(PrefixLen);
FPaths::NormalizeFilename(Filename);
OutFiles.Add(Filename);
}

return true;
}

// Run a Plastic "update" command to sync the workspace and parse its XML results.
bool RunSync(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace, TArray<FString>& OutUpdatedFiles, TArray<FString>& OutErrorMessages)
bool RunUpdate(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace, TArray<FString>& OutUpdatedFiles, TArray<FString>& OutErrorMessages)
{
bool bResult = false;

TArray<FString> InfoMessages;
TArray<FString> Parameters;
// Update specified directory to the head of the repository
// Detect special case for a partial checkout (CS:-1 in Gluon mode)!
if (!bInIsPartialWorkspace)
{
const FScopedTempFile TempFile;
TArray<FString> InfoMessages;
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *TempFile.GetFilename()));
Parameters.Add(TEXT("--encoding=\"utf-8\""));
Parameters.Add(TEXT("--last"));
Expand All @@ -1455,23 +1485,30 @@ bool RunSync(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace, T
{
FXmlFile XmlFile;
{
TRACE_CPUPROFILER_EVENT_SCOPE(PlasticSourceControlUtils::RunSync::FXmlFile::LoadFile);
TRACE_CPUPROFILER_EVENT_SCOPE(PlasticSourceControlUtils::RunUpdate::FXmlFile::LoadFile);
bResult = XmlFile.LoadFile(Results, EConstructMethod::ConstructFromBuffer);
}
if (bResult)
{
bResult = ParseSyncResults(XmlFile, OutUpdatedFiles);
bResult = ParseUpdateResults(XmlFile, OutUpdatedFiles);
}
else
{
UE_LOG(LogSourceControl, Error, TEXT("RunSync: XML parse error '%s'"), *XmlFile.GetLastError())
UE_LOG(LogSourceControl, Error, TEXT("RunUpdate: XML parse error '%s'"), *XmlFile.GetLastError())
}
}
}
}
else
{
bResult = PlasticSourceControlUtils::RunCommand(TEXT("partial update"), Parameters, InFiles, InfoMessages, OutErrorMessages);
TArray<FString> Results;
Parameters.Add(TEXT("--report"));
Parameters.Add(TEXT("--machinereadable"));
bResult = PlasticSourceControlUtils::RunCommand(TEXT("partial update"), Parameters, InFiles, Results, OutErrorMessages);
if (bResult)
{
bResult = ParseUpdateResults(Results, OutUpdatedFiles);
}
}

return bResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool RunGetHistory(const bool bInUpdateHistory, TArray<FPlasticSourceControlStat
* @param OutUpdatedFiles The files that where updated
* @param OutErrorMessages Any errors (from StdErr) as an array per-line
*/
bool RunSync(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace, TArray<FString>& OutUpdatedFiles, TArray<FString>& OutErrorMessages);
bool RunUpdate(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace, TArray<FString>& OutUpdatedFiles, TArray<FString>& OutErrorMessages);

#if ENGINE_MAJOR_VERSION == 5

Expand Down

0 comments on commit 59a901e

Please sign in to comment.