Skip to content

Commit

Permalink
In fact, since we cannot rely anymore on the duo undochange + undoche…
Browse files Browse the repository at this point in the history
…ckout, we should fully embrace the new "undo" command

It means that we don't need to triage files in two arrays of ChangedFiles and CheckedOutFiles (we just add the Origin / Redirectors to the existing Files array)
We also shouldn't add the Origin / Redirector file if it is already listed in the array of Files
  • Loading branch information
SRombautsU committed Nov 23, 2022
1 parent 6a60815 commit 00f3724
Showing 1 changed file with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,50 +541,40 @@ bool FPlasticRevertWorker::Execute(FPlasticSourceControlCommand& InCommand)
Files = InCommand.Files;
}

TArray<FString> ChangedFiles;
TArray<FString> CheckedOutFiles;

for (const FString& File : Files)
for (int i = 0; i < Files.Num(); i++) // Required for loop on index since we are adding to the Files array as we go
{
const FString& File = Files[i];

TSharedRef<FPlasticSourceControlState, ESPMode::ThreadSafe> State = GetProvider().GetStateInternal(File);

if (EWorkspaceState::Changed == State->WorkspaceState)
{
// only revert the changes of the given file in workspace
ChangedFiles.Add(State->LocalFilename);
}
else
if (State->WorkspaceState == EWorkspaceState::Moved)
{
CheckedOutFiles.Add(State->LocalFilename);
// in case of a Moved/Renamed, find the rename origin to revert both at once
if (EWorkspaceState::Moved == State->WorkspaceState)
// In case of a Moved/Renamed, find the rename Origin / Redirector to revert both at once
// (only if it is not already in the list of files to revert)
const FString& MovedFrom = State->MovedFrom;
if (!Files.FindByPredicate([&MovedFrom](const FString& File) { return File.Equals(MovedFrom, ESearchCase::IgnoreCase); }))
{
CheckedOutFiles.Add(State->MovedFrom);

// Delete the redirector
IFileManager::Get().Delete(*State->MovedFrom);
Files.Add(MovedFrom);
}

// Delete the redirector
IFileManager::Get().Delete(*MovedFrom);
}
}

InCommand.bCommandSuccessful = true;

if (ChangedFiles.Num() > 0)
{
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("undo"), TArray<FString>(), ChangedFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
}

if (CheckedOutFiles.Num() > 0)
if (Files.Num() > 0)
{
// revert the checkout and any changes of the given file in workspace
// Detect special case for a partial checkout (CS:-1 in Gluon mode)!
if (-1 != InCommand.ChangesetNumber)
{
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("undocheckout"), TArray<FString>(), CheckedOutFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("undo"), TArray<FString>(), Files, InCommand.InfoMessages, InCommand.ErrorMessages);
}
else
{
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("partial undocheckout"), TArray<FString>(), CheckedOutFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("partial undo"), TArray<FString>(), Files, InCommand.InfoMessages, InCommand.ErrorMessages);
}
}

Expand Down

0 comments on commit 00f3724

Please sign in to comment.