Search in sources :

Example 1 with StoredContent

use of com.intellij.history.core.StoredContent in project intellij-community by JetBrains.

the class IdeaGateway method doCreateEntry.

@Nullable
private Entry doCreateEntry(@NotNull VirtualFile file, boolean forDeletion) {
    if (!file.isDirectory()) {
        if (!isVersioned(file))
            return null;
        Pair<StoredContent, Long> contentAndStamps;
        if (forDeletion) {
            FileDocumentManager m = FileDocumentManager.getInstance();
            // should not try to load document
            Document d = m.isFileModified(file) ? m.getCachedDocument(file) : null;
            contentAndStamps = acquireAndClearCurrentContent(file, d);
        } else {
            contentAndStamps = getActualContentNoAcquire(file);
        }
        return doCreateFileEntry(file, contentAndStamps);
    }
    DirectoryEntry newDir = null;
    if (file instanceof VirtualFileSystemEntry) {
        int nameId = ((VirtualFileSystemEntry) file).getNameId();
        if (nameId > 0) {
            newDir = new DirectoryEntry(nameId);
        }
    }
    if (newDir == null) {
        newDir = new DirectoryEntry(file.getName());
    }
    doCreateChildren(newDir, iterateDBChildren(file), forDeletion);
    if (!isVersioned(file) && newDir.getChildren().isEmpty())
        return null;
    return newDir;
}
Also used : VirtualFileSystemEntry(com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) StoredContent(com.intellij.history.core.StoredContent) Document(com.intellij.openapi.editor.Document) DirectoryEntry(com.intellij.history.core.tree.DirectoryEntry) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with StoredContent

use of com.intellij.history.core.StoredContent in project intellij-community by JetBrains.

the class StreamTest method testDirectoryEntryWithChildren.

@Test
public void testDirectoryEntryWithChildren() throws IOException {
    Entry dir = new DirectoryEntry("");
    Entry subDir = new DirectoryEntry("");
    dir.addChild(subDir);
    subDir.addChild(new FileEntry("a", new StoredContent(333), -1, false));
    subDir.addChild(new FileEntry("b", new StoredContent(333), -1, false));
    StreamUtil.writeEntry(os, dir);
    Entry result = StreamUtil.readEntry(is);
    List<Entry> children = result.getChildren();
    assertEquals(1, children.size());
    Entry e = children.get(0);
    assertEquals(DirectoryEntry.class, e.getClass());
    assertSame(result, e.getParent());
    children = e.getChildren();
    assertEquals(2, children.size());
    assertEquals(FileEntry.class, children.get(0).getClass());
    assertSame(e, children.get(0).getParent());
    assertEquals(FileEntry.class, children.get(1).getClass());
    assertSame(e, children.get(1).getParent());
}
Also used : DirectoryEntry(com.intellij.history.core.tree.DirectoryEntry) Entry(com.intellij.history.core.tree.Entry) RootEntry(com.intellij.history.core.tree.RootEntry) FileEntry(com.intellij.history.core.tree.FileEntry) FileEntry(com.intellij.history.core.tree.FileEntry) StoredContent(com.intellij.history.core.StoredContent) DirectoryEntry(com.intellij.history.core.tree.DirectoryEntry) Test(org.junit.Test)

Example 3 with StoredContent

use of com.intellij.history.core.StoredContent in project intellij-community by JetBrains.

the class StreamTest method testDeleteChange.

@Test
public void testDeleteChange() throws IOException {
    DirectoryEntry dir = new DirectoryEntry("dir");
    dir.addChild(new FileEntry("file", new StoredContent(333), -1, false));
    dir.addChild(new DirectoryEntry("subDir"));
    Change c = new DeleteChange(nextId(), "entry", dir);
    StreamUtil.writeChange(os, c);
    Change read = StreamUtil.readChange(is);
    assertEquals(DeleteChange.class, read.getClass());
    DeleteChange result = (DeleteChange) read;
    assertEquals("entry", result.getPath());
    Entry e = result.getDeletedEntry();
    assertEquals(DirectoryEntry.class, e.getClass());
    assertEquals("dir", e.getName());
    assertEquals(2, e.getChildren().size());
    assertEquals("dir/file", e.getChildren().get(0).getPath());
    assertEquals("dir/subDir", e.getChildren().get(1).getPath());
}
Also used : DirectoryEntry(com.intellij.history.core.tree.DirectoryEntry) Entry(com.intellij.history.core.tree.Entry) RootEntry(com.intellij.history.core.tree.RootEntry) FileEntry(com.intellij.history.core.tree.FileEntry) FileEntry(com.intellij.history.core.tree.FileEntry) StoredContent(com.intellij.history.core.StoredContent) DirectoryEntry(com.intellij.history.core.tree.DirectoryEntry) Test(org.junit.Test)

Example 4 with StoredContent

use of com.intellij.history.core.StoredContent in project intellij-community by JetBrains.

the class DirectoryEntryTest method testHasUnavailableContent.

@Test
@Ignore
public void testHasUnavailableContent() {
    Entry dir = new DirectoryEntry("dir");
    assertHasNoUnavailableContent(dir);
    dir.addChild(new FileEntry("f", c("abc"), -1, false));
    assertHasNoUnavailableContent(dir);
    FileEntry f1 = new FileEntry("f1", new StoredContent(-1), -1, false);
    FileEntry f2 = new FileEntry("f2", new StoredContent(-1), -1, false);
    DirectoryEntry subDir = new DirectoryEntry("subDir");
    dir.addChild(subDir);
    dir.addChild(f1);
    subDir.addChild(f2);
    assertHasUnavailableContent(dir, f2, f1);
    assertHasUnavailableContent(subDir, f2);
}
Also used : StoredContent(com.intellij.history.core.StoredContent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with StoredContent

use of com.intellij.history.core.StoredContent in project intellij-community by JetBrains.

the class FileEntryTest method testHasUnavailableContent.

@Test
@Ignore
public void testHasUnavailableContent() {
    Entry e1 = new FileEntry(null, c("abc"), -1, false);
    Entry e2 = new FileEntry(null, new StoredContent(-1), -1, false);
    assertFalse(e1.hasUnavailableContent());
    assertTrue(e2.hasUnavailableContent());
}
Also used : StoredContent(com.intellij.history.core.StoredContent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

StoredContent (com.intellij.history.core.StoredContent)8 Test (org.junit.Test)7 DirectoryEntry (com.intellij.history.core.tree.DirectoryEntry)5 Entry (com.intellij.history.core.tree.Entry)4 FileEntry (com.intellij.history.core.tree.FileEntry)4 RootEntry (com.intellij.history.core.tree.RootEntry)4 Ignore (org.junit.Ignore)2 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 VirtualFileSystemEntry (com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry)1 Nullable (org.jetbrains.annotations.Nullable)1