commit - 201cc4e4a6b34d9ad7518c89b4cbe0d4a7a8907a
commit + ba570446954968ad7b2feb330d7b6371087d413b
blob - ac1cc93524bbae9807b2bb24fc2210a6b8af6352
blob + 3c6290cecb06079e14f45563523a392484d336b2
--- src/main/kotlin/dev/nezzontli/gotvcs/GotCommandLineWrapper.kt
+++ src/main/kotlin/dev/nezzontli/gotvcs/GotCommandLineWrapper.kt
@Throws(VcsException::class)
fun catAtBase(workDir: File, relativePath: String): String =
run(workDir, "cat", "-c", ":base", "-P", relativePath)
+
+ @Throws(VcsException::class)
+ fun baseCommit(workDir: File): String {
+ val output = run(workDir, "info")
+ val line = output.lineSequence().firstOrNull { it.trimStart().startsWith("work tree base commit:") }
+ ?: throw VcsException("got info no reportó un commit base para $workDir")
+ return line.substringAfter("work tree base commit:").trim()
+ }
}
blob - 71fc5d1ce6d080d0810c34ed9caf00cac683e449
blob + 2b11afcff5ba20367d7e32ba7829e39a6fc8cb26
--- src/main/kotlin/dev/nezzontli/gotvcs/GotContentRevision.kt
+++ src/main/kotlin/dev/nezzontli/gotvcs/GotContentRevision.kt
override fun getFile(): FilePath = filePath
- override fun getRevisionNumber(): VcsRevisionNumber = VcsRevisionNumber.NULL
+ override fun getRevisionNumber(): VcsRevisionNumber = try {
+ GotRevisionNumber(commandLine.baseCommit(workDir))
+ } catch (e: VcsException) {
+ VcsRevisionNumber.NULL
+ }
}
blob - b5a39a068886b33c37f6f1679ea1a6aac2223b8b
blob + c7ec1298940b9e9368ea674e3d1b32b8ecdd8718
--- src/main/kotlin/dev/nezzontli/gotvcs/GotVcs.kt
+++ src/main/kotlin/dev/nezzontli/gotvcs/GotVcs.kt
import com.intellij.openapi.vcs.AbstractVcs
import com.intellij.openapi.vcs.VcsKey
import com.intellij.openapi.vcs.changes.ChangeProvider
+import com.intellij.openapi.vcs.diff.DiffProvider
class GotVcs(project: Project) : AbstractVcs(project, NAME) {
private val commandLine = GotCommandLineWrapper()
private val changeProvider = GotChangeProvider(commandLine)
+ private val diffProvider = GotDiffProvider(project, commandLine)
override fun getDisplayName(): String = NAME
override fun getChangeProvider(): ChangeProvider = changeProvider
+ override fun getDiffProvider(): DiffProvider = diffProvider
+
companion object {
const val NAME = "got"
blob - /dev/null
blob + 2e993f11cd12946885696846731a01e0c625bf13 (mode 644)
--- /dev/null
+++ src/main/kotlin/dev/nezzontli/gotvcs/GotDiffProvider.kt
+package dev.nezzontli.gotvcs
+
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.vcs.FilePath
+import com.intellij.openapi.vcs.ProjectLevelVcsManager
+import com.intellij.openapi.vcs.VcsException
+import com.intellij.openapi.vcs.changes.ContentRevision
+import com.intellij.openapi.vcs.diff.DiffProvider
+import com.intellij.openapi.vcs.diff.ItemLatestState
+import com.intellij.openapi.vcs.history.VcsRevisionNumber
+import com.intellij.openapi.vfs.VfsUtilCore
+import com.intellij.openapi.vfs.VirtualFile
+import com.intellij.vcsUtil.VcsUtil
+import java.io.File
+
+/**
+ * Alimenta el gutter de líneas modificadas y las acciones "Show Diff" a
+ * partir del commit base del work tree (`got info` + `got cat -c :base`).
+ * Solo compara contra la base actual; comparar contra revisiones históricas
+ * arbitrarias queda para la Fase 5 (historial).
+ */
+class GotDiffProvider(
+ private val project: Project,
+ private val commandLine: GotCommandLineWrapper,
+) : DiffProvider {
+
+ private fun rootAndRelativePath(file: VirtualFile): Pair<File, String>? {
+ val vcsRoot = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(file) ?: return null
+ val relativePath = VfsUtilCore.getRelativePath(file, vcsRoot) ?: return null
+ return File(vcsRoot.path) to relativePath
+ }
+
+ private fun baseRevisionOrNull(workDir: File): VcsRevisionNumber? = try {
+ GotRevisionNumber(commandLine.baseCommit(workDir))
+ } catch (e: VcsException) {
+ null
+ }
+
+ override fun getCurrentRevision(file: VirtualFile): VcsRevisionNumber? {
+ val (workDir, _) = rootAndRelativePath(file) ?: return null
+ return baseRevisionOrNull(workDir)
+ }
+
+ override fun getLastRevision(virtualFile: VirtualFile): ItemLatestState? {
+ val (workDir, _) = rootAndRelativePath(virtualFile) ?: return null
+ val revision = baseRevisionOrNull(workDir) ?: return null
+ return ItemLatestState(revision, true, true)
+ }
+
+ override fun getLastRevision(filePath: FilePath): ItemLatestState? {
+ val virtualFile = filePath.virtualFile ?: return null
+ return getLastRevision(virtualFile)
+ }
+
+ override fun createFileContent(revisionNumber: VcsRevisionNumber, selectedFile: VirtualFile): ContentRevision? {
+ val (workDir, relativePath) = rootAndRelativePath(selectedFile) ?: return null
+ val filePath = VcsUtil.getFilePath(selectedFile)
+ return GotContentRevision(filePath, workDir, relativePath, commandLine)
+ }
+
+ override fun getLatestCommittedRevision(vcsRoot: VirtualFile): VcsRevisionNumber? =
+ baseRevisionOrNull(File(vcsRoot.path))
+}
blob - /dev/null
blob + 3a7eed70de7a0f802b493ff624bccb5d3e125ad8 (mode 644)
--- /dev/null
+++ src/main/kotlin/dev/nezzontli/gotvcs/GotRevisionNumber.kt
+package dev.nezzontli.gotvcs
+
+import com.intellij.openapi.vcs.history.VcsRevisionNumber
+
+/** Identifica el commit base de un work tree got (hash resuelto vía `got info`). */
+data class GotRevisionNumber(private val commitId: String) : VcsRevisionNumber {
+
+ override fun asString(): String = commitId.take(12)
+
+ override fun compareTo(other: VcsRevisionNumber?): Int =
+ if (other is GotRevisionNumber) commitId.compareTo(other.commitId) else -1
+}