This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
using Codice.CM.Common;
using Unity.PlasticSCM.Editor.AssetUtils;
namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
{
internal interface IAssetStatusCache
{
AssetStatus GetStatus(string fullPath);
LockStatusData GetLockStatusData(string fullPath);
void Clear();
}
internal class AssetStatusCache : IAssetStatusCache
{
internal AssetStatusCache(
WorkspaceInfo wkInfo,
bool isGluonMode)
{
mLocalStatusCache = new LocalStatusCache(wkInfo);
mRemoteStatusCache = new RemoteStatusCache(
wkInfo,
isGluonMode,
ProjectWindow.Repaint,
RepaintInspector.All);
mLockStatusCache = new LockStatusCache(
wkInfo,
ProjectWindow.Repaint,
RepaintInspector.All);
}
AssetStatus IAssetStatusCache.GetStatus(string fullPath)
{
AssetStatus localStatus = mLocalStatusCache.GetStatus(fullPath);
if (!ClassifyAssetStatus.IsControlled(localStatus))
return localStatus;
AssetStatus remoteStatus = mRemoteStatusCache.GetStatus(fullPath);
AssetStatus lockStatus = mLockStatusCache.GetStatus(fullPath);
return localStatus | remoteStatus | lockStatus;
}
LockStatusData IAssetStatusCache.GetLockStatusData(string fullPath)
{
return mLockStatusCache.GetLockStatusData(fullPath);
}
void IAssetStatusCache.Clear()
{
mLocalStatusCache.Clear();
mRemoteStatusCache.Clear();
mLockStatusCache.Clear();
}
readonly LocalStatusCache mLocalStatusCache;
readonly RemoteStatusCache mRemoteStatusCache;
readonly LockStatusCache mLockStatusCache;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f227b28cf424364489edd67fce697bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Codice.Utils;
namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
{
internal static class BuildPathDictionary
{
internal static Dictionary<string, T> ForPlatform<T>()
{
if (PlatformIdentifier.IsWindows())
return new Dictionary<string, T>(
StringComparer.OrdinalIgnoreCase);
return new Dictionary<string, T>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9c963b5d17c74314eb7105e71377cdb8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
using System.Collections.Generic;
using Codice;
using Codice.Client.BaseCommands;
using Codice.Client.Commands.WkTree;
using Codice.CM.Common;
using PlasticGui.WorkspaceWindow;
namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
{
internal class LocalStatusCache
{
internal LocalStatusCache(WorkspaceInfo wkInfo)
{
mWkInfo = wkInfo;
}
internal AssetStatus GetStatus(string fullPath)
{
AssetStatus result;
if (mStatusByPathCache.TryGetValue(fullPath, out result))
return result;
result = CalculateStatus(
fullPath,
mWkInfo.ClientPath,
FilterManager.Get().GetIgnoredFilter(),
FilterManager.Get().GetHiddenChangesFilter());
mStatusByPathCache.Add(fullPath, result);
return result;
}
internal void Clear()
{
mStatusByPathCache.Clear();
}
static AssetStatus CalculateStatus(
string fullPath,
string wkPath,
IgnoredFilesFilter ignoredFilter,
HiddenChangesFilesFilter hiddenChangesFilter)
{
WorkspaceTreeNode treeNode = PlasticGui.Plastic.API.GetWorkspaceTreeNode(fullPath);
if (CheckWorkspaceTreeNodeStatus.IsPrivate(treeNode))
{
return ignoredFilter.IsIgnored(fullPath) ?
AssetStatus.Ignored : AssetStatus.Private;
}
if (CheckWorkspaceTreeNodeStatus.IsAdded(treeNode))
return AssetStatus.Added;
AssetStatus result = AssetStatus.Controlled;
if (CheckWorkspaceTreeNodeStatus.IsCheckedOut(treeNode) &&
!CheckWorkspaceTreeNodeStatus.IsDirectory(treeNode))
result |= AssetStatus.Checkout;
if (hiddenChangesFilter.IsHiddenChanged(fullPath))
result |= AssetStatus.HiddenChanged;
return result;
}
Dictionary<string, AssetStatus> mStatusByPathCache =
BuildPathDictionary.ForPlatform<AssetStatus>();
readonly WorkspaceInfo mWkInfo;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 226459a134855504d841db6b61519d2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using Codice;
using Codice.Client.Commands;
using Codice.Client.Commands.WkTree;
using Codice.Client.Common;
using Codice.Client.Common.Locks;
using Codice.Client.Common.Threading;
using Codice.Client.Common.WkTree;
using Codice.CM.Common;
using Codice.CM.Common.Mount;
using Codice.Utils;
using PlasticGui.WorkspaceWindow;
using PlasticGui.WorkspaceWindow.Items.Locks;
namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
{
internal class LockStatusCache
{
internal LockStatusCache(
WorkspaceInfo wkInfo,
Action repaintProjectWindow,
Action repaintInspector)
{
mWkInfo = wkInfo;
mRepaintProjectWindow = repaintProjectWindow;
mRepaintInspector = repaintInspector;
}
internal AssetStatus GetStatus(string fullPath)
{
LockStatusData lockStatusData = GetLockStatusData(fullPath);
if (lockStatusData == null)
return AssetStatus.None;
return lockStatusData.Status;
}
internal LockStatusData GetLockStatusData(string fullPath)
{
lock (mLock)
{
if (mStatusByPathCache == null)
{
mStatusByPathCache = BuildPathDictionary.ForPlatform<LockStatusData>();
mCurrentCancelToken.Cancel();
mCurrentCancelToken = new CancelToken();
AsyncCalculateStatus(mCurrentCancelToken);
return null;
}
LockStatusData result;
if (mStatusByPathCache.TryGetValue(fullPath, out result))
return result;
return null;
}
}
internal void Clear()
{
lock (mLock)
{
mCurrentCancelToken.Cancel();
mStatusByPathCache = null;
}
}
void AsyncCalculateStatus(CancelToken cancelToken)
{
Dictionary<string, LockStatusData> statusByPathCache = null;
IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
Dictionary<MountPointWithPath, List<WorkspaceTreeNode>> lockCandidates =
new Dictionary<MountPointWithPath, List<WorkspaceTreeNode>>();
FillLockCandidates.ForTree(mWkInfo, lockCandidates);
if (cancelToken.IsCancelled())
return;
Dictionary<WorkspaceTreeNode, LockInfo> lockInfoByNode =
SearchLocks.GetLocksInfo(mWkInfo, lockCandidates);
if (cancelToken.IsCancelled())
return;
statusByPathCache = BuildStatusByNodeCache.
ForLocks(mWkInfo.ClientPath, lockInfoByNode);
},
/*afterOperationDelegate*/ delegate
{
if (waiter.Exception != null)
{
ExceptionsHandler.LogException(
"LockStatusCache",
waiter.Exception);
return;
}
if (cancelToken.IsCancelled())
return;
lock (mLock)
{
mStatusByPathCache = statusByPathCache;
}
mRepaintProjectWindow();
mRepaintInspector();
});
}
static class BuildStatusByNodeCache
{
internal static Dictionary<string, LockStatusData> ForLocks(
string wkPath,
Dictionary<WorkspaceTreeNode, LockInfo> lockInfoByNode)
{
Dictionary<string, LockStatusData> result =
BuildPathDictionary.ForPlatform<LockStatusData>();
LockOwnerNameResolver nameResolver = new LockOwnerNameResolver();
foreach (WorkspaceTreeNode node in lockInfoByNode.Keys)
{
LockStatusData lockStatusData = BuildLockStatusData(
node, lockInfoByNode[node], nameResolver);
string nodeWkPath = WorkspacePath.GetWorkspacePathFromCmPath(
wkPath,
WorkspaceNodeOperations.GetCmPath(node),
PathHelper.GetDirectorySeparatorChar(wkPath));
result.Add(nodeWkPath, lockStatusData);
}
return result;
}
static LockStatusData BuildLockStatusData(
WorkspaceTreeNode node,
LockInfo lockInfo,
LockOwnerNameResolver nameResolver)
{
return new LockStatusData(
GetAssetStatus(node, lockInfo),
nameResolver.GetSeidName(lockInfo.SEIDData),
BranchInfoCache.GetProtectedBranchName(
node.RepSpec, lockInfo.HolderBranchId));
}
static AssetStatus GetAssetStatus(
WorkspaceTreeNode node,
LockInfo lockInfo)
{
if (lockInfo.Status == LockInfo.LockStatus.Retained)
return AssetStatus.Retained;
return CheckWorkspaceTreeNodeStatus.IsCheckedOut(node) ?
AssetStatus.Locked : AssetStatus.LockedRemote;
}
}
CancelToken mCurrentCancelToken = new CancelToken();
Dictionary<string, LockStatusData> mStatusByPathCache;
readonly Action mRepaintInspector;
readonly Action mRepaintProjectWindow;
readonly WorkspaceInfo mWkInfo;
static object mLock = new object();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 953c29d2e0dece647a64940343c91547
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using Codice.Client.BaseCommands;
using Codice.Client.Commands;
using Codice.Client.Common;
using Codice.Client.Common.Threading;
using Codice.Client.GameUI;
using Codice.Client.GameUI.Update;
using Codice.CM.Common;
using Codice.CM.Common.Merge;
using Codice.CM.Common.Mount;
using Codice.CM.Common.Partial;
using Codice.CM.Common.Update.Partial;
using Codice.Utils;
using GluonGui.WorkspaceWindow.Views;
namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
{
internal class RemoteStatusCache
{
internal RemoteStatusCache(
WorkspaceInfo wkInfo,
bool isGluonMode,
Action repaintProjectWindow,
Action repaintInspector)
{
mWkInfo = wkInfo;
mIsGluonMode = isGluonMode;
mRepaintProjectWindow = repaintProjectWindow;
mRepaintInspector = repaintInspector;
}
internal AssetStatus GetStatus(string fullPath)
{
if (!mIsGluonMode)
return AssetStatus.UpToDate;
lock(mLock)
{
if (mStatusByPathCache == null)
{
mStatusByPathCache = BuildPathDictionary.ForPlatform<AssetStatus>();
mCurrentCancelToken.Cancel();
mCurrentCancelToken = new CancelToken();
AsyncCalculateStatus(mCurrentCancelToken);
return AssetStatus.UpToDate;
}
AssetStatus result;
if (mStatusByPathCache.TryGetValue(fullPath, out result))
return result;
return AssetStatus.UpToDate;
}
}
internal void Clear()
{
lock (mLock)
{
mCurrentCancelToken.Cancel();
mStatusByPathCache = null;
}
}
void AsyncCalculateStatus(CancelToken cancelToken)
{
Dictionary<string, AssetStatus> statusByPathCache = null;
IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
OutOfDateItems outOfDateItems =
OutOfDateUpdater.CalculateOutOfDateItems(
mWkInfo, new List<ErrorMessage>(),
OutOfDateCalculator.Options.IsIncomingChanges);
if (cancelToken.IsCancelled())
return;
statusByPathCache = BuildStatusByPathCache.
ForOutOfDateItems(outOfDateItems, mWkInfo.ClientPath);
},
/*afterOperationDelegate*/ delegate
{
if (waiter.Exception != null)
{
ExceptionsHandler.LogException(
"RemoteStatusCache",
waiter.Exception);
return;
}
if (cancelToken.IsCancelled())
return;
lock (mLock)
{
mStatusByPathCache = statusByPathCache;
}
mRepaintProjectWindow();
mRepaintInspector();
});
}
static class BuildStatusByPathCache
{
internal static Dictionary<string, AssetStatus> ForOutOfDateItems(
OutOfDateItems outOfDateItems,
string wkPath)
{
Dictionary<string, AssetStatus> result =
BuildPathDictionary.ForPlatform<AssetStatus>();
if (outOfDateItems == null)
return result;
foreach (OutOfDateItemsByMount diffs in
outOfDateItems.GetOutOfDateItemsByMountList(PathHelper.GetPathSorter()))
{
foreach (Difference diff in diffs.Changed)
{
if (diff is DiffXlinkChanged)
continue;
string path = GetPathForDiff(wkPath, diffs.Mount, diff.Path);
result.Add(path, AssetStatus.OutOfDate);
}
foreach (Difference diff in diffs.Deleted)
{
string path = GetPathForDiff(wkPath, diffs.Mount, diff.Path);
result.Add(path, AssetStatus.DeletedOnServer);
}
}
foreach (GluonFileConflict fileConflict in
outOfDateItems.GetFileConflicts())
{
string path = GetPathForConflict(wkPath, fileConflict.CmPath);
result.Add(path, AssetStatus.Conflicted);
}
return result;
}
static string GetPathForDiff(
string wkPath,
MountPointWithPath mountPoint,
string cmSubPath)
{
return WorkspacePath.GetWorkspacePathFromCmPath(
wkPath,
WorkspacePath.ComposeMountPath(mountPoint.MountPath, cmSubPath),
PathHelper.GetDirectorySeparatorChar(wkPath));
}
static string GetPathForConflict(
string wkPath,
string cmPath)
{
return WorkspacePath.GetWorkspacePathFromCmPath(
wkPath, cmPath,
PathHelper.GetDirectorySeparatorChar(wkPath));
}
}
CancelToken mCurrentCancelToken = new CancelToken();
Dictionary<string, AssetStatus> mStatusByPathCache;
readonly Action mRepaintInspector;
readonly Action mRepaintProjectWindow;
readonly bool mIsGluonMode;
readonly WorkspaceInfo mWkInfo;
static object mLock = new object();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9acb575a60d7e045ad7fadd3e3e137d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: