PijulLogEntryCommitDetails.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.log
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.Change
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.vcs.log.Hash
import com.intellij.vcs.log.VcsFullCommitDetails
import com.intellij.vcs.log.VcsUser
import com.intellij.vcs.log.impl.HashImpl
import com.intellij.vcs.log.impl.VcsUserImpl
import org.apache.commons.codec.digest.DigestUtils
import java.nio.file.Path
class PijulLogEntryCommitDetails(
val root: Path,
val project: Project,
val entry: PijulLogEntry,
val changeRetriever: (String) -> List<Change>
) : VcsFullCommitDetails {
override fun getId(): Hash =
HashImpl.build(DigestUtils.sha1Hex(this.entry.changeHash))
//PijulHash(this.entry.changeHash)
override fun getParents(): MutableList<Hash> =
//this.entry.dependencies.map { it.hash }.map(::PijulHash).toMutableList()
this.entry.dependencies.map { it.hash }.map { DigestUtils.sha1Hex(it) }.map { HashImpl.build(it) }.toMutableList()
fun getPijulParents(): List<PijulHash> =
this.entry.dependencies.map { it.hash }.map(::PijulHash)
override fun getTimestamp(): Long = this.entry.date.toInstant().toEpochMilli()
override fun getRoot(): VirtualFile =
VirtualFileManager.getInstance().findFileByNioPath(this.root)!!
override fun getSubject(): String =
if (this.entry.message.isEmpty()) ""
else this.entry.message.split("\n").first { it.trim().isNotEmpty() }
override fun getAuthor(): VcsUser =
this.entry.authors.firstOrNull()?.let {
VcsUserImpl(it.name ?: "", it.email ?: "")
} ?: VcsUserImpl("", "")
override fun getCommitter(): VcsUser =
this.author
override fun getAuthorTime(): Long =
this.timestamp
override fun getCommitTime(): Long =
this.timestamp
override fun getFullMessage(): String =
this.entry.message
override fun getChanges(): MutableCollection<Change> =
this.changeRetriever(this.entry.changeHash).toMutableList()
override fun getChanges(parent: Int): MutableCollection<Change> =
this.changeRetriever(this.parents[parent].asString()).toMutableList()
}