Skip to content

Commit

Permalink
Merge pull request #69 from PlasticSCM/1001028-improve-move-status-pe…
Browse files Browse the repository at this point in the history
…rformances

Improve performances of "move" operations by calling status with --controlledchanged instead of --all
  • Loading branch information
mig42 committed Mar 14, 2023
2 parents c7b8bdb + 310b1d0 commit 15b900f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool FPlasticConnectWorker::Execute(FPlasticSourceControlCommand& InCommand)
{
TArray<FString> ContentDir;
ContentDir.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
PlasticSourceControlUtils::RunUpdateStatus(ContentDir, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(ContentDir, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}
}
else
Expand Down Expand Up @@ -249,7 +249,7 @@ bool FPlasticCheckOutWorker::Execute(FPlasticSourceControlCommand& InCommand)
}

// now update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);

return InCommand.bCommandSuccessful;
}
Expand Down Expand Up @@ -424,7 +424,7 @@ bool FPlasticCheckInWorker::Execute(FPlasticSourceControlCommand& InCommand)
}

// now update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}
else
{
Expand Down Expand Up @@ -520,7 +520,7 @@ bool FPlasticMarkForAddWorker::Execute(FPlasticSourceControlCommand& InCommand)
}

// now update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}
else
{
Expand Down Expand Up @@ -563,7 +563,7 @@ bool FPlasticDeleteWorker::Execute(FPlasticSourceControlCommand& InCommand)
}

// now update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);

return InCommand.bCommandSuccessful;
}
Expand Down Expand Up @@ -690,8 +690,9 @@ bool FPlasticRevertWorker::Execute(FPlasticSourceControlCommand& InCommand)

// NOTE: optim, in UE4 there was no need to update the status of our files since this is done immediately after by the Editor, except now that we are using changelists
#if ENGINE_MAJOR_VERSION == 5
// update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
// update the status of our files: need to check for local changes in case of a SoftRevert
const PlasticSourceControlUtils::EStatusSearchType SearchType = bIsSoftRevert ? PlasticSourceControlUtils::EStatusSearchType::All : PlasticSourceControlUtils::EStatusSearchType::ControlledOnly;
PlasticSourceControlUtils::RunUpdateStatus(Files, SearchType, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
#endif

return InCommand.bCommandSuccessful;
Expand Down Expand Up @@ -744,7 +745,7 @@ bool FPlasticRevertUnchangedWorker::Execute(FPlasticSourceControlCommand& InComm
{
Files.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
}
PlasticSourceControlUtils::RunUpdateStatus(Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);

return InCommand.bCommandSuccessful;
}
Expand Down Expand Up @@ -792,8 +793,7 @@ bool FPlasticRevertAllWorker::Execute(FPlasticSourceControlCommand& InCommand)
TArray<FPlasticSourceControlState> TempStates;
TArray<FString> ContentDir;
ContentDir.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
// TODO: here we would just need a fast "status" to only retrieve the local status of files, not server locks etc.
PlasticSourceControlUtils::RunUpdateStatus(ContentDir, false, InCommand.ErrorMessages, TempStates, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(ContentDir, PlasticSourceControlUtils::EStatusSearchType::All, false, InCommand.ErrorMessages, TempStates, InCommand.ChangesetNumber, InCommand.BranchName);

for (auto& State : TempStates)
{
Expand Down Expand Up @@ -842,7 +842,7 @@ bool FPlasticRevertAllWorker::Execute(FPlasticSourceControlCommand& InCommand)
// now update the status of the updated files
if (Operation->UpdatedFiles.Num())
{
PlasticSourceControlUtils::RunUpdateStatus(Operation->UpdatedFiles, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(Operation->UpdatedFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}

return InCommand.bCommandSuccessful;
Expand Down Expand Up @@ -929,7 +929,7 @@ bool FPlasticUpdateStatusWorker::Execute(FPlasticSourceControlCommand& InCommand

if (Files.Num() > 0)
{
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(Files, Operation->ShouldUpdateHistory(), InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(Files, PlasticSourceControlUtils::EStatusSearchType::All, Operation->ShouldUpdateHistory(), InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
// Remove all "is not in a workspace" error and convert the result to "success" if there are no other errors
PlasticSourceControlUtils::RemoveRedundantErrors(InCommand, TEXT("is not in a workspace."));
if (!InCommand.bCommandSuccessful)
Expand Down Expand Up @@ -995,7 +995,7 @@ bool FPlasticUpdateStatusWorker::Execute(FPlasticSourceControlCommand& InCommand
{
TArray<FString> ProjectDirs;
ProjectDirs.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(ProjectDirs, Operation->ShouldUpdateHistory(), InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(ProjectDirs, PlasticSourceControlUtils::EStatusSearchType::All, Operation->ShouldUpdateHistory(), InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}
else
{
Expand Down Expand Up @@ -1155,11 +1155,11 @@ bool FPlasticCopyWorker::Execute(FPlasticSourceControlCommand& InCommand)
InCommand.bCommandSuccessful = true;
}

// now update the status of our files:
// now update the status of our files
TArray<FString> BothFiles;
BothFiles.Add(Origin);
BothFiles.Add(Destination);
PlasticSourceControlUtils::RunUpdateStatus(BothFiles, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(BothFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}
else
{
Expand Down Expand Up @@ -1191,7 +1191,7 @@ bool FPlasticSyncWorker::Execute(FPlasticSourceControlCommand& InCommand)
// now update the status of the updated files
if (UpdatedFiles.Num())
{
PlasticSourceControlUtils::RunUpdateStatus(UpdatedFiles, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(UpdatedFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}

if ((InCommand.Operation->GetName() == FName("SyncAll")))
Expand Down Expand Up @@ -1245,7 +1245,7 @@ bool FPlasticResolveWorker::Execute(FPlasticSourceControlCommand& InCommand)
}

// now update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);

return InCommand.bCommandSuccessful;
}
Expand Down Expand Up @@ -2011,7 +2011,7 @@ bool FPlasticUnshelveWorker::Execute(FPlasticSourceControlCommand& InCommand)
if (InCommand.bCommandSuccessful)
{
// now update the status of our files
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(InCommand.Files, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);

ChangelistToUpdate = InCommand.Changelist;
}
Expand Down
21 changes: 15 additions & 6 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ class FFileVisitor : public IPlatformFile::FDirectoryVisitor
};

/**
* @brief Run a "status" command for a directory to get workspace file states
* @brief Run a "status" command for a directory to get the local workspace file states
*
* ie. Changed, CheckedOut, Copied, Replaced, Added, Private, Ignored, Deleted, LocallyDeleted, Moved, LocallyMoved
*
Expand All @@ -594,12 +594,13 @@ class FFileVisitor : public IPlatformFile::FDirectoryVisitor
*
* @param[in] InDir The path to the common directory of all the files listed after.
* @param[in] InFiles List of files in a directory, or the path to the directory itself (never empty).
* @param[in] InSearchType Call "status" with "--all", or with just "--controlledchanged" when doing only a quick check following a source control operation
* @param[out] OutErrorMessages Error messages from the "status" command
* @param[out] OutStates States of files for witch the status has been gathered (distinct than InFiles in case of a "directory status")
* @param[out] OutChangeset The current Changeset Number
* @param[out] OutBranchName Name of the current checked-out branch
*/
static bool RunStatus(const FString& InDir, TArray<FString>&& InFiles, TArray<FString>& OutErrorMessages, TArray<FPlasticSourceControlState>& OutStates, int32& OutChangeset, FString& OutBranchName)
static bool RunStatus(const FString& InDir, TArray<FString>&& InFiles, const EStatusSearchType InSearchType, TArray<FString>& OutErrorMessages, TArray<FPlasticSourceControlState>& OutStates, int32& OutChangeset, FString& OutBranchName)
{
TRACE_CPUPROFILER_EVENT_SCOPE(PlasticSourceControlUtils::RunStatus);

Expand All @@ -608,8 +609,16 @@ static bool RunStatus(const FString& InDir, TArray<FString>&& InFiles, TArray<FS
TArray<FString> Parameters;
Parameters.Add(TEXT("--compact"));
Parameters.Add(TEXT("--noheaders"));
Parameters.Add(TEXT("--all"));
Parameters.Add(TEXT("--ignored"));
if (InSearchType == EStatusSearchType::All)
{
Parameters.Add(TEXT("--all"));
Parameters.Add(TEXT("--ignored"));
}
else if (InSearchType == EStatusSearchType::ControlledOnly)
{
Parameters.Add(TEXT("--controlledchanged"));
}

// "cm status" only operate on one path (file or directory) at a time, so use one common path for multiple files in a directory
TArray<FString> OnePath;
// Only one file: optim very useful for the .uproject file at the root to avoid parsing the whole repository
Expand Down Expand Up @@ -952,7 +961,7 @@ struct FFilesInCommonDir
};

// Run a batch of Plastic "status" and "fileinfo" commands to update status of given files and directories.
bool RunUpdateStatus(const TArray<FString>& InFiles, const bool bInUpdateHistory, TArray<FString>& OutErrorMessages, TArray<FPlasticSourceControlState>& OutStates, int32& OutChangeset, FString& OutBranchName)
bool RunUpdateStatus(const TArray<FString>& InFiles, const EStatusSearchType InSearchType, const bool bInUpdateHistory, TArray<FString>& OutErrorMessages, TArray<FPlasticSourceControlState>& OutStates, int32& OutChangeset, FString& OutBranchName)
{
bool bResults = true;

Expand Down Expand Up @@ -1047,7 +1056,7 @@ bool RunUpdateStatus(const TArray<FString>& InFiles, const bool bInUpdateHistory
// Run a "status" command on the directory to get workspace file states.
// (ie. Changed, CheckedOut, Copied, Replaced, Added, Private, Ignored, Deleted, LocallyDeleted, Moved, LocallyMoved)
TArray<FPlasticSourceControlState> States;
const bool bGroupOk = RunStatus(Group.Value.CommonDir, MoveTemp(Group.Value.Files), OutErrorMessages, States, OutChangeset, OutBranchName);
const bool bGroupOk = RunStatus(Group.Value.CommonDir, MoveTemp(Group.Value.Files), InSearchType, OutErrorMessages, States, OutChangeset, OutBranchName);
if (!bGroupOk)
{
bResults = false;
Expand Down
11 changes: 10 additions & 1 deletion Source/PlasticSourceControl/Private/PlasticSourceControlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,27 @@ bool RunCommand(const FString& InCommand, const TArray<FString>& InParameters, c
*/
bool RunCommand(const FString& InCommand, const TArray<FString>& InParameters, const TArray<FString>& InFiles, TArray<FString>& OutResults, TArray<FString>& OutErrorMessages);


// Specify the "search type" for the "status" command
enum class EStatusSearchType
{
All, // status --all --ignored (this can take much longer, searching for local changes, especially on the first call)
ControlledOnly // status --controlledchanged
};

/**
* Run a Plastic "status" command and parse it.
*
* @param InFiles The files to be operated on
* @param InSearchType Call "status" with "--all", or with just "--controlledchanged" when doing only a quick check following a source control operation
* @param bInUpdateHistory If getting the history of files, force execute the fileinfo command required to do get RepSpec of xlinks (history view or visual diff)
* @param OutErrorMessages Any errors (from StdErr) as an array per-line
* @param OutStates States of the files
* @param OutChangeset The current Changeset Number
* @param OutBranchName Name of the current checked-out branch
* @returns true if the command succeeded and returned no errors
*/
bool RunUpdateStatus(const TArray<FString>& InFiles, const bool bInUpdateHistory, TArray<FString>& OutErrorMessages, TArray<FPlasticSourceControlState>& OutStates, int32& OutChangeset, FString& OutBranchName);
bool RunUpdateStatus(const TArray<FString>& InFiles, const EStatusSearchType InSearchType, const bool bInUpdateHistory, TArray<FString>& OutErrorMessages, TArray<FPlasticSourceControlState>& OutStates, int32& OutChangeset, FString& OutBranchName);

/**
* Run a Plastic "cat" command to dump the binary content of a revision into a file.
Expand Down

0 comments on commit 15b900f

Please sign in to comment.