Fork channel

Create a new channel as a copy of main.

Rename channel

Rename main to:

Delete channel

Delete main? This cannot be undone.

PijulContentRevision.kt
/**
 * Dracon - An IntelliJ-Pijul integration.
 * Copyright 2021 JonathanxD <jhrldev@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.github.jonathanxd.dracon.content

import com.github.jonathanxd.dracon.cache.FileRevisionCache
import com.github.jonathanxd.dracon.revision.PijulRevisionNumber
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.FilePath
import com.intellij.openapi.vcs.LocalFilePath
import com.intellij.openapi.vcs.changes.ContentRevision
import com.intellij.openapi.vcs.history.VcsRevisionNumber
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.ExperimentalPathApi

class PijulContentRevision(
    val root: Path,
    val filePath: Path,
    val revision: PijulRevisionNumber,
    val project: Project
) : ContentRevision {

    @OptIn(ExperimentalPathApi::class)
    constructor(
        root: Path,
        filePath: FilePath,
        revision: PijulRevisionNumber,
        project: Project
    ) : this(root, Paths.get(filePath.path), revision, project)

    private val content by lazy {
        this.project.service<FileRevisionCache>().loadAsync(this)
    }

    override fun getContent(): String = String(this.content.get(), Charsets.UTF_8)

    override fun getFile(): FilePath =
        LocalFilePath(this.filePath, Files.isDirectory(this.filePath))

    override fun getRevisionNumber(): VcsRevisionNumber =
        this.revision

    override fun toString(): String =
        "PijulContentRevision(${this.revision.hash})"
}