Files
UnrealEngineUWP/Engine/Source/Developer/Merge/Private/MergeUtils.cpp
Thomas Sarkanen be75fe1eca Updated revision display to display strings rather than revision indices
API break: added new pure virtual ISourceControlProvider::UsesChangelists()
API break: added new pure virtual ISourceControlState::FindHistoryRevision(const FString&)
API break: added new pure virtual ISourceControlRevision::GetRevision()

Implementing a Git provider requires us to be able to display revisions that are not indices as Git revisions are hashes. This updates the relvant code to allow us to display these revisions correctly.

[CL 2411986 by Thomas Sarkanen in Main branch]
2015-01-20 05:48:14 -05:00

139 lines
4.4 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "MergePrivatePCH.h"
#include "MergeUtils.h"
#include "ISourceControlModule.h"
#include "SourceControlHelpers.h"
#include "NotificationManager.h"
#include "Developer/AssetTools/Public/IAssetTypeActions.h"
#include "Runtime/Slate/Public/Widgets/Notifications/SNotificationList.h"
#define LOCTEXT_NAMESPACE "MergeToolUtils"
//------------------------------------------------------------------------------
FSourceControlStatePtr FMergeToolUtils::GetSourceControlState(const FString& PackageName)
{
ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider();
TSharedRef<FUpdateStatus, ESPMode::ThreadSafe> UpdateStatusOperation = ISourceControlOperation::Create<FUpdateStatus>();
UpdateStatusOperation->SetUpdateHistory(true);
SourceControlProvider.Execute(UpdateStatusOperation, SourceControlHelpers::PackageFilename(PackageName));
FSourceControlStatePtr State = SourceControlProvider.GetState(SourceControlHelpers::PackageFilename(PackageName), EStateCacheUsage::Use);
if (!State.IsValid() || !State->IsSourceControlled() || !FPackageName::DoesPackageExist(PackageName))
{
return FSourceControlStatePtr();
}
else
{
return State;
}
}
//------------------------------------------------------------------------------
UObject const* FMergeToolUtils::LoadRevision(const FString& AssetName, const ISourceControlRevision& DesiredRevision)
{
FSlateNotificationManager& NotificationManager = FSlateNotificationManager::Get();
// Get the head revision of this package from source control
FString TempFileName;
if (DesiredRevision.Get(TempFileName))
{
// Forcibly disable compile on load in case we are loading old blueprints that might try to update/compile
TGuardValue<bool> DisableCompileOnLoad(GForceDisableBlueprintCompileOnLoad, true);
// Try and load that package
UPackage* TempPackage = LoadPackage(NULL, *TempFileName, LOAD_None);
if (TempPackage != NULL)
{
// Grab the old asset from that old package
UObject* OldObject = FindObject<UObject>(TempPackage, *AssetName);
if (OldObject)
{
return OldObject;
}
else
{
NotificationManager.AddNotification(
FText::Format(
LOCTEXT("MergedFailedToFindObject", "Aborted Load of {0} because we could not find an object named {1}" )
, FText::FromString(TempFileName)
, FText::FromString(AssetName)
)
);
}
}
else
{
NotificationManager.AddNotification(
FText::Format(
LOCTEXT("MergedFailedToLoadPackage", "Aborted Load of {0} because we could not load the package")
, FText::FromString(TempFileName)
)
);
}
}
else
{
NotificationManager.AddNotification(
FText::Format(
LOCTEXT("MergedFailedToFindRevision", "Aborted Load of {0} because we could not get the requested revision")
, FText::FromString(TempFileName)
)
);
}
return NULL;
}
//------------------------------------------------------------------------------
UObject const* FMergeToolUtils::LoadRevision(const FString& PackageName, const FRevisionInfo& DesiredRevision)
{
const UObject* AssetRevision = nullptr;
if (UPackage* AssetPackage = LoadPackage(/*Outer =*/nullptr, *PackageName, LOAD_None))
{
TArray<UObject*> PackageObjs;
GetObjectsWithOuter(AssetPackage, PackageObjs, /*bIncludeNestedObjects =*/false);
for (UObject* PackageObj : PackageObjs)
{
if (PackageObj->IsAsset())
{
AssetRevision = LoadRevision(PackageObj, DesiredRevision);
break;
}
}
}
return AssetRevision;
}
//------------------------------------------------------------------------------
UObject const* FMergeToolUtils::LoadRevision(const UObject* AssetObject, const FRevisionInfo& DesiredRevision)
{
check(AssetObject->IsAsset());
const UObject* AssetRevision = nullptr;
if (DesiredRevision.Revision.IsEmpty())
{
// an invalid revision number represents the local copy
AssetRevision = AssetObject;
}
else
{
FString const PackageName = AssetObject->GetOutermost()->GetName();
FSourceControlStatePtr SourceControlState = GetSourceControlState(PackageName);
if (SourceControlState.IsValid())
{
TSharedPtr<ISourceControlRevision, ESPMode::ThreadSafe> Revision = SourceControlState->FindHistoryRevision(DesiredRevision.Revision);
if (Revision.IsValid())
{
FString const AssetName = AssetObject->GetName();
AssetRevision = LoadRevision(AssetName, *Revision);
}
}
}
return AssetRevision;
}
#undef LOCTEXT_NAMESPACE