IntelliJ Plugin for integration with Pijul
message = 'Initial CahngeProvider'
timestamp = '2021-03-29T01:50:38.537749028Z'

[[authors]]
name = 'Jonathan H. R. Lopes'

# Dependencies
[2] PGNTR2EPCZBOWI67LKY6AN5B3RGIEOQ6NTTXGODLESKDSPWV26KQC
[3]+FNNW5IEAXQ43WKB6QSQB7DFLG3Y3T5FYPXIUX7KQ2URR2GU3QLTAC
[4]+OPFG6CZ26PPTGTH7ULLRQGZGR3YEIEJOV5W2E3WN7PFRZS62CVLQC
[5]+GGYFPXND4VBCROZZXTKAP7Y4JOP2OOYQAFVLMUE7SLFM225EUSIAC
[*] NTRPUMVQHUIQZ6O72NJ72XFYTZWZOSDA6CSKMUCGKFVNE3KIDYYQC

# Hunks

1. File addition: "revision" in "src/main/kotlin/com/github/jonathanxd/dracon" +dx
  up 3.107, new 0:10

2. File addition: "PijulRevisionNumber.kt" in "src/main/kotlin/com/github/jonathanxd/dracon/revision"
  up 0.11, new 12:36
+ package com.github.jonathanxd.dracon.revision
+ 
+ import com.intellij.openapi.vcs.changes.patch.BlobIndexUtil
+ import com.intellij.openapi.vcs.history.ShortVcsRevisionNumber
+ import com.intellij.openapi.vcs.history.VcsRevisionNumber
+ import java.time.LocalDateTime
+ import java.time.ZonedDateTime
+ 
+ class PijulRevisionNumber(val hash: String, val timestamp: ZonedDateTime) : ShortVcsRevisionNumber {
+ 
+     val NOT_COMMITTED_HASH = BlobIndexUtil.NOT_COMMITTED_HASH
+ 
+     override fun compareTo(other: VcsRevisionNumber): Int {
+         if (this === other) return 0
+ 
+         if (other is PijulRevisionNumber) {
+             return this.timestamp.compareTo(other.timestamp)
+         }
+ 
+         return -1
+     }
+ 
+     override fun asString(): String = this.hash
+ 
+     override fun toShortString(): String = this.asString()
+ }
\

3. File addition: "provider" in "src/main/kotlin/com/github/jonathanxd/dracon" +dx
  up 3.107, new 843:853

4. File addition: "PijulChangeProvider.kt" in "src/main/kotlin/com/github/jonathanxd/dracon/provider"
  up 0.854, new 855:879
+ package com.github.jonathanxd.dracon.provider
+ 
+ import com.intellij.openapi.progress.ProgressIndicator
+ import com.intellij.openapi.project.Project
+ import com.intellij.openapi.vcs.VcsKey
+ import com.intellij.openapi.vcs.changes.*
+ 
+ class PijulChangeProvider(val project: Project, val key: VcsKey) : ChangeProvider {
+     override fun getChanges(
+         dirtyScope: VcsDirtyScope,
+         builder: ChangelistBuilder,
+         progress: ProgressIndicator,
+         addGate: ChangeListManagerGate
+     ) {
+         if (project.isDisposed) return
+         val dirtDirs = dirtyScope.recursivelyDirtyDirectories
+ 
+         println(dirtDirs)
+     }
+ 
+     override fun isModifiedDocumentTrackingRequired(): Boolean = true
+ }
\

5. Edit in src/main/kotlin/com/github/jonathanxd/dracon/pijul/Pijul.kt:13 3.4428
  up 3.4473, new 1584:1698, down 3.4473
+ import com.github.jonathanxd.dracon.log.PijulLog
+ import com.github.jonathanxd.dracon.revision.PijulRevisionNumber

6. Edit in src/main/kotlin/com/github/jonathanxd/dracon/pijul/Pijul.kt:82 3.4428
  up 3.6839, new 1699:1950, down 3.6839
+     @RequiresBackgroundThread
+     fun latestRevisionNumber(project: Project, root: VirtualFile): PijulOperationResult<PijulRevisionNumber>
+ 
+     @RequiresBackgroundThread
+     fun log(project: Project, root: VirtualFile): PijulOperationResult<PijulLog>

7. File addition: "PijulLog.kt" in "src/main/kotlin/com/github/jonathanxd/dracon/log"
  up 3.6847, new 1951:1964
+ package com.github.jonathanxd.dracon.log
+ 
+ import java.time.LocalDateTime
+ import java.time.ZonedDateTime
+ import java.time.format.DateTimeFormatter
+ import java.time.format.ResolverStyle
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ class Author(val name: String?, val fullName: String?, val email: String?)
+ class PijulLog(val entries: List<PijulLogEntry>)
+ 
+ class PijulLogEntry(
+     val changeHash: String,
+                     val message: String,
+                     val date: ZonedDateTime,
+                     val authors: List<Author>
+ )
+ 
+ 
+ val MESSAGE_PATTERN = Regex("message = '(.*)'\\n")
+ val TIME_PATTERN = Regex("timestamp = '(.*)'\\n")
+ val AUTHORS_SECTION_PATTERN = Regex("\\[\\[authors\\]\\]\n")
+ val AUTHOR_PATTERN = Regex("name = '(.*)'\\n")
+ 
+ fun String.parseChange(hash: String): PijulLogEntry {
+     val message = MESSAGE_PATTERN.find(this)?.groupValues?.get(1)!!
+     val timestamp = TIME_PATTERN.find(this)?.groupValues?.get(1)!!
+     val authorsSection = AUTHORS_SECTION_PATTERN.find(this)?.range?.endInclusive
+     val authors = mutableListOf<Author>()
+ 
+     if (authorsSection != null) {
+ 
+         var lastFound: Int? = authorsSection
+         while (lastFound != null) {
+             val foundAuthor = AUTHOR_PATTERN.find(this, lastFound)
+             val foundAuthorGroup = foundAuthor?.groupValues?.get(1)
+ 
+             if (foundAuthorGroup != null) {
+                 authors += Author(foundAuthorGroup, null, null)
+                 lastFound = if (foundAuthor.range.last + 1 < this.length && this[foundAuthor.range.last + 1] == '\n') {
+                     null
+                 } else {
+                     foundAuthor.range.last
+                 }
+             } else {
+                 lastFound = null
+             }
+         }
+     }
+ 
+     return PijulLogEntry(hash, message, timestamp.parseAsLocalDateTime(), authors)
+ }
+ 
+ val RFC3339_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSSSSSSSS]XXX")
+     .withResolverStyle(ResolverStyle.LENIENT)
+ 
+ fun String.parseAsLocalDateTime(): ZonedDateTime {
+     return ZonedDateTime.parse(this, RFC3339_FORMATTER)
+ }
\

8. Edit in src/main/kotlin/com/github/jonathanxd/dracon/cmd/PijulCmd.kt:13 3.10972
  up 3.11015, new 4000:4103, down 3.11015
+ import com.github.jonathanxd.dracon.log.PijulLog
+ import com.github.jonathanxd.dracon.log.PijulLogEntry

9. Edit in src/main/kotlin/com/github/jonathanxd/dracon/cmd/PijulCmd.kt:16 3.10972
  up 3.11075, new 4104:4156, down 3.11075
+ import com.github.jonathanxd.dracon.log.parseChange

10. Edit in src/main/kotlin/com/github/jonathanxd/dracon/cmd/PijulCmd.kt:20 3.10972
  up 4.2779, new 4157:4222, down 3.11119
+ import com.github.jonathanxd.dracon.revision.PijulRevisionNumber

11. Edit in src/main/kotlin/com/github/jonathanxd/dracon/cmd/PijulCmd.kt:106 3.10972
  up 3.13610, new 4223:4490, down 3.13610
+ 
+     override fun log(project: Project, root: VirtualFile): PijulOperationResult<PijulLog> {
+         val rootPath = Paths.get(VcsUtil.getFilePath(root).path)
+ 
+         val logHashExecution = this.execPijul(project, rootPath, listOf("log", "--hash-only"), delay = 10L)

12. Edit in src/main/kotlin/com/github/jonathanxd/dracon/cmd/PijulCmd.kt:112 3.10972
  up 3.13611, new 4491:5952, down 3.13611
+         val hashes = this.doExecutionWithMapper("log--hash-only", logHashExecution) {
+             it.lines()
+         }
+ 
+         if (hashes.statusCode !is SuccessStatusCode) {
+             return hashes as PijulOperationResult<PijulLog>
+         } else {
+             val entries = mutableListOf<PijulLogEntry>()
+             for (hash in hashes.result!!) {
+                 val change = this.doExecutionWithMapper("change-$hash", this.execPijul(project, rootPath, listOf("change", hash), delay = 10L)) {
+                     it.parseChange(hash)
+                 }
+ 
+                 if (change.statusCode !is SuccessStatusCode) {
+                     return change as PijulOperationResult<PijulLog>
+                 }
+             }
+ 
+             return PijulOperationResult(hashes.operation, hashes.statusCode, PijulLog(entries))
+         }
+     }
+ 
+     override fun latestRevisionNumber(project: Project, root: VirtualFile): PijulOperationResult<PijulRevisionNumber> {
+         /*val root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(file)
+             ?: return PijulOperationResult("file_status", SuccessStatusCode, FileStatus.UNKNOWN)*/
+         val rootPath = Paths.get(VcsUtil.getFilePath(root).path)
+ 
+         val log = this.log(project, root)
+ 
+         return PijulOperationResult(log.operation, log.statusCode,
+             log.result?.entries?.firstOrNull()?.let {
+                 PijulRevisionNumber(it.changeHash, it.date)
+             }
+         )
+     }
+ 

13. Edit in src/main/kotlin/com/github/jonathanxd/dracon/PijulVcs.kt:14 3.24146
  up 3.24239, new 5953:6018, down 3.24239
+ import com.github.jonathanxd.dracon.provider.PijulChangeProvider

14. Edit in src/main/kotlin/com/github/jonathanxd/dracon/PijulVcs.kt:20 3.24146
  up 3.24475, new 6019:6074, down 3.24475
+ import com.intellij.openapi.vcs.changes.ChangeProvider

15. Edit in src/main/kotlin/com/github/jonathanxd/dracon/PijulVcs.kt:46 3.24146
  up 3.25153, new 6075:6178, down 3.25153
+     override fun getChangeProvider(): ChangeProvider =
+         PijulChangeProvider(this.project, KEY)
+ 

16. File addition: "dada.toml" in "/"
  up 1.0, new 6179:6190

17. Edit in build.gradle.kts:33 5.13712
  up 5.14803, new 6193:6231, down 5.14803
+     maven(url = "https://jitpack.io")

18. Edit in build.gradle.kts:36 5.13712
  up 5.14820, new 6232:6394, down 5.14820
+     implementation("org.tomlj:tomlj:1.0.0")
+     implementation("com.github.JonathanxD.JwIUtils:JwIUtils:4.17.0") {
+         exclude(group = "org.jetbrains")
+     }

19. Replacement in README.md:21 5.17946
B:BD 2.59651 -> 2.59651:59660/2
  up 2.59651, new 6395:8239
- - [ ] ...
+ - [ ] ...
+ 
+ 
+ # FAQ
+ 
+ ## Why Dracon and not Pijul for IDEA (or something like that)?
+ 
+ Because Dracon is not an official plugin, and I want to make sure that it is clear to anyone who uses this plugin. Dracon is an individual project being developed by [Jonathan H. R. Lopes](https://github.com/JonathanxD) which does not have any relation with Pijul creator. Also, Dracon uses MIT license, allowing to anyone, and that includes the Pijul creator, to contribute and create your own version of Dracon, if wish to.
+ 
+ ## Why Dracon is developed against IntelliJ EAP instead of a stable releases?
+ 
+ Dracon is being developed based in actual [HG4Idea](https://github.com/JetBrains/intellij-community/tree/master/plugins/hg4idea) and [Git4Idea](https://github.com/JetBrains/intellij-community/tree/master/plugins/git4idea) plugins, as well based in current code of [IntelliJ IDEA Community](https://github.com/JetBrains/intellij-community/), and is planned to be released by the end of first semester of 2021, when release time comes, the IntelliJ EAP will be already released as stable, also I don't want to support older releases of IntelliJ IDEA because this involves basing on deprecated code, and this is my first IDEA plugin, so the more I focus the present than the past, more I deliver in terms of better and stable features.
+ 
+ ## Could I contribute to Dracon development?
+ 
+ I'm currently focused on learning how IDEA Plugin platform works and how DVCS is implemented in IDEA, so until Dracon is officially released, I will not be accepting contributions, but Dracon is licensed under MIT, you are free to create your own version of Dracon and developing it on your own.
+ 
+ ## When Dracon will be official released?
+ 
+ I will be periodically releasing Dragon experimental builds, but Dracon stable release is planned by the end of first semester of 2021.
\