No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchLocks.cs 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections.Generic;
  2. using Codice.Client.Commands;
  3. using Codice.Client.Commands.WkTree;
  4. using Codice.Client.Common.Locks;
  5. using Codice.Client.Common.WkTree;
  6. using Codice.CM.Common;
  7. using Codice.CM.WorkspaceServer;
  8. namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
  9. {
  10. internal static class SearchLocks
  11. {
  12. internal static Dictionary<WorkspaceTreeNode, LockInfo> GetLocksInfo(
  13. WorkspaceInfo wkInfo,
  14. Dictionary<MountPointWithPath, List<WorkspaceTreeNode>> locksCandidates)
  15. {
  16. Dictionary<WorkspaceTreeNode, LockInfo> result =
  17. new Dictionary<WorkspaceTreeNode, LockInfo>();
  18. ServerLocks.ForWorkingBranchOnRepoByItem locksForWorkingBranchOnRepoByItem =
  19. new ServerLocks.ForWorkingBranchOnRepoByItem();
  20. foreach (KeyValuePair<MountPointWithPath, List<WorkspaceTreeNode>> each in locksCandidates)
  21. {
  22. FillRepositoryLocks(
  23. wkInfo, each.Key, each.Value,
  24. locksForWorkingBranchOnRepoByItem, result);
  25. }
  26. return result;
  27. }
  28. static void FillRepositoryLocks(
  29. WorkspaceInfo wkInfo,
  30. MountPointWithPath mount,
  31. List<WorkspaceTreeNode> candidates,
  32. ServerLocks.ForWorkingBranchOnRepoByItem locksForWorkingBranchOnRepoByItem,
  33. Dictionary<WorkspaceTreeNode, LockInfo> locks)
  34. {
  35. if (candidates.Count == 0)
  36. return;
  37. LockRule lockRule = ServerLocks.GetLockRule(mount.RepSpec);
  38. if (lockRule == null)
  39. return;
  40. candidates = GetLockableCandidates(candidates, lockRule);
  41. if (candidates.Count == 0)
  42. return;
  43. BranchInfo workingBranch = CheckoutBranchSolver.Get(wkInfo).
  44. GetWorkingBranchWithoutBranchExpansionByMount(mount);
  45. if (workingBranch == null)
  46. return;
  47. ServerLocks.GetLocksForRepoByItemId(
  48. mount.RepSpec, workingBranch.Id, locksForWorkingBranchOnRepoByItem);
  49. Dictionary<long, LockInfo> lockByItemCache;
  50. if (!locksForWorkingBranchOnRepoByItem.TryGetLocks(
  51. mount.RepSpec, workingBranch.Id, out lockByItemCache))
  52. return;
  53. if (lockByItemCache.Count == 0)
  54. return;
  55. foreach (WorkspaceTreeNode candidate in candidates)
  56. {
  57. LockInfo serverLock;
  58. if (!lockByItemCache.TryGetValue(
  59. candidate.RevInfo.ItemId, out serverLock))
  60. continue;
  61. locks[candidate] = serverLock;
  62. }
  63. }
  64. static List<WorkspaceTreeNode> GetLockableCandidates(
  65. List<WorkspaceTreeNode> candidates,
  66. LockRule lockRule)
  67. {
  68. List<WorkspaceTreeNode> result = new List<WorkspaceTreeNode>();
  69. LockedFilesFilter filter = new LockedFilesFilter(lockRule.Rules);
  70. foreach (WorkspaceTreeNode candidate in candidates)
  71. {
  72. string cmPath = WorkspaceNodeOperations.GetCmPath(candidate);
  73. if (cmPath == null)
  74. {
  75. //The node could not be on the head tree (like copied items) so when we
  76. //cannot calculate the path we assume that it's lockable.
  77. result.Add(candidate);
  78. continue;
  79. }
  80. if (filter.IsLockable(cmPath))
  81. result.Add(candidate);
  82. }
  83. return result;
  84. }
  85. }
  86. }