Skip to content

Commit

Permalink
Merge pull request #96 from PlasticSCM/miguel/fix-update-on-startup
Browse files Browse the repository at this point in the history
Fix "Update Workspace status on Editor startup"
  • Loading branch information
SRombautsU authored Oct 30, 2023
2 parents af67247 + 24ee887 commit b93f0af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "PlasticSourceControlModule.h"
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlSettings.h"
#include "PlasticSourceControlShell.h"
#include "PlasticSourceControlState.h"
#include "PlasticSourceControlUtils.h"
#include "PlasticSourceControlVersions.h"
Expand Down Expand Up @@ -171,11 +172,12 @@ bool FPlasticConnectWorker::Execute(FPlasticSourceControlCommand& InCommand)
// Now update the status of assets in the Content directory
// but only on real (re-)connection (but not each time Login() is called by Rename or Fixup Redirector command to check connection)
// and only if enabled in the settings
if (!GetProvider().IsAvailable() && GetProvider().AccessSettings().GetUpdateStatusAtStartup())
if (!PlasticSourceControlShell::GetShellIsWarmedUp() && GetProvider().AccessSettings().GetUpdateStatusAtStartup())
{
PlasticSourceControlShell::SetShellIsWarmedUp();
TArray<FString> ContentDir;
ContentDir.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
PlasticSourceControlUtils::RunUpdateStatus(ContentDir, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
PlasticSourceControlUtils::RunUpdateStatus(ContentDir, PlasticSourceControlUtils::EStatusSearchType::All, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}
}
else
Expand Down
29 changes: 29 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ static FCriticalSection ShellCriticalSection;
static size_t ShellCommandCounter = -1;
static double ShellCumulatedTime = 0.;

// Whether we already ran a status command to warm up the current shell process
static bool bShellIsWarmedUp = false;

// Internal function to cleanup (called under the critical section)
static void _CleanupBackgroundCommandLineShell()
{
Expand All @@ -79,6 +82,16 @@ static void _CleanupBackgroundCommandLineShell()
ShellInputPipeRead = ShellInputPipeWrite = nullptr;
}

static bool _GetShellIsWarmedUp()
{
return bShellIsWarmedUp;
}

static void _SetShellIsWarmedUp()
{
bShellIsWarmedUp = true;
}

// Internal function to launch the Unity Version Control background 'cm' process in interactive shell mode (called under the critical section)
static bool _StartBackgroundPlasticShell(const FString& InPathToPlasticBinary, const FString& InWorkingDirectory)
{
Expand All @@ -90,6 +103,8 @@ static bool _StartBackgroundPlasticShell(const FString& InPathToPlasticBinary, c
const bool bLaunchHidden = true; // the new process will be minimized in the task bar
const bool bLaunchReallyHidden = bLaunchHidden; // the new process will not have a window or be in the task bar

bShellIsWarmedUp = false;

const double StartTimestamp = FPlatformTime::Seconds();

#if ENGINE_MAJOR_VERSION == 4
Expand Down Expand Up @@ -368,6 +383,20 @@ void Terminate()
_ExitBackgroundCommandLineShell();
}

void SetShellIsWarmedUp()
{
FScopeLock Lock(&ShellCriticalSection);

_SetShellIsWarmedUp();
}

bool GetShellIsWarmedUp()
{
FScopeLock Lock(&ShellCriticalSection);

return _GetShellIsWarmedUp();
}

// Run command and return the raw result
bool RunCommand(const FString& InCommand, const TArray<FString>& InParameters, const TArray<FString>& InFiles, FString& OutResults, FString& OutErrors)
{
Expand Down
10 changes: 10 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ bool Launch(const FString& InPathToPlasticBinary, const FString& InWorkspaceRoot
/** Terminate the background 'cm shell' process and associated pipes */
void Terminate();

/** Mark the current shell process as already warmed up - i.e. we already ran a preliminary 'status' command. */
void SetShellIsWarmedUp();

/**
* Retrieve whether the current shell process was already warmed up - i.e. we already ran a preliminary 'status' command.
*
* @returns true if the shell process was already warmed up
*/
bool GetShellIsWarmedUp();


/**
* Run a Plastic command - the result is the output of cm, as a multi-line string.
Expand Down

0 comments on commit b93f0af

Please sign in to comment.