Skip to content

Commit

Permalink
Implement comparison operators designed to detect and report only mea…
Browse files Browse the repository at this point in the history
…ningful changes to the Editor

Now PlasticSourceControlUtils::UpdateCachedStates() only reports that the cache was updated if the state changed in a meaningful way, useful to the Editor

Mainly for the purpose of updating Content Browser overlay icons
  • Loading branch information
SRombautsU committed Feb 2, 2024
1 parent 55d45f1 commit e16c4ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ bool FPlasticSwitchToPartialWorkspaceWorker::Execute(FPlasticSourceControlComman
{
TArray<FString> ProjectFiles;
ProjectFiles.Add(FPaths::ConvertRelativePathToFull(FPaths::GetProjectFilePath()));
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(ProjectFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(ProjectFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}

return InCommand.bCommandSuccessful;
Expand Down Expand Up @@ -1175,7 +1175,7 @@ bool FPlasticSwitchToBranchWorker::Execute(FPlasticSourceControlCommand& InComma
{
// the current branch is used to asses the status of Retained Locks
GetProvider().SetBranchName(Operation->BranchName);
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(Operation->UpdatedFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, 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 @@ -1204,7 +1204,7 @@ bool FPlasticMergeBranchWorker::Execute(FPlasticSourceControlCommand& InCommand)
// now update the status of the updated files
if (Operation->UpdatedFiles.Num())
{
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(Operation->UpdatedFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, 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
13 changes: 13 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlState.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ class FPlasticSourceControlState : public ISourceControlState
Move(MoveTemp(InState));
}

// Comparison operator designed to detect and report only meaningful changes to the Editor, mainly for the purpose of updating Content Browser overlay icons
bool operator==(const FPlasticSourceControlState& InState) const
{
return (WorkspaceState == InState.WorkspaceState)
&& (LockedBy == InState.LockedBy)
&& (RetainedBy == InState.RetainedBy)
&& (IsCurrent() == InState.IsCurrent());
}
bool operator!=(const FPlasticSourceControlState& InState) const
{
return !(*this == InState);
}

const FPlasticSourceControlState& operator=(FPlasticSourceControlState&& InState)
{
Move(MoveTemp(InState));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,20 @@ bool UpdateCachedStates(TArray<FPlasticSourceControlState>&& InStates)
FPlasticSourceControlProvider& Provider = FPlasticSourceControlModule::Get().GetProvider();
const FDateTime Now = FDateTime::Now();

bool bUpdatedStates = false;
for (auto&& InState : InStates)
{
TSharedRef<FPlasticSourceControlState, ESPMode::ThreadSafe> State = Provider.GetStateInternal(InState.LocalFilename);
// Only report that the cache was updated if the state changed in a meaningful way, useful to the Editor
if (*State != InState)
{
bUpdatedStates = true;
}
*State = MoveTemp(InState);
State->TimeStamp = Now;
}

return (InStates.Num() > 0);
return bUpdatedStates;
}

void RemoveRedundantErrors(FPlasticSourceControlCommand& InCommand, const FString& InFilter)
Expand Down

0 comments on commit e16c4ab

Please sign in to comment.