ZCRW57C5MSBXYGUMGQTZNHGHO4HGHFBICW53X5I2IMGP3H2CKWRQC
Q7FXTHVUPVAFMNY277C3NFJO3VXLZU5G6C6UYSD5QPURHSG3A7OQC
EAGIDXOLFTHZMZ77ZWAM7MVVUBBXJMZD7RZUNBHJPYRFGGKILGVAC
MTPTFTHGAOKQGRUDXC55AM6XJHZZZ5EF6FPVXKFVCUYVXJNEANYQC
GGYFPXND4VBCROZZXTKAP7Y4JOP2OOYQAFVLMUE7SLFM225EUSIAC
NTRPUMVQHUIQZ6O72NJ72XFYTZWZOSDA6CSKMUCGKFVNE3KIDYYQC
FNNW5IEAXQ43WKB6QSQB7DFLG3Y3T5FYPXIUX7KQ2URR2GU3QLTAC
OPFG6CZ26PPTGTH7ULLRQGZGR3YEIEJOV5W2E3WN7PFRZS62CVLQC
FRFFQV7VNYKGCA7ZAOSRPC2HHYTAIZ6AGGR7A5QEV6QPAQGFDYGAC
6CR2EFUN7JXFHCBTNX3WWOOP4WFOCFO6KSPEBN6V6J5HFZO2LHNQC
QXUEMZ3B2FUHFUC7ZZHJMH5FVWLEMEYXUMFA6JNXTJKIVZNMRIOAC
7L5LODGZ7AN4ZULDJZMLALD7PL6E57VZSNNSG67SFJARUJGCT47QC
record.author=&Author:
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>.
expert.mode.notification.failure=Failed to record changes with exit code <bold>{0}</bold> and message: <tt>{1}</tt>.
<!--
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.
-->
}
}
fun isIdeaRoot(virtualFile: VirtualFile): Boolean {
val root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(virtualFile)
if (root != null) {
return root == virtualFile || virtualFile.toNioPath().toAbsolutePath().toString().startsWith(
root.toNioPath().toAbsolutePath().resolve(".idea").toString()
)
} else {
return false
return Files.readString(tmpTarget.resolve(filePath))
val relativeToRoot = filePath.subpath(root.nameCount, filePath.nameCount)
try {
return Files.readString(tmpTarget.resolve(relativeToRoot))
} finally {
FileUtilRt.delete(tempDir)
}
branch: String?): this(project, vcsRoot, Paths.get(filePath.path).relativeTo(vcsRoot), revision, author_, message, branch)
branch: String?,
deleted: Boolean): this(project, vcsRoot, Paths.get(filePath.path).relativeTo(vcsRoot), revision, authors, message, branch, deleted)
override fun getAuthorEmail(): String? =
this.authors.map { it.email }.firstOrNull()
override fun getCommitterName(): String? = this.author
override fun getCommitterEmail(): String? = this.authorEmail
override fun getPath(): FilePath =
LocalFilePath(this.filePath, Files.isDirectory(this.filePath))
override fun getAuthorDate(): Date? = Date.from(this.revision.timestamp.toInstant())
override fun isDeleted(): Boolean = this.deleted
override fun compareTo(other: PijulVcsFileRevision): Int =
this.revision.timestamp.compareTo(other.revision.timestamp)
partner.acceptRevision(
PijulVcsFileRevision(
this.project,
root.toNioPath(),
path,
PijulRevisionNumber(it.changeHash, it.date),
it.authors.map { it.name }.firstOrNull(),
it.message,
currentChannel
it.hunks.filterIsInstance<HunkWithPath>().groupBy {
it.resolvePath(root.toNioPath())
}.forEach { path, hunks ->
val deleted = hunks.any { it is FileDelHunk }
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
)
val rootAbsolute = root!!.toNioPath().toAbsolutePath()
if (dir.path.startsWith(rootAbsolute.resolve(".pijul").toString()))
continue;
if (dir.path.startsWith(rootAbsolute.resolve(".idea").toString()))
continue;
if (!dir.path.startsWith(rootAbsolute.toString()))
continue;
if (!dir.path.startsWith(project.baseDir.toNioPath().toAbsolutePath().toString()))
continue;
}
}
override fun recordToString(
project: Project,
root: Path
): PijulOperationResult<String> {
val arguments = mutableListOf("record")
val uuid = UUID.randomUUID().toString()
val tempFile = createCopieTempFile(uuid)
val operation = this.createPainlessExecPijulWithCopieOperation(
this.project,
root,
tempFile,
CopieMode.TO,
arguments
)
return this.doExecutionWithMapperEvenFailed("record", operation) {
val data = Files.readString(tempFile, Charsets.UTF_8)
deleteCopieTempDir(uuid)
data
}
}
override fun recordFromString(project: Project, root: Path, record: String): PijulOperationResult<String> {
val arguments = mutableListOf("record")
val uuid = UUID.randomUUID().toString()
val tempFile = createCopieTempFile(uuid)
Files.writeString(tempFile, record, Charsets.UTF_8, StandardOpenOption.CREATE_NEW)
val operation = this.createPainlessExecPijulWithCopieOperation(
this.project,
root,
tempFile,
CopieMode.FROM,
arguments
)
return this.doExecutionWithMapper("record", operation) {
deleteCopieTempDir(uuid)
it
} else {
if (Files.isDirectory(filePath)) {
if (hunkPath == filePath) {
if (hunk is FileAddHunk) {
isAdd = true
}
shouldConsume = true
} else if (hunkPath.startsWith(filePath)) {
shouldConsume = true
}
} else {
if (hunkPath == filePath) {
if (hunk is FileAddHunk) {
isAdd = true
}
shouldConsume = true
}
}
}
}
fun <T> doExecutionWithMapperEvenFailed(name: String,
execution: PijulExecution,
regularStreamStringMapper: (String) -> T?): PijulOperationResult<T> {
val status = runBlocking(Dispatchers.IO) {
execution.status.first()
}
return if (status == 0) {
val std = runBlocking(Dispatchers.IO) {
execution.regularStream.toList().joinToString("\n")
}
PijulOperationResult(name, SuccessStatusCode, regularStreamStringMapper(std))
} else {
val error = runBlocking(Dispatchers.IO) {
execution.errorStream.toList().joinToString("\n")
}
PijulOperationResult(name, NonZeroExitStatusCode(status, error), regularStreamStringMapper(""))
dir: Path,
args: List<String>): PijulExecution {
dir: Path,
args: List<String>): PijulExecution {
val process = ProcessBuilder()
.command(listOf(this.findPijul()) + args)
.directory(dir.toFile())
.start()
val input = process.inputStream
val error = process.errorStream
return PijulExecution(
input.linesToFlow().onEach {
draconConsoleWriter(project).logCommand("pijul", args, it)
},
error.linesToFlow().onEach {
draconConsoleWriter(project).logCommandError("pijul", args, it)
},
flow {
process.onExit().await()
val exit = process.exitValue()
if (exit == 0) {
draconConsoleWriter(project).logCommand("pijul", args, "<Exit status> $exit")
} else {
draconConsoleWriter(project).logCommandError("pijul", args, "<Exit status> $exit")
}
emit(exit)
}.flowOn(Dispatchers.IO)
)
}
/**
* Creates a [PijulExecution] operation that could be executed at any time. This operation uses Kotlin Coroutines
* and can be executed immediately through [doExecution] or through [doExecutionWithMapper].
*
* This implementation does not requires a delay value to be provided, like [createExecPijulOperation] does, instead
* it uses the kotlin conversion from `CompletionStage` to `Coroutines` and awaits the process through [Process.onExit].
*
* [doExecution] and [doExecutionWithMapper] does execution by scheduling task to [Dispatchers.IO], instead of Main Thread,
* offloading the Process execution handling to a different scheduler. However, mapping operation of [doExecutionWithMapper]
* is not offloaded from the caller context.
*
*/
@RequiresBackgroundThread
private fun createPainlessExecPijulWithCopieOperation(project: Project,
dir: Path,
copiePath: Path,
copieMode: CopieMode,
args: List<String>): PijulExecution {
}
fun createCopieTempFile(hash: String): Path {
val tempDir = FileUtilRt.createTempDirectory("dracon_records-", hash).toPath()
return tempDir.resolve("record")
}
fun deleteCopieTempDir(hash: String) {
val tempDir = FileUtilRt.createTempDirectory("dracon_records-", hash).toPath()
FileUtilRt.delete(tempDir.toFile())
}
enum class CopieMode {
FROM,
TO
}
}
/**
* Returns whether [resolvedPath] is a directory inside [this] [Path].
*
* @param root The root path for [this] [Path] and [resolvedPath].
*/
fun Path.isInside(root: Path, resolvedPath: String) =
if (this == root) {
true
} else if (Files.isDirectory(this) && resolvedPath.startsWith(this.toString())) {
true
} else if (!Files.isDirectory(this)) {
this.toString().equals(resolvedPath, ignoreCase = true)
} else {
false
}
/**
* Returns whether [this] path is equal the [path].
*/
fun String.isEqual(path: Path) =
path.toString() == this
/**
* Returns whether [this] path is equal the [path].
*/
fun String.isPathEqual(path: String) =
this.removeTrailingSlash().equals(path.removeTrailingSlash(), ignoreCase = true)
fun String.removeTrailingSlash() =
if (this.length > 1 && this.endsWith("/")) this.substring(0, this.length - 1)
else this
/**
* Returns whether [this] path is inside the [path].
*/
fun String.isInside(path: Path) =
path.startsWith(this)