Fork channel

Create a new channel as a copy of main.

Rename channel

Rename main to:

Delete channel

Delete main? This cannot be undone.

Patterns.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

object HunkEditPattern: Pattern<HunkEditPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. Edit in (\"(?<file>.*)(?:\":)+)(?<line>\\d+) (?<inode>\\d+\\.\\d+) (\"(?<encoding>[^\"]+)\")\\n?")
) {
    override val factory: (MatchResult) -> HunkEditPatternMatch = ::create
}

// Corner case: 120. File addition: "coroutine" in "src/main/kotlin/com/github/jonathanxd/dracon" +dx "binary"
object HunkAddPattern : Pattern<HunkAddPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. File addition: (\"(?<file>.*)(?:\" )+)in (\"(?<path>.*)(?:\" )+)(?<mode>[^ ]+)?( ?\"(?<encoding>[^\"]+)\")(?<meta> [^ ]+)?\\n?")
) {
    override val factory: (MatchResult) -> HunkAddPatternMatch = ::create
}

object HunkDelPattern : Pattern<HunkDelPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. File deletion: (\"(?<file>.*)(?:\" )+)(?<inode>\\d+\\.\\d+) (\"(?<encoding>[^\"]+)\")\\n?")
) {
    override val factory: (MatchResult) -> HunkDelPatternMatch = ::create
}

object HunkUnDelPattern : Pattern<HunkUnDelPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. File un-deletion: (\"(?<file>.*)(?:\" )+)(?<inode>\\d+\\.\\d+) (\"(?<encoding>[^\"]+)\")\\n?")
) {
    override val factory: (MatchResult) -> HunkUnDelPatternMatch = ::create
}

object HunkReplacementPattern : Pattern<HunkReplacementPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. Replacement in (\"(?<file>.*)(?:\":)+)(?<line>\\d+) (?<inode>\\d+\\.\\d+) (\"(?<encoding>[^\"]+)\")\\n?")
) {
    override val factory: (MatchResult) -> HunkReplacementPatternMatch = ::create
}

// Corner case: 9. Moved: "src/main/kotlin/com/github/jonathanxd/dracon/handler" "handler" +dx 7.107
object HunkMovedPattern : Pattern<HunkMovedPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. Moved: (\"(?<old>.*)(?:\" )+)(\"(?<new>.*)(?:\" )+)((?<mode>[^ ]+) )?(?<inode>\\d+\\.\\d+)([^ ]+ )?( \"(?<encoding>[^\"]+)\")?([^ ]+ )?(?<meta>.*)\\n?")
) {
    override val factory: (MatchResult) -> HunkMovedPatternMatch = ::create
}

object HunkNameConflictPattern : Pattern<HunkNameConflictPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. (?<type>Solving|Un-solving) a name conflict in (\"(?<file>.*)(?:\" )+)(?<inode>\\d+\\.\\d+): (?<deletedNames>.*)\\n?")
) {
    override val factory: (MatchResult) -> HunkNameConflictPatternMatch = ::create
}

object HunkOrderConflictPattern : Pattern<HunkOrderConflictPatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. (?<type>Solving|Un-solving) an order conflict in (\"(?<file>.*)(?:\":)+)(?<pos>\\d+)? (?<inode>\\d+\\.\\d+)\\n?")
) {
    override val factory: (MatchResult) -> HunkOrderConflictPatternMatch = ::create
}

object HunkZombiePattern : Pattern<HunkZombiePatternMatch>(
    Regex("(?<changeNumber>\\d+)\\. Resurrecting zombie lines in (\"(?<file>.*)(?:\":)+)(?<pos>\\d+) (?<inode>\\d+\\.\\d+)\\n?")
) {
    override val factory: (MatchResult) -> HunkZombiePatternMatch = ::create
}


class HunkEditPatternMatch(override val matchResult: MatchResult): EncodingHunkMatch {
    val file: String get() = matchResult.groups["file"]!!.value.let {
        if (it.startsWith("\"") && it.endsWith("\"")) it.substring(1, it.lastIndex)
        else it
    }

    val line: Int get() = matchResult.groups["line"]!!.value.toInt()
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
}

class HunkAddPatternMatch(override val matchResult: MatchResult): EncodingHunkMatch {
    val fileName: String get() = matchResult.groups["file"]!!.value
    val path: String get() = matchResult.groups["path"]!!.value
    val mode: String? get() = matchResult.groups["mode"]?.value
    val meta: String? get() = matchResult.groups["meta"]?.value
}

class HunkDelPatternMatch(override val matchResult: MatchResult): EncodingHunkMatch {
    val fileName: String get() = matchResult.groups["file"]!!.value
    val meta: String? get() = matchResult.groups["meta"]?.value
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
}

class HunkUnDelPatternMatch(override val matchResult: MatchResult): EncodingHunkMatch {
    val fileName: String get() = matchResult.groups["file"]!!.value
    val meta: String? get() = matchResult.groups["meta"]?.value
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
}

class HunkReplacementPatternMatch(override val matchResult: MatchResult): EncodingHunkMatch {
    val fileName: String get() = matchResult.groups["file"]!!.value
    val line: Int get() = matchResult.groups["line"]!!.value.toInt()
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
}

class HunkMovedPatternMatch(override val matchResult: MatchResult): HunkMatch {
    val old: String get() = matchResult.groups["old"]!!.value
    val new: String get() = matchResult.groups["new"]!!.value
    val mode: String? get() = matchResult.groups["mode"]?.value
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
    val meta: String? get() = matchResult.groups["meta"]?.value
}

class HunkNameConflictPatternMatch(override val matchResult: MatchResult): HunkMatch {
    val type: HunkType get() = when (matchResult.groups["type"]!!.value.lowercase()) {
        "solving" -> HunkType.SOLVING_NAME_CONFLICT
        "un-solving" -> HunkType.UN_SOLVING_NAME_CONFLICT
        else -> HunkType.UNKNOWN_NAME_CONFLICT_RESOLUTION
    }
    val fileName: String get() = matchResult.groups["file"]!!.value
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
    val deletedNames: List<String> get() = matchResult.groups["deletedNames"]!!.value.split(",")
}

class HunkOrderConflictPatternMatch(override val matchResult: MatchResult): HunkMatch {
    val type: HunkType get() = when (matchResult.groups["type"]!!.value.lowercase()) {
        "solving" -> HunkType.SOLVING_ORDER_CONFLICT
        "un-solving" -> HunkType.UN_SOLVING_ORDER_CONFLICT
        else -> HunkType.UNKNOWN_ORDER_CONFLICT_RESOLUTION
    }
    val fileName: String get() = matchResult.groups["file"]!!.value
    val pos: Int? get() = matchResult.groups["pos"]?.value?.toInt()
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
}

class HunkZombiePatternMatch(override val matchResult: MatchResult): HunkMatch {
    val fileName: String get() = matchResult.groups["file"]!!.value
    val pos: Int get() = matchResult.groups["pos"]!!.value.toInt()
    val inode: Double get() = matchResult.groups["inode"]!!.value.toDouble()
}

inline fun <reified T> create(result: MatchResult): T =
    T::class.constructors.first().call(result)