Exemplo n.º 1
0
        public void ForceLock(IEnumerable <SVNStatusData> lockedByOtherEntries)
        {
            var shouldLog   = SVNPreferencesManager.Instance.PersonalPrefs.TraceLogs.HasFlag(SVNTraceLogs.SVNOperations);
            var lockMessage = SVNPreferencesManager.Instance.ProjectPrefs.AutoLockMessage;

            var targetsFileToUse = FileUtil.GetUniqueTempPathInProject();               // Not thread safe - call in main thread only.

            EnqueueOperation(op => WiseSVNIntegration.LockFiles(lockedByOtherEntries.Select(sd => sd.Path), true, lockMessage, "", targetsFileToUse))
            .Completed += (op) => {
                if (op.Result != LockOperationResult.Success)
                {
                    Debug.LogError($"Auto-locking by force failed with result {op.Result} for assets:\n{string.Join("\n", lockedByOtherEntries.Select(sd => sd.Path))}.");
                    EditorUtility.DisplayDialog("SVN Auto-Locking", "Stealing lock failed. Check the logs for more info.", "I will!");
                }
                else if (shouldLog)
                {
                    Debug.Log($"Auto-locked assets by force:\n{string.Join("\n", lockedByOtherEntries.Select(sd => sd.Path))}");
                }
            };

            if (m_PendingOperations.Count > 0 && m_HasPendingOperations == false)
            {
                m_HasPendingOperations = true;
                m_PendingOperations.Peek().Start();
            }
        }
Exemplo n.º 2
0
        private void OnStatusDatabaseChanged()
        {
            if (!IsActive)
            {
                return;
            }

            var statusDatabaseData = SVNStatusesDatabase.Instance.GetAllKnownStatusData(false, true, true)
                                     .Where(sd => !Directory.Exists(sd.Path))
                                     .ToList()
            ;

            var newEntries = new List <SVNStatusData>();

            foreach (var statusData in statusDatabaseData)
            {
                if (AddOrUpdateKnowsStatusData(statusData))
                {
                    newEntries.Add(statusData);
                }
            }

            m_KnownData.RemoveAll(known => !statusDatabaseData.Any(unknown => known.Path == unknown.Path));

            var shouldLock           = new List <SVNStatusData>(newEntries.Count);
            var lockedByOtherEntries = new List <SVNStatusData>(newEntries.Count);
            var shouldUnlock         = new List <SVNStatusData>();

            // Check for new assets to lock.
            foreach (var statusData in newEntries)
            {
                // NOTE: Deleted status never occurs as it is not provided by the SVNStatusesDatabase. :(
                if (statusData.Status != VCFileStatus.Modified && statusData.Status != VCFileStatus.Deleted && statusData.Status != VCFileStatus.Replaced)
                {
                    continue;
                }

                if (statusData.LockStatus == VCLockStatus.LockedHere)
                {
                    continue;
                }

                var  assetPath = statusData.Path;
                bool isMeta    = false;
                if (statusData.Path.EndsWith(".meta", StringComparison.OrdinalIgnoreCase))
                {
                    assetPath = statusData.Path.Substring(0, statusData.Path.LastIndexOf(".meta"));
                    isMeta    = true;
                }
                assetPath = assetPath.Replace("\\", "/");

                var autoLockingParam = m_ProjectPrefs.AutoLockingParameters
                                       .FirstOrDefault(al => assetPath.StartsWith(al.TargetFolder, StringComparison.OrdinalIgnoreCase));

                if (string.IsNullOrEmpty(autoLockingParam.TargetFolder))
                {
                    continue;
                }

                if (isMeta && !autoLockingParam.IncludeTargetMetas)
                {
                    continue;
                }

                if (SVNPreferencesManager.ShouldExclude(autoLockingParam.Exclude, assetPath))
                {
                    continue;
                }

                bool matched = IsAssetOfType(assetPath, autoLockingParam.TargetTypes, statusData.Status == VCFileStatus.Deleted);
                if (!matched && !autoLockingParam.TargetTypes.HasFlag(AssetType.OtherTypes))
                {
                    continue;
                }

                if (statusData.LockStatus == VCLockStatus.NoLock)
                {
                    shouldLock.Add(statusData);
                    continue;
                }

                lockedByOtherEntries.Add(statusData);
            }

            // Check for old assets to unlock.
            foreach (var statusData in statusDatabaseData)
            {
                if (statusData.Status != VCFileStatus.Normal)
                {
                    continue;
                }

                var assetPath = statusData.Path;
                if (statusData.Path.EndsWith(".meta", StringComparison.OrdinalIgnoreCase))
                {
                    assetPath = statusData.Path.Substring(0, statusData.Path.LastIndexOf(".meta"));
                }
                assetPath = assetPath.Replace("\\", "/");

                var autoLockingParam = m_ProjectPrefs.AutoLockingParameters
                                       .FirstOrDefault(al => assetPath.StartsWith(al.TargetFolder, StringComparison.OrdinalIgnoreCase));

                if (string.IsNullOrEmpty(autoLockingParam.TargetFolder))
                {
                    continue;
                }

                if (SVNPreferencesManager.ShouldExclude(autoLockingParam.Exclude, assetPath))
                {
                    continue;
                }

                bool matched = IsAssetOfType(assetPath, autoLockingParam.TargetTypes, false);
                if (!matched && !autoLockingParam.TargetTypes.HasFlag(AssetType.OtherTypes))
                {
                    continue;
                }

                if (statusData.LockStatus != VCLockStatus.NoLock && statusData.LockStatus != VCLockStatus.LockedOther)
                {
                    shouldUnlock.Add(statusData);
                }
            }


            var shouldLog   = SVNPreferencesManager.Instance.PersonalPrefs.TraceLogs.HasFlag(SVNTraceLogs.SVNOperations);
            var lockMessage = SVNPreferencesManager.Instance.ProjectPrefs.AutoLockMessage;

            if (shouldLock.Count > 0)
            {
                var targetsFileToUse = FileUtil.GetUniqueTempPathInProject();                   // Not thread safe - call in main thread only.
                EnqueueOperation(op => WiseSVNIntegration.LockFiles(shouldLock.Select(sd => sd.Path), false, lockMessage, "", targetsFileToUse))
                .Completed += (op) => {
                    if (op.Result != LockOperationResult.Success)
                    {
                        Debug.LogError($"Auto-locking failed with result {op.Result} for assets:\n{string.Join("\n", shouldLock.Select(sd => sd.Path))}");
                    }
                    else if (shouldLog)
                    {
                        Debug.Log($"Auto-locked assets:\n{string.Join("\n", shouldLock.Select(sd => sd.Path))}");
                    }
                };
            }

            if (shouldUnlock.Count > 0)
            {
                var targetsFileToUse = FileUtil.GetUniqueTempPathInProject();                   // Not thread safe - call in main thread only.
                EnqueueOperation(op => WiseSVNIntegration.UnlockFiles(shouldUnlock.Select(sd => sd.Path), false, targetsFileToUse))
                .Completed += (op) => {
                    // If lock was stolen or broken, there is no good way to release it without causing error.
                    // In that case the lock will be cleared from the local cache, so ignore the error.
                    if (op.Result != LockOperationResult.Success && op.Result != LockOperationResult.LockedByOther)
                    {
                        Debug.LogError($"Auto-unlocking failed with result {op.Result} for assets:\n{string.Join("\n", shouldUnlock.Select(sd => sd.Path))}");
                    }
                    else if (shouldLog)
                    {
                        Debug.Log($"Auto-unlocked assets:\n{string.Join("\n", shouldUnlock.Select(sd => sd.Path))}");
                    }
                };
            }

            if (lockedByOtherEntries.Count > 0)
            {
                SVNAutoLockingForceWindow.PromptForceLock(lockedByOtherEntries);
            }

            if (m_PendingOperations.Count > 0 && m_HasPendingOperations == false)
            {
                m_HasPendingOperations = true;
                m_PendingOperations.Peek().Start();
            }
        }