<commit_before>package com.intellij.localvcs;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class DeleteChange extends Change {
  private Path myPath;
  private Entry myAffectedEntry;
  private IdPath myAffectedEntryIdPath;

  public DeleteChange(Path path) {
    myPath = path;
  }

  public DeleteChange(Stream s) throws IOException {
    myPath = s.readPath();
    myAffectedEntry = s.readEntry();
  }

  @Override
  public void write(Stream s) throws IOException {
    s.writePath(myPath);
    s.writeEntry(myAffectedEntry);
  }

  public Entry getAffectedEntry() {
    return myAffectedEntry;
  }

  @Override
  public void applyTo(RootEntry root) {
    myAffectedEntry = root.getEntry(myPath);
    myAffectedEntryIdPath = myAffectedEntry.getIdPath();

    root.doDelete(myPath);
  }

  @Override
  public void revertOn(RootEntry root) {
    // todo maybe we should create several DeleteChanges instead of saving
    // todo previous entry?
    restoreEntryRecursively(root, myAffectedEntry, myPath);
  }

  private void restoreEntryRecursively(RootEntry root, Entry e, Path p) {
    if (e.isDirectory()) {
      root.doCreateDirectory(e.getId(), p);
      for (Entry child : e.getChildren()) {
        restoreEntryRecursively(root, child, p.appendedWith(child.getName()));
      }
    } else {
      root.doCreateFile(e.getId(), p, e.getContent());
    }
  }

  @Override
  protected List<IdPath> getAffectedEntryIdPaths() {
    return Arrays.asList(myAffectedEntryIdPath);
  }
}<commit_msg>(no message)<commit_after>package com.intellij.localvcs;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class DeleteChange extends Change {
  private Path myPath;
  private Entry myAffectedEntry;
  private IdPath myAffectedEntryIdPath;

  public DeleteChange(Path path) {
    myPath = path;
  }

  public DeleteChange(Stream s) throws IOException {
    myPath = s.readPath();
    myAffectedEntry = s.readEntry();
  }

  @Override
  public void write(Stream s) throws IOException {
    s.writePath(myPath);
    s.writeEntry(myAffectedEntry);
  }

  public Entry getAffectedEntry() {
    return myAffectedEntry;
  }

  @Override
  public void applyTo(RootEntry root) {
    myAffectedEntry = root.getEntry(myPath);
    myAffectedEntryIdPath = myAffectedEntry.getIdPath();

    root.doDelete(myPath);
  }

  @Override
  public void _revertOn(RootEntry root) {
    // todo maybe we should create several DeleteChanges instead of saving
    // todo previous entry?
    restoreEntryRecursively(root, myAffectedEntry, myPath);
  }

  private void restoreEntryRecursively(RootEntry root, Entry e, Path p) {
    if (e.isDirectory()) {
      root.doCreateDirectory(e.getId(), p);
      for (Entry child : e.getChildren()) {
        restoreEntryRecursively(root, child, p.appendedWith(child.getName()));
      }
    } else {
      root.doCreateFile(e.getId(), p, e.getContent());
    }
  }

  @Override
  protected List<IdPath> getAffectedEntryIdPaths() {
    return Arrays.asList(myAffectedEntryIdPath);
  }
}
{'fraction_non_alphanumeric': 0.10286458333333333, 'fraction_numerical': 0.0, 'mean_word_length': 3.742283950617284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4818365', 'n_tokens_mistral': 994, 'n_tokens_neox': 956, 'n_words': 221}