<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.vcs.update;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.List;

public class RefreshVFsSynchronously {
  private RefreshVFsSynchronously() {
  }

  public static void updateAllChanged(final UpdatedFiles updatedFiles) {
    // approx so ok
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (progressIndicator != null) {
      progressIndicator.setIndeterminate(false);
    }
    final int num = getFilesNum(updatedFiles);

    wrapIntoLock(new Runnable() {
      public void run() {
        UpdateFilesHelper.iterateFileGroupFilesDeletedOnServerFirst(updatedFiles, new MyRefreshCallback(num, progressIndicator));
      }
    });
  }

  private static int getFilesNum(final UpdatedFiles files) {
    int result = 0;
    for (FileGroup group : files.getTopLevelGroups()) {
      result += group.getImmediateFilesSize();
      final List<FileGroup> children = group.getChildren();
      for (FileGroup child : children) {
        result += child.getImmediateFilesSize();
      }
    }
    return result;
  }

  @Nullable
  public static VirtualFile findCreatedFile(final File root) {
    refresh(root);
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    return lfs.findFileByIoFile(root);
  }

  private static void refresh(final File root) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile vFile = lfs.refreshAndFindFileByIoFile(root);
    if (vFile != null) {
      vFile.refresh(false, false);
      return;
    }
  }

  private static void refreshDeletedOrReplaced(final File root) {
    final File parent = root.getParentFile();
    VirtualFile vf = null;
    // parent should also notice the change
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final VirtualFile rootVf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
    if (parent != null) {
      vf = localFileSystem.refreshAndFindFileByIoFile(parent);
    }
    if (vf == null) {
      vf = rootVf;
    }
    if (vf != null) {
      ((NewVirtualFile)vf).markDirtyRecursively();
      vf.refresh(false, true);
    }
  }

  public static void updateChangesForRollback(final List<Change> changes) {
    updateChangesImpl(changes, RollbackChangeWrapper.ourInstance);
  }

  public static void updateChanges(final List<Change> changes) {
    updateChangesImpl(changes, DirectChangeWrapper.ourInstance);
  }

  private static void updateChangesImpl(final List<Change> changes, final ChangeWrapper wrapper) {
    // approx so ok
    final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    if (pi != null) {
      pi.setIndeterminate(false);
    }
    final double num = changes.size();

    int cnt = 0;
    final FilesForRefresh filesForRefresh = new FilesForRefresh();
    for (Change change : changes) {
      if ((! wrapper.beforeNull(change)) && (wrapper.movedOrRenamedOrReplaced(change) || (wrapper.afterNull(change)))) {
        refreshDeletedOrReplaced(wrapper.getBeforeFile(change));
      } else if (! wrapper.beforeNull(change)) {
        refresh(wrapper.getBeforeFile(change));
      }
      if ((! wrapper.afterNull(change)) && 
          (wrapper.beforeNull(change) || (! Comparing.equal(change.getAfterRevision().getFile(), change.getBeforeRevision().getFile())))
         ) {
        refresh(wrapper.getAfterFile(change));<commit_msg>deadcode<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.vcs.update;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.List;

public class RefreshVFsSynchronously {
  private RefreshVFsSynchronously() {
  }

  public static void updateAllChanged(final UpdatedFiles updatedFiles) {
    // approx so ok
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (progressIndicator != null) {
      progressIndicator.setIndeterminate(false);
    }
    final int num = getFilesNum(updatedFiles);

    wrapIntoLock(new Runnable() {
      public void run() {
        UpdateFilesHelper.iterateFileGroupFilesDeletedOnServerFirst(updatedFiles, new MyRefreshCallback(num, progressIndicator));
      }
    });
  }

  private static int getFilesNum(final UpdatedFiles files) {
    int result = 0;
    for (FileGroup group : files.getTopLevelGroups()) {
      result += group.getImmediateFilesSize();
      final List<FileGroup> children = group.getChildren();
      for (FileGroup child : children) {
        result += child.getImmediateFilesSize();
      }
    }
    return result;
  }

  @Nullable
  public static VirtualFile findCreatedFile(final File root) {
    refresh(root);
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    return lfs.findFileByIoFile(root);
  }

  private static void refresh(final File root) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile vFile = lfs.refreshAndFindFileByIoFile(root);
    if (vFile != null) {
      vFile.refresh(false, false);
      return;
    }
  }

  private static void refreshDeletedOrReplaced(final File root) {
    final File parent = root.getParentFile();
    VirtualFile vf = null;
    // parent should also notice the change
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final VirtualFile rootVf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
    if (parent != null) {
      vf = localFileSystem.refreshAndFindFileByIoFile(parent);
    }
    if (vf == null) {
      vf = rootVf;
    }
    if (vf != null) {
      ((NewVirtualFile)vf).markDirtyRecursively();
      vf.refresh(false, true);
    }
  }

  public static void updateChangesForRollback(final List<Change> changes) {
    updateChangesImpl(changes, RollbackChangeWrapper.ourInstance);
  }

  public static void updateChanges(final List<Change> changes) {
    updateChangesImpl(changes, DirectChangeWrapper.ourInstance);
  }

  private static void updateChangesImpl(final List<Change> changes, final ChangeWrapper wrapper) {
    // approx so ok
    final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    if (pi != null) {
      pi.setIndeterminate(false);
    }
    final double num = changes.size();

    int cnt = 0;
    for (Change change : changes) {
      if ((! wrapper.beforeNull(change)) && (wrapper.movedOrRenamedOrReplaced(change) || (wrapper.afterNull(change)))) {
        refreshDeletedOrReplaced(wrapper.getBeforeFile(change));
      } else if (! wrapper.beforeNull(change)) {
        refresh(wrapper.getBeforeFile(change));
      }
      if ((! wrapper.afterNull(change)) && 
          (wrapper.beforeNull(change) || (! Comparing.equal(change.getAfterRevision().getFile(), change.getBeforeRevision().getFile())))
         ) {
        refresh(wrapper.getAfterFile(change));
{'fraction_non_alphanumeric': 0.10160899272647124, 'fraction_numerical': 0.003085739475424289, 'mean_word_length': 3.9726027397260273, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673631', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2568, 'n_words': 626}