public static void visitByStatus()

in src/org/jetbrains/tfsIntegration/core/tfs/StatusProvider.java [40:130]


  public static void visitByStatus(final @NotNull WorkspaceInfo workspace,
                                   final List<? extends ItemPath> roots,
                                   boolean recursive,
                                   final @Nullable ProgressIndicator progress,
                                   final @NotNull StatusVisitor statusVisitor,
                                   Object projectOrComponent) throws TfsException {
    if (roots.isEmpty()) {
      return;
    }

    List<ItemSpec> itemSpecs = new ArrayList<>(roots.size());
    for (ItemPath root : roots) {
      final VirtualFile file = root.getLocalPath().getVirtualFile();
      RecursionType recursionType =
        recursive && (file == null || !file.exists() || file.isDirectory()) ? RecursionType.Full : RecursionType.None;
      itemSpecs.add(VersionControlServer.createItemSpec(root.getLocalPath(), recursionType));
    }

    VersionControlServer.ExtendedItemsAndPendingChanges extendedItemsAndPendingChanges = workspace.getServer().getVCS()
      .getExtendedItemsAndPendingChanges(workspace.getName(), workspace.getOwnerName(), itemSpecs, ItemType.Any, projectOrComponent,
                                         TFSBundle.message("loading.changes"));

    Map<Integer, PendingChange> pendingChanges = new HashMap<>(extendedItemsAndPendingChanges.pendingChanges.size());
    for (PendingChange pendingChange : extendedItemsAndPendingChanges.pendingChanges) {
      pendingChanges.put(pendingChange.getItemid(), pendingChange);
    }

    Map<Integer, ExtendedItem> extendedItems = new HashMap<>();
    for (ExtendedItem extendedItem : extendedItemsAndPendingChanges.extendedItems) {
      extendedItems.put(extendedItem.getItemid(), extendedItem);
    }

    TFSProgressUtil.checkCanceled(progress);

    for (ItemPath root : roots) {
      Collection<FilePath> localItems = new HashSet<>();
      localItems.add(root.getLocalPath());
      if (recursive) {
        addExistingFilesRecursively(localItems, root.getLocalPath().getVirtualFile());
      }

      // first process all local items given
      for (FilePath localItem : localItems) {

        ExtendedItem extendedItem = null;
        PendingChange pendingChange = null;

        // TODO: what is faster: to search throughout pending changes or extended items?

        for (PendingChange candidate : pendingChanges.values()) {
          if (equals(localItem, VersionControlPath.localPathFromTfsRepresentation(candidate.getLocal()))) {
            extendedItem = extendedItems.remove(candidate.getItemid());
            //TFSVcs.assertTrue(extendedItem != null, "pending change without extended item for " +
            //                                        VersionControlPath.localPathFromTfsRepresentation(candidate.getLocal()));
            // don't assert: if there's no item, we will get 'unversioned' status as a result
            pendingChange = candidate;
            break;
          }
        }

        if (extendedItem == null) {
          for (ExtendedItem candidate : extendedItems.values()) {
            if (equals(localItem, VersionControlPath.localPathFromTfsRepresentation(candidate.getLocal()))) {
              extendedItem = extendedItems.remove(candidate.getItemid());
              break;
            }
          }
        }

        final boolean localItemExists = TfsFileUtil.localItemExists(localItem);
        if (!localItemExists && extendedItem != null) {
          // if path is the original one from dirtyScope, it may have invalid 'isDirectory' status
          localItem = VcsUtil.getFilePath(localItem.getPath(), extendedItem.getType() == ItemType.Folder);
        }
        determineServerStatus(pendingChange, extendedItem).visitBy(localItem, localItemExists, statusVisitor);
      }
      TFSProgressUtil.checkCanceled(progress);
    }

    if (recursive) {
      // then care about locally deleted
      for (ExtendedItem extendedItem : extendedItems.values()) {
        PendingChange pendingChange = pendingChanges.get(extendedItem.getItemid());
        if (pendingChange != null || extendedItem.getLocal() != null) {
          FilePath localPath = VersionControlPath.getFilePath(pendingChange != null ? pendingChange.getLocal() : extendedItem.getLocal(),
                                                              extendedItem.getType() == ItemType.Folder);
          determineServerStatus(pendingChange, extendedItem).visitBy(localPath, false, statusVisitor);
        }
      }
    }
  }