37OJKSWJFDRHNWQW6P7HSZX6OWZWVNCJ2IFT42O5TANQF7VOVX6AC
A7JOR7M3BUKXYMMAR43IK4GXFXGI33HM6H6LZHDES3HWW6GYFAYAC
G54TB4QZZ6OYC2KZTB7KUVW3NJ6VASH7WPNFU2IATPZWM3POIRNQC
2N67RQZCVGL6GYJJLM2US4YVCEIUK25AHCLD66C7HR4PPTNUOCWAC
7L5LODGZ7AN4ZULDJZMLALD7PL6E57VZSNNSG67SFJARUJGCT47QC
MTPTFTHGAOKQGRUDXC55AM6XJHZZZ5EF6FPVXKFVCUYVXJNEANYQC
GGYFPXND4VBCROZZXTKAP7Y4JOP2OOYQAFVLMUE7SLFM225EUSIAC
ZCRW57C5MSBXYGUMGQTZNHGHO4HGHFBICW53X5I2IMGP3H2CKWRQC
FRFFQV7VNYKGCA7ZAOSRPC2HHYTAIZ6AGGR7A5QEV6QPAQGFDYGAC
ISO7J5ZH5UB7NFZKTKKJQHQHCP4DWQ3F7SM2NDMVYJAGGIKDLX4QC
Q7FXTHVUPVAFMNY277C3NFJO3VXLZU5G6C6UYSD5QPURHSG3A7OQC
5AUENX2YJVFNKZUSPEPDNLLL7TKZS2WTFC6CABWSZK2EC4MNCRQAC
B43WNBLFFR2UQIH3C6KIZAQTAEQOQM3J3IYLGQMVGJHYOME73OKQC
6CR2EFUN7JXFHCBTNX3WWOOP4WFOCFO6KSPEBN6V6J5HFZO2LHNQC
QXUEMZ3B2FUHFUC7ZZHJMH5FVWLEMEYXUMFA6JNXTJKIVZNMRIOAC
FNNW5IEAXQ43WKB6QSQB7DFLG3Y3T5FYPXIUX7KQ2URR2GU3QLTAC
OPFG6CZ26PPTGTH7ULLRQGZGR3YEIEJOV5W2E3WN7PFRZS62CVLQC
Q35OTML226J2HZLHOCPV5OY6ZUM2XU4RZBE5E3GDWVHVFASHFEJAC
NTRPUMVQHUIQZ6O72NJ72XFYTZWZOSDA6CSKMUCGKFVNE3KIDYYQC
PGNTR2EPCZBOWI67LKY6AN5B3RGIEOQ6NTTXGODLESKDSPWV26KQC
MZYZIVHY5DUHVJH7YGENRAIKTKMZWJ5ANRVGFLLU7YTHXC2OXZJQC
EAGIDXOLFTHZMZ77ZWAM7MVVUBBXJMZD7RZUNBHJPYRFGGKILGVAC
package com.github.jonathanxd.dracon.test
import com.github.jonathanxd.dracon.log.*
import com.github.jonathanxd.dracon.pijul.credit.parseCredit
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import java.time.ZoneOffset
import java.time.ZonedDateTime
class DraconCreditTest : ShouldSpec({
should("correctly parse a 'pijul credit' text with example credit") {
val text = """
GGYFPXND4VBCQ
NTRPUMVQHUIQY
> #
> # 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.
> #
>
GGYFPXND4VBCQ, NTRPUMVQHUIQY
> dracon.vcs.name=Pijul
> dracon.vcs.name.with.mnemonic=_Pijul
Q7FXTHVUPVAFM
>
GGYFPXND4VBCQ, Q7FXTHVUPVAFM
>
MTPTFTHGAOKQG
> action.Pijul.Init.text=Create Pijul Repository
> action.Pijul.Add.text=Add Files...
ZCRW57C5MSBXY
> action.Pijul.ExpertRecord.text=Record (Expert Mode)...
2N67RQZCVGL6G
> action.Pijul.InvalidateCaches.text=Invalidate Caches
ZCRW57C5MSBXY, 2N67RQZCVGL6G, MTPTFTHGAOKQG
> action.Pijul.Commit.And.Push.text=Commit And Push...
GGYFPXND4VBCQ, MTPTFTHGAOKQG
> init.title=Create Pijul Repository
> init.description=Select the target directory to init Pijul repository.
> init.warning.title=Pijul Init
> init.warning.already.under.pijul=The directory <tt>{0}</tt> is already under Pijul.\n\
Q7FXTHVUPVAFM, MTPTFTHGAOKQG
> Are you sure that you want to create a new VCS root?
> init.error=Failed to initialize Pijul repository.
>
> dracon.refresh=Refreshing Pijul Repository
>
ZCRW57C5MSBXY, Q7FXTHVUPVAFM
> group.Pijul.Menu.text=_Pijul
>
> record.action.name=Record
ZCRW57C5MSBXY, 2N67RQZCVGL6G
> record.author=&Author:
> record.expert.mode.title=Record (Expert Mode)
>
> expert.mode.button.record=Record
> expert.mode.button.cancel=Cancel
>
> expert.mode.notification.group.id=Expert mode
> expert.mode.notification.title=Record (expert mode)
> expert.mode.notification.success=Successfully recorded changes. New revision: <tt>{0}</tt>.
2N67RQZCVGL6G
> expert.mode.notification.failure=Failed to record changes with exit code <bold>{0}</bold> and message: <tt>{1}</tt>.
>
> cache.invalidate.text=Invalidating caches...
> cache.invalidate.current.text=Invalidating <em>{0}</em>...
> cache.invalidate.finish.text=Invalidated caches
>
> install.pijul.title=Install pijul
> install.pijul.title2=Install Pijul
> install.pijul.text=Cannot find pijul binaries.\n\
> Do you want to install pijul using rust cargo?
>
> install.editor.server.title=Install editor-server
> install.editor.server.title2=Install Editor Server
> install.editor.server.text=Cannot find editor-server binaries.\n\
> Dracon depends on editor-server for interfacing with Pijul.\n\
> Do you want to install editor-server using rust cargo?
>
> install.cargo.title=Install Rustup and Cargo
> install.cargo.text=In order to install <tt>{0}</tt> you need to have cargo installed.\n\
> However we cannot find cargo installed in this machine.\n\
> Do you want to install rustup with cargo?\n\
> If you agree, we will download rustup and launch the installer, you take from there.
>
> install.pijul.warning.text=You won't be able to use Dracon plugin since some dependencies could not be installed.
>
> install.cargo.running.text=Running cargo install...
""".trimIndent()
val credit = text.parseCredit()
credit.toString() shouldBe "PijulCredit(header=[GGYFPXND4VBCQ], entries=[PijulCreditEntry(shortHash=[NTRPUMVQHUIQY], data=[#, # 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., #, ]), PijulCreditEntry(shortHash=[GGYFPXND4VBCQ, NTRPUMVQHUIQY], data=[dracon.vcs.name=Pijul, dracon.vcs.name.with.mnemonic=_Pijul]), PijulCreditEntry(shortHash=[Q7FXTHVUPVAFM], data=[]), PijulCreditEntry(shortHash=[GGYFPXND4VBCQ, Q7FXTHVUPVAFM], data=[]), PijulCreditEntry(shortHash=[MTPTFTHGAOKQG], data=[action.Pijul.Init.text=Create Pijul Repository, action.Pijul.Add.text=Add Files...]), PijulCreditEntry(shortHash=[ZCRW57C5MSBXY], data=[action.Pijul.ExpertRecord.text=Record (Expert Mode)...]), PijulCreditEntry(shortHash=[2N67RQZCVGL6G], data=[action.Pijul.InvalidateCaches.text=Invalidate Caches]), PijulCreditEntry(shortHash=[ZCRW57C5MSBXY, 2N67RQZCVGL6G, MTPTFTHGAOKQG], data=[action.Pijul.Commit.And.Push.text=Commit And Push...]), PijulCreditEntry(shortHash=[GGYFPXND4VBCQ, MTPTFTHGAOKQG], data=[init.title=Create Pijul Repository, init.description=Select the target directory to init Pijul repository., init.warning.title=Pijul Init, init.warning.already.under.pijul=The directory <tt>{0}</tt> is already under Pijul.\\n\\]), PijulCreditEntry(shortHash=[Q7FXTHVUPVAFM, MTPTFTHGAOKQG], data=[ Are you sure that you want to create a new VCS root?, init.error=Failed to initialize Pijul repository., , dracon.refresh=Refreshing Pijul Repository, ]), PijulCreditEntry(shortHash=[ZCRW57C5MSBXY, Q7FXTHVUPVAFM], data=[group.Pijul.Menu.text=_Pijul, , record.action.name=Record]), PijulCreditEntry(shortHash=[ZCRW57C5MSBXY, 2N67RQZCVGL6G], data=[record.author=&Author:, record.expert.mode.title=Record (Expert Mode), , expert.mode.button.record=Record, expert.mode.button.cancel=Cancel, , expert.mode.notification.group.id=Expert mode, expert.mode.notification.title=Record (expert mode), expert.mode.notification.success=Successfully recorded changes. New revision: <tt>{0}</tt>.]), PijulCreditEntry(shortHash=[2N67RQZCVGL6G], data=[expert.mode.notification.failure=Failed to record changes with exit code <bold>{0}</bold> and message: <tt>{1}</tt>., , cache.invalidate.text=Invalidating caches..., cache.invalidate.current.text=Invalidating <em>{0}</em>..., cache.invalidate.finish.text=Invalidated caches, , install.pijul.title=Install pijul, install.pijul.title2=Install Pijul, install.pijul.text=Cannot find pijul binaries.\\n\\, Do you want to install pijul using rust cargo?, , install.editor.server.title=Install editor-server, install.editor.server.title2=Install Editor Server, install.editor.server.text=Cannot find editor-server binaries.\\n\\, Dracon depends on editor-server for interfacing with Pijul.\\n\\, Do you want to install editor-server using rust cargo?, , install.cargo.title=Install Rustup and Cargo, install.cargo.text=In order to install <tt>{0}</tt> you need to have cargo installed.\\n\\, However we cannot find cargo installed in this machine.\\n\\, Do you want to install rustup with cargo?\\n\\, If you agree, we will download rustup and launch the installer, you take from there., , install.pijul.warning.text=You won't be able to use Dracon plugin since some dependencies could not be installed., , install.cargo.running.text=Running cargo install...])])"
}
})
install.cargo.running.text=Running cargo install...
index.revision.text=Indexing files revisions.
index.reset.text=Resetting working directory...
index.item.description.text=Indexing <tt>{0}</tt>...
index.item.description.finish.text=Finished!
index.unrecord.description.text=Un-recording changes...
index.ls.text=Listing tracked files...
index.revision.loading.text=Loading revisions...
index.revision.files.text=Working on files...
index.revision.description.text=Working on revision {0}...
index.revision.file.description.text=Loading file {0} of revision {1}...
<!-- Pijul ignore lang -->
<fileType language="PijulIgnore" extensions="ignore" fieldName="INSTANCE" name="PijulIgnore file"
implementationClass="com.github.jonathanxd.dracon.lang.ignore.PijulIgnoreFileType"/>
<lang.parserDefinition language="PijulIgnore"
implementationClass="com.intellij.openapi.vcs.changes.ignore.lang.IgnoreParserDefinition"/>
<codeInsight.lineMarkerProvider language="PijulIgnore"
implementationClass="com.intellij.openapi.vcs.changes.ignore.codeInsight.IgnoreDirectoryMarkerProvider"/>
<lang.braceMatcher language="PijulIgnore" implementationClass="com.intellij.openapi.vcs.changes.ignore.lang.IgnoreBraceMatcher"/>
<lang.commenter language="PijulIgnore" implementationClass="com.intellij.openapi.vcs.changes.ignore.lang.IgnoreCommenter"/>
<!--END Pijul ignore lang-->
<action id="Pijul.InvalidateCaches" class="com.github.jonathanxd.dracon.actions.PijulInvalidateCaches">
</action>
<action id="Pijul.InvalidateCaches" class="com.github.jonathanxd.dracon.actions.PijulInvalidateCaches"/>
<action id="Pijul.AddToIgnore" class="com.github.jonathanxd.dracon.actions.PijulAddToIgnore"/>
</group>
<group id="Pijul.Ignore.File" class="com.github.jonathanxd.dracon.actions.PijulIgnoreActionGroup">
<add-to-group group-id="ChangesViewPopupMenu" anchor="after" relative-to-action="ChangesView.AddUnversioned"/>
<add-to-group group-id="Pijul.Menu" anchor="after" relative-to-action="Pijul.Add"/>
<add-to-group group-id="Unversioned.Files.Dialog.Popup" anchor="after" relative-to-action="$Delete"/>
val tempDir = FileUtilRt.createTempDirectory("dracon_diffs-", revisionHash)
if (Files.isDirectory(filePath)) {
// Will always fail for directories.
return ""
}
val tempDir = FileUtilRt.createTempDirectory("dracon_diffs-", revisionHash + UUID.randomUUID().toString())
} finally {
FileUtilRt.delete(tempDir)
}
}
@OptIn(ExperimentalPathApi::class)
fun loadStateInRevisionForAllFiles(revisionHash: String,
project: Project,
root: Path,
i: ProgressIndicator): Map<Path, ByteArray> {
val tempDir = FileUtilRt.createTempDirectory("dracon_diffs-all-", revisionHash + UUID.randomUUID().toString())
val tmpTarget = tempDir.toPath()
val pathToRevisionState = mutableMapOf<Path, ByteArray>()
copyFolder(root, tmpTarget, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
val revisions = pijul(project).latestRevisionNumber(project, tmpTarget).result
i.text2 = DraconBundle.message("index.reset.text")
val reset = pijul(project).reset(project, tmpTarget)
if (reset.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revision $revisionHash during reset. $revisions")
}
i.fraction += 0.0001
if (revisions == null || revisions.hash != revisionHash) {
i.text2 = DraconBundle.message("index.unrecord.description.text")
val rollbackOp = pijul(project).rollbackTo(revisionHash, project, tmpTarget)
if (rollbackOp.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revision $revisionHash during unrecord. $rollbackOp")
}
i.fraction += 0.0001
}
i.text2 = DraconBundle.message("index.ls.text")
val ls = pijul(project).trackedFiles(project, tmpTarget)
if (ls.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revision $revisionHash during reset. $revisions")
}
i.fraction += 0.0001
val trackedFiles = ls.result!!
trackedFiles.forEachWithProgress(i) { it, indic ->
indic.text2 = DraconBundle.message("index.item.description.text", it.toString())
if (Files.isRegularFile(it)) {
pathToRevisionState[it] = Files.readAllBytes(it)
}
}
i.text2 = DraconBundle.message("index.item.description.finish.text")
try {
return pathToRevisionState
} finally {
FileUtilRt.delete(tempDir)
}
}
@OptIn(ExperimentalPathApi::class)
fun loadStateInEveryRevisionForAllFiles(allRevisions: List<String>,
project: Project,
root: Path,
i: ProgressIndicator): Map<String, Map<Path, ByteArray>> {
if (allRevisions.isEmpty()) {
throw IllegalArgumentException("Provided 'allRevisions' argument must not be empty.")
}
val tempDir = FileUtilRt.createTempDirectory("dracon_diffs-all-","${allRevisions.size}-" + UUID.randomUUID().toString())
val tmpTarget = tempDir.toPath()
val revisionToPathToState = mutableMapOf<String, MutableMap<Path, ByteArray>>()
copyFolder(root, tmpTarget, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
val revisions = pijul(project).allRevisions(project, tmpTarget)
if (revisions.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revisions '$allRevisions' during all revisions hash retrieval. $revisions")
}
val pijulRevisions = revisions.result!!.map { it.hash }
val indexOfFirstRevision = pijulRevisions.indexOf(allRevisions[0])
if (indexOfFirstRevision == -1) {
throw IllegalArgumentException("Could not find revision ${allRevisions[0]} in Pijul repository!")
} else {
if (indexOfFirstRevision + allRevisions.size >= pijulRevisions.size) {
throw IllegalArgumentException("There are more revisions to unrecord than the amount of recorded changes in Pijul Repository.")
} else {
val revisionSubList = pijulRevisions.subList(indexOfFirstRevision, indexOfFirstRevision + allRevisions.size)
if (allRevisions != revisionSubList) {
throw IllegalArgumentException("Revisions to load must sequentially match a sub sequence of revisions in Pijul repository. " +
"Changes found in pijul: $revisionSubList. Changes to unrecord: $allRevisions")
}
}
}
i.text2 = DraconBundle.message("index.reset.text")
val reset = pijul(project).reset(project, tmpTarget)
if (reset.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revisions '$allRevisions' during reset. $reset")
}
i.fraction += 0.0001
allRevisions.withIndex().toList().forEachWithProgress(i) { (index, rev), indicator ->
val pathToRevisionState = revisionToPathToState.computeIfAbsent(rev) { mutableMapOf() }
indicator.text2 = DraconBundle.message("index.revision.description.text", rev)
if (index == 0) {
val rollback = pijul(project).rollbackTo(rev, project, tmpTarget)
if (rollback.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revision '$rev' during rollback. $rollback")
}
} else {
val unrecord = pijul(project).unrecord(project, tmpTarget, rev)
if (unrecord.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revision '$rev' during unrecord. $unrecord")
}
}
indicator.text2 = DraconBundle.message("index.ls.text")
val ls = pijul(project).trackedFiles(project, tmpTarget)
if (ls.statusCode !is SuccessStatusCode) {
throw IllegalStateException("Failed to load state of all files in revision $rev during tracked file listing. $ls")
}
indicator.fraction += 0.0001
val trackedFiles = ls.result!!
trackedFiles.forEachWithProgress(indicator) { it, indic ->
indic.text2 = DraconBundle.message("index.item.description.text", it.toString())
if (Files.isRegularFile(it)) {
val relativeToRoot = root.resolve(it.relativeTo(tmpTarget))
pathToRevisionState[relativeToRoot] = Files.readAllBytes(it)
}
}
}
i.text2 = DraconBundle.message("index.item.description.finish.text")
try {
return revisionToPathToState
partner.acceptRevision(
PijulVcsFileRevision(
this.project,
root.toNioPath(),
path,
PijulRevisionNumber(it.changeHash, it.date),
it.authors.map { VcsUserImpl(it.name ?: "", it.email ?: "") }.filter { it.name.isNotEmpty() },
it.message,
currentChannel,
deleted
partner.acceptRevision(
PijulVcsFileRevision(
this.project,
root.toNioPath(),
path,
PijulRevisionNumber(it.changeHash, it.date),
it.authors.map { VcsUserImpl(it.name ?: "", it.email ?: "") }.filter { it.name.isNotEmpty() },
msg,
currentChannel,
deleted
)
package com.github.jonathanxd.dracon.pijul.credit
import com.github.jonathanxd.dracon.log.substringUntil
import java.io.Serializable
data class PijulCredit(val header: List<String>,
val entries: List<PijulCreditEntry>
): Serializable {
companion object {
const val serialVersionUID = 1L
}
}
data class PijulCreditEntry(val shortHash: List<String>, val data: List<String>): Serializable {
companion object {
const val serialVersionUID = 1L
}
}
fun String.parseCredit(): PijulCredit {
val header = mutableListOf<String>()
val lines = mutableListOf<PijulCreditEntry>()
var shortHashes: List<String>? = null
var pointer = 0
while (pointer > -1) {
if (pointer < this.length && this[pointer] == '\n') {
pointer += 1
continue
}
if (pointer == this.length) {
break
}
val line = this.substringUntil(pointer, '\n', includeChar = false)
if (line.isNotEmpty() && line.isNotBlank()) {
if (!line.startsWith(">")) {
if (shortHashes != null) {
header.addAll(shortHashes)
}
shortHashes = line.split(",").map { it.trim() }
} else {
val hashes = shortHashes
?: throw IllegalStateException("Something wrong happened during credit parsing")
val data = mutableListOf<String>()
var dataLine = line
while (dataLine.startsWith("> ") && pointer > -1) {
data.add(dataLine.substring("> ".length))
if (pointer + 1 >= this.length) {
break;
}
pointer = this.indexOf("\n", pointer + 1)
if (pointer == -1) {
break
}
while (pointer < this.length && this[pointer] == '\n') {
pointer += 1
if (pointer == this.length) {
break
}
}
dataLine = this.substringUntil(pointer, '\n', includeChar = false)
}
shortHashes = null
lines += PijulCreditEntry(hashes, data)
if (!dataLine.startsWith("> ") && line.isNotEmpty() && line.isNotBlank()) {
shortHashes = dataLine.split(",").map { it.trim() }
}
}
}
if (pointer == -1) {
break
}
if (pointer + 1 >= this.length) {
break;
}
pointer = this.indexOf("\n", pointer + 1)
}
if (shortHashes != null) {
header.addAll(shortHashes)
}
return PijulCredit(header, lines)
}
package com.github.jonathanxd.dracon.lang.ignore
import com.intellij.openapi.vcs.changes.ignore.lang.IgnoreFileType
import com.intellij.openapi.vcs.changes.ignore.lang.IgnoreLanguage
import com.intellij.openapi.vcs.changes.ignore.lang.Syntax
object PijulIgnoreLanguage : IgnoreLanguage("PijulIgnore", "ignore") {
override fun getFileType(): IgnoreFileType = PijulIgnoreFileType
override fun isSyntaxSupported(): Boolean = true
override fun getDefaultSyntax(): Syntax = Syntax.REGEXP
}
package com.github.jonathanxd.dracon.lang.ignore
import com.intellij.openapi.vcs.changes.ignore.lang.IgnoreFileType
object PijulIgnoreFileType : IgnoreFileType(PijulIgnoreLanguage)
package com.github.jonathanxd.dracon.ignore
import com.github.jonathanxd.dracon.PijulVcs
import com.intellij.openapi.vcs.IgnoredCheckResult
import com.intellij.openapi.vcs.VcsIgnoreChecker
import com.intellij.openapi.vcs.VcsKey
import com.intellij.openapi.vfs.VirtualFile
import java.nio.file.Path
class PijulIgnoreChecker : VcsIgnoreChecker {
override fun getSupportedVcs(): VcsKey = PijulVcs.KEY
override fun isIgnored(vcsRoot: VirtualFile, file: Path): IgnoredCheckResult {
TODO("Not yet implemented")
}
override fun isFilePatternIgnored(vcsRoot: VirtualFile, filePattern: String): IgnoredCheckResult {
TODO("Not yet implemented")
}
}
val execution = this.createExecPijulOperation(project, path, listOf("add", "-r") + pathList)
val execution = if (pathList.all { Files.isRegularFile(path.resolve(it)) }) {
this.createExecPijulOperation(project, path, listOf("add") + pathList)
} else {
this.createExecPijulOperation(project, path, listOf("add", "-r") + pathList)
}
@OptIn(ExperimentalPathApi::class)
override fun credit(project: Project, root: Path, file: Path): PijulOperationResult<PijulCredit> {
val filePath = file.relativeTo(root).toString()
val credit = this.doExecutionWithMapper("credit",
this.createExecPijulOperation(project, root, listOf("credit", filePath))
) {
if (it.isEmpty() || it.trim().isEmpty() || it.trim().isBlank()) null
else it.parseCredit()
}
return credit
}
}
}
override fun unrecord(project: Project, root: Path, hash: String): PijulOperationResult<Boolean> {
val unrecord = this.doExecution(
"unrecord_$hash",
this.createPainlessExecPijulOperation(project, root, listOf("unrecord", "--reset", hash))
)
if (unrecord.statusCode !is SuccessStatusCode) {
return unrecord as PijulOperationResult<Boolean>
package com.github.jonathanxd.dracon.cache
import com.github.jonathanxd.dracon.context.PijulVcsContext
import com.github.jonathanxd.dracon.log.PijulLogEntry
import com.github.jonathanxd.dracon.pijul.PijulOperationResult
import com.github.jonathanxd.dracon.pijul.SuccessStatusCode
import com.github.jonathanxd.dracon.revision.PijulRevisionNumber
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import java.nio.file.Path
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.relativeTo
@Suppress("UnstableApiUsage")
@OptIn(ExperimentalPathApi::class)
@Service
class PijulLogRevisionCache(val project: Project): CacheService<String, PijulRevisionNumber> {
override val cache = DataCache<String, PijulRevisionNumber>(project, "revision")
fun loadRevision(path: Path, compute: () -> PijulOperationResult<PijulRevisionNumber>): PijulOperationResult<PijulRevisionNumber> {
val ctx = this.project.service<PijulVcsContext>()
val relativePath = path.relativeTo(ctx.root).toString()
return this.cache.queryOrLoad(relativePath,
{ compute() },
{ it.statusCode is SuccessStatusCode },
{it.result!!},
{ PijulOperationResult("revision", SuccessStatusCode, it) }
)
}
fun unload(path: Path) {
val ctx = this.project.service<PijulVcsContext>()
val relativePath = path.relativeTo(ctx.root).toString()
this.invalidate(relativePath)
}
override fun invalidate(key: String) {
super.invalidate(key)
this.cache.unload("")
}
}
class PijulLogEntryChangeCache(val project: Project) {
private val dataCache = DataCache<String, PijulLogEntry>(project, "path_change")
private val revisionDataCache = DataCache<String, PijulRevisionNumber>(project, "revision")
class PijulLogEntryChangeCache(val project: Project): CacheService<String, PijulLogEntry> {
override val cache = DataCache<String, PijulLogEntry>(project, "path_change")
)
}
fun loadRevision(path: Path, compute: () -> PijulOperationResult<PijulRevisionNumber>): PijulOperationResult<PijulRevisionNumber> {
val ctx = this.project.service<PijulVcsContext>()
val relativePath = path.relativeTo(ctx.root).toString()
return this.revisionDataCache.queryOrLoad(relativePath,
{ compute() },
{ it.statusCode is SuccessStatusCode },
{it.result!!},
{ PijulOperationResult("revision", SuccessStatusCode, it) }
class PijulLogEntryCache(val project: Project) {
private val dataCache = DataCache<String, PijulLogEntry>(project, "change")
class PijulLogEntryCache(val project: Project): CacheService<String, PijulLogEntry> {
override val cache = DataCache<String, PijulLogEntry>(project, "change")
class FileStatusCache(val project: Project) {
private val cache = DataCache<String, CacheablePijulFileStatus>(this.project, "file_status")
class FileStatusCache(val project: Project): CacheService<String, CacheablePijulFileStatus> {
override val cache = DataCache<String, CacheablePijulFileStatus>(this.project, "file_status")
fun invalidate() {
this.cache.invalidate()
fun updateCache(path: Path, newValueCompute: () -> CacheablePijulFileStatus) {
val ctx = this.project.service<PijulVcsContext>()
val relativePath = path.relativeTo(ctx.root).toString()
super.updateCache(relativePath, newValueCompute)
}
fun updateCacheForPaths(paths: List<Path>, newValueCompute: (Path) -> CacheablePijulFileStatus) {
val ctx = this.project.service<PijulVcsContext>()
val relativePathMap = paths.associateBy { it.relativeTo(ctx.root).toString() }
super.updateCache(relativePathMap.keys.toList()) {
newValueCompute(relativePathMap[it]!!)
}
import com.github.jonathanxd.dracon.revision.PijulVcsFileRevision
import com.github.jonathanxd.dracon.revision.loadStateInRevision
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.pijul.pijul
import com.github.jonathanxd.dracon.revision.*
class FileRevisionCache(val project: Project) {
private val cache = DataCache<FileRevisionRef, ByteArray>(this.project, "file_revision")
class FileRevisionCache(val project: Project) : CacheService<FileRevisionRef, ByteArray> {
override val cache = DataCache<FileRevisionRef, ByteArray>(this.project, "file_revision")
fun loadAsync(rev: PijulVcsFileRevision): CompletableFuture<ByteArray> =
this.loadAsync(rev.filePath, rev.revision)
fun loadAsync(rev: PijulContentRevision): CompletableFuture<ByteArray> =
this.loadAsync(rev.filePath, rev.revision)
private fun Path.filePathAsString() = this.toAbsolutePath().toString()
fun loadAndPrecacheRevisions(amount: Int, i: ProgressIndicator) {
this.cache.lock()
try {
i.isIndeterminate = false
val root = project.service<PijulVcsContext>().root
val revs = pijul(project).allRevisions(project, root).result?.take(amount).orEmpty()
fun loadAsync(rev: PijulContentRevision): CompletableFuture<ByteArray> {
val root = project.service<PijulVcsContext>().root
val fileRev = FileRevisionRef(rev.filePath.toAbsolutePath().toString(), rev.revision.hash)
val states = i.withPushPop {
i.text = DraconBundle.message("index.revision.loading.text")
loadStateInEveryRevisionForAllFiles(
revs.map { it.hash },
project,
root,
i
)
}
i.text2 = DraconBundle.message("index.item.description.finish.text")
i.withPushPop {
i.text = DraconBundle.message("index.revision.files.text")
states.entries.forEachWithProgress(i) { (rev, stateMap), indic ->
stateMap.entries.forEachWithProgress(indic) { (path, bytes), indicator2 ->
indicator2.text2 =
DraconBundle.message("index.revision.file.description.text", path.toString(), rev)
val revRef = FileRevisionRef(path.filePathAsString(), rev)
this.cache.updateCache(revRef) {
bytes
}
}
}
}
return this.cache.queryOrLoadAsync(fileRev) {
loadStateInRevision(
rev.revision.hash,
this.project,
root,
rev.filePath
).toByteArray(Charsets.UTF_8)
i.text2 = DraconBundle.message("index.item.description.finish.text")
i.fraction = 1.0
} finally {
this.cache.unlock()
/**
* @see CacheService.invalidate
*/
fun invalidate(key: K) {
this.lock.lock()
try {
this.inMemory.remove(key)
this.manager.write(this.inMemory)
} finally {
this.lock.unlock();
}
}
/**
* @see CacheService.updateCache
*/
fun updateCache(key: K, newValueCompute: () -> V) {
val instant = Instant.now()
this.lock()
try {
val inMemoryValue = this.inMemory[key]
if (inMemoryValue == null || inMemoryValue.instant.isBefore(instant)) {
this.inMemory[key] = CachedValue(instant, newValueCompute())
}
} finally {
this.unlock()
}
}
/**
* @see CacheService.updateCache
*/
fun updateCache(keys: List<K>, newValueCompute: (K) -> V) {
val instant = Instant.now()
this.lock()
try {
for (key in keys) {
val inMemoryValue = this.inMemory[key]
if (inMemoryValue == null || inMemoryValue.instant.isBefore(instant)) {
this.inMemory[key] = CachedValue(instant, newValueCompute(key))
}
}
} finally {
this.unlock()
}
}
package com.github.jonathanxd.dracon.cache
import java.io.Serializable
import java.time.Instant
class CachedValue<V>(val instant: Instant, val value: V): Serializable {
companion object {
const val serialVersionUID = 1L
}
}
package com.github.jonathanxd.dracon.cache
import com.intellij.openapi.components.Service
import java.time.Instant
/**
* This is a base interface implemented by every [DataCache] service,
* as [DataCache] is never used directly, an [IntelliJ Light Service][Service]
* must be setup to interface a [DataCache] and classes that uses the cache.
*
* This interface is for [Cache][DataCache] [Services][Service] which manages a single [DataCache][cache]
* with a [key type][K] [K] and a [value type][V] [V]. If the service does manages more than one [DataCache][cache],
* we **heavily recommend** you to split it into two different services which communicate with each other.
*/
interface CacheService<K: Any, V: Any> {
val cache: DataCache<K, V>
/**
* Invalidates the [cache] that this service handles.
*
* ## **Warning**
*
* **This is only recommended when the cache is not working correctly, corrupted or an operation that changes
* all the data that was previously cached takes in place.**
*
* **This is not recommended to be called for little changes, such as the ones that applies to only one or `N{2,}` keys
* because it slow down the perception of the Dracon performance, as it does need to cache all the data again, and as the
* cache is backed by a temporary file in the seconday storage (not a memory one), it does depends on the I/O
* overhead, which is good for NVMe storages and SATA 3 ones, but not for HDDs. Also some `pijul` operations are really
* expensive, such as `pijul unrecord`, the Dracon Log Algorithm, Dracon File Status algorithms and Dracon Revision
* load algorithm (backed by `pijul unrecord`), when the cache of these operations is invalidated, the overall
* performance Dracon drops absurdly.**
*
* @see DataCache
*/
fun invalidate() {
this.cache.invalidate()
}
/**
* Invalidates one key in [cache], this is a good way to invalidate data in cache (but not the best one), as it does not
* cause all the cache to be recomputed, however, if you already know the new value for the cache, or a function
* to compute it, use [updateCache] function.
*
*/
fun invalidate(key: K) {
this.cache.invalidate(key)
}
/**
* Updates the cache value of a [key] using the [newValueCompute]. This is the best way to update the cache data,
* as it does provides either a lightweight function to compute the new cache value, or a constant computed value
* that does not involve a new computation routine.
*
* Please note that this function does not guarantee that the new computed value will be inserted into the cache,
* because the cache could be updated between the time you change something that need to be reflected in the cache,
* and the time request to update the key, if a cache recompute operation takes in this time between, the
* service will ignore the provided [newValueCompute]. The up-to-date check is made using [CachedValue] container,
* which holds the [Instant] which provides the time that an operation requested to update the cache (not the time the
* update takes place). However this check do not guarantee that the cached value will be up-to-date, as we cannot guarantee
* that the time the operation was requested matches the time the data was created.
*/
fun updateCache(key: K, newValueCompute: () -> V) {
this.cache.updateCache(key, newValueCompute)
}
/**
* Updates the cache value of multiple [keys] using the [newValueCompute]. This is the best way to update the cache data,
* as it does provides either a lightweight function to compute the new cache value, or a constant computed value
* that does not involve a new computation routine.
*
* Please note that this function does not guarantee that the new computed value will be inserted into the cache,
* because the cache could be updated between the time you change something that need to be reflected in the cache,
* and the time request to update the key, if a cache recompute operation takes in this time between, the
* service will ignore the provided [newValueCompute]. The up-to-date check is made using [CachedValue] container,
* which holds the [Instant] which provides the time that an operation requested to update the cache (not the time the
* update takes place). However this check do not guarantee that the cached value will be up-to-date, as we cannot guarantee
* that the time the operation was requested matches the time the data was created.
*/
fun updateCache(keys: List<K>, newValueCompute: (K) -> V) {
this.cache.updateCache(keys, newValueCompute)
}
}
package com.github.jonathanxd.dracon.annotation
import com.github.jonathanxd.dracon.cache.CacheService
/**
* Signals that to an operation take effect in IntelliJ, the underling cache needs to be updated.
*
*
* There are two ways of updating the underling cache:
*
* #### Execute [CacheService.invalidate]
*
* It does cleanup the entire cache, which is only recommended for when the change does update everything that was cached,
* or when the user requests to invalidate the cache, because the cache may be not working correctly or corrupt.
*
*/
annotation class NeedsCacheUpdate()
package com.github.jonathanxd.dracon.activity
import com.github.jonathanxd.dracon.cache.FileRevisionCache
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.intellij.openapi.components.service
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
const val PRE_INDEX_REVISION_AMOUNT = 30
class PijulIndexActivity : StartupActivity.Background {
override fun runActivity(project: Project) {
object : Task.Backgroundable(project, DraconBundle.message("index.revision.text")) {
override fun run(indicator: ProgressIndicator) {
val fileRevisionCache = project.service<FileRevisionCache>()
fileRevisionCache.loadAndPrecacheRevisions(PRE_INDEX_REVISION_AMOUNT, indicator)
}
}.queue()
}
}
import com.github.jonathanxd.dracon.cache.FileRevisionCache
import com.github.jonathanxd.dracon.cache.FileStatusCache
import com.github.jonathanxd.dracon.cache.PijulLogEntryCache
import com.github.jonathanxd.dracon.cache.PijulLogEntryChangeCache
import com.github.jonathanxd.dracon.cache.*
package com.github.jonathanxd.dracon.actions
import com.intellij.openapi.vcs.changes.ignore.actions.IgnoreFileActionGroup
import com.intellij.openapi.vcs.changes.ignore.lang.IgnoreFileType
object PijulIgnoreActionGroup : IgnoreFileActionGroup(IgnoreFileType.INSTANCE)
/**
* 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.actions
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.pijul.NonZeroExitStatusCode
import com.github.jonathanxd.dracon.pijul.Pijul
import com.github.jonathanxd.dracon.pijul.pijul
import com.github.jonathanxd.dracon.util.wrapInHml
import com.github.jonathanxd.dracon.vcs.DraconVcsUtil
import com.github.jonathanxd.dracon.vcs.NotificationIds
import com.github.jonathanxd.dracon.vfs.DraconVfsUtil
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.fileChooser.FileChooser
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vcs.ProjectLevelVcsManager
import com.intellij.openapi.vcs.VcsNotifier
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager
import com.intellij.vcsUtil.VcsUtil
class PijulAddToIgnore: DumbAwareAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT) ?: ProjectManager.getInstance().defaultProject
val fcd = FileChooserDescriptorFactory.createSingleFileDescriptor()
fcd.isShowFileSystemRoots = true
fcd.title = DraconBundle.Init.title
fcd.description = DraconBundle.Init.description
fcd.isHideIgnored = false
val baseDir = e.getData(CommonDataKeys.VIRTUAL_FILE)?.let { if (it.isDirectory) null else it } ?: project.baseDir
FileChooser.chooseFile(fcd, project, baseDir) { root ->
if (Pijul.isUnderPijul(root)) {
val dialog = Messages.showYesNoCancelDialog(
project,
DraconBundle.Init.alreadyUnderPijulForHtml(root.presentableUrl),
DraconBundle.Init.title,
Messages.getWarningIcon()
)
if (dialog != Messages.YES) {
return@chooseFile
}
}
object : Task.Backgroundable(project, DraconBundle.Dracon.refreshing) {
override fun run(indicator: ProgressIndicator) {
indicator.isIndeterminate = true
val init = pijul(project).init(project, root)
if (init.statusCode is NonZeroExitStatusCode) {
VcsNotifier
.getInstance(this.project)
.notifyError(
NotificationIds.FAILED_TO_INIT,
DraconBundle.Init.error,
init.statusCode.message.wrapInHml(),
true
)
}
if (project.isDefault) {
return
}
// Refresh VCS?
DraconVcsUtil.refreshAfterInit(project, root)
}
}.queue()
}
}
}
pijul(project).add(project, vcsRoot, paths)
val trackedFiles = pijul(project).trackedFiles(project, Paths.get(VcsUtil.getFilePath(vcsRoot).path))
val add = pijul(project).add(project, vcsRoot, paths)
if (add.statusCode is SuccessStatusCode) {
val pathsAsNio = paths.map {
Paths.get(it.path).toAbsolutePath()
}.filter { trackedFiles.result == null || !trackedFiles.result.contains(it) }
project.service<FileStatusCache>()
.updateCacheForPaths(pathsAsNio) {
FileStatus.ADDED.toPijul()
}
}
- Does not support amend.
- Record text file opens in default editor instead of IntelliJ Editor.
- [ ] Support amend.
- ~~Record text file opens in default editor instead of IntelliJ Editor.~~
- [X] Record text is opened in IntelliJ IDEA powered by [editor-server](https://crates.io/crates/editor-server) backend.
- [X] File history support
- [X] Allows users to compare between revisions
- [X] Allows users to see affected files for any given revision.
Dracon is in a heavily experimental state, and it depends on latest IDEA EAP build. First download an **experimental** or **nightly** build from [builds](https://nest.pijul.com/Jonathan/Dracon:main/MJDBCNFHSHAR4.BEAAA) directory (probably you will need to clone this repo to get the zip file), then go to IntelliJ IDEA Plugins section and click in the gear on the right side of *Installed tab* and select *Install plugin from Disk...* and select the downloaded Dracon *.zip*. Now you're ready to go.
The easiest way is to pick an officially packaged version of Dracon which we periodically publish.
First download an **experimental** or **nightly** build from [builds](https://nest.pijul.com/Jonathan/Dracon:main/MJDBCNFHSHAR4.BEAAA) directory (probably you will need to clone this repo to get the zip file), then go to IntelliJ IDEA Plugins section and click in the gear on the right side of *Installed tab* and select *Install plugin from Disk...* and select the downloaded Dracon *.zip*. Now you're ready to go.
For Unix:
```bash
./gradlew buildPlugin
```
For Windows:
```batch
.\gradlew.bat buildPlugin
```
The generated plugin file could be find in `build/distributions` path, the installation of the plugin `.zip` is exactly the same as for an officially made build: Go to IntelliJ IDEA Plugins section and click in the gear on the right side of *Installed* tab and select *Install plugin from Disk...* and select the generated Dracon *.zip*.
### JetBrains Marketplace
Recently versions of Dracon requires [editor-server](https://crates.io/crates/editor-server) to be installed in order to work, the final
release version will come bundled with the [editor-server](https://crates.io/crates/editor-server).
### Dependencies
Recently versions of Dracon requires [editor-server](https://crates.io/crates/editor-server) to be installed in order to work, ~~the final
release version will come bundled with the [editor-server](https://crates.io/crates/editor-server).~~ The most recent version of Dracon does prompts for Pijul and Editor-Server download, as this requires Cargo in order to install dependencies if it is not installed, Dracon will prompt for Rustup and Cargo installation, it does the baby steps for installation, but you take the lead as soon as choices need to be made.
## File Changes Loading Overhead
Pijul does not have an easy way to retrieve the state of a file in a given revision, in order to support this, Dracon creates a copy of the repository in a temporary directory and execute `pijul unrecord` against all revisions that happened after the given revision.
For CoW based file systems, such as ZFS and Btrfs, this operation is very cheap, and as long as all the files are not modified when **pijul unrecord** changes, this overhead may not be perceptible. However, there are some cases when this overhead becomes very perceptible, for example, when the amount of revisions between the target revision (the revision who you want to see), and the current revision (the last recorded revision), are bigger.
So, how much bigger is bigger enough to be perceptible? I'm not sure, I don't have enough samples to conclude the exact amount of changes that are needed in order to this operation overhead be perceptible, it also depends on the complexity of the entire operation, how many files changed between these revisions, the complexity of these changes, the performance of the secondary storage (Read/Write). I've been tested Dracon and made a bunch of performance improvements, such as caching, which improved the overall performance of revision loading and project loading.
~~An NVMe SSD and a CoW file system alleviate this a bit, however I'm always working in strategies to improve the performance, however when Pijul provides a way to see the state of a file in a given revision, I will use it instead of the actual routine.~~
In the most current versions, Dracon does a bunch of caching and preloads file revisions, also caching code has been the focus of the development now that Dracon is almost ready for a nightly release. However, there is room for improvements.
~~Also, I'm currently improving the rollback algorithm to *unrecord* only revision which actually change the file, instead of all revisions between the actual revision (inclusively) and the target revision (exclusively) by looking at `pijul credit`~~
Plans have changed, instead of only un-recording changes that `pijul credit` annotated, Dracon save the state of other files of a given revision, speeding things a bit and reducing the amount of `pijul unrecord` we execute (currently only for the caching).