Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8141d1
import latest java converted to kotlin
nbransby Oct 26, 2021
5845925
Added fix for version
Reedyuk Oct 29, 2021
37177b2
Added missing bracket
Reedyuk Oct 29, 2021
ba9c029
adjusted workflow to publish
Reedyuk Oct 29, 2021
9aa9e95
added semantic version
Reedyuk Oct 29, 2021
8061ce1
added semantic version
Reedyuk Oct 29, 2021
c62ab2d
disabled signing
Reedyuk Oct 29, 2021
3168994
Added string replace for gitliveapp
Reedyuk Oct 29, 2021
f027b71
Add UnifiedDiffReader.kt and actuals
michaelprichardson Dec 8, 2021
000129d
Add tests
michaelprichardson Dec 8, 2021
3b59325
Add BiConsumer
michaelprichardson Dec 8, 2021
1ec375a
Add test files
michaelprichardson Dec 8, 2021
349bdae
Comment out ios targets
michaelprichardson Dec 8, 2021
1de1ec9
Add reader expects
michaelprichardson Dec 8, 2021
7300438
Change from Reader to suspend function, add coroutines
michaelprichardson Dec 14, 2021
766af91
Remove Reader
michaelprichardson Dec 14, 2021
de55958
Extract coroutines version number
michaelprichardson Dec 15, 2021
6ce39c9
Fix expects and actuals
michaelprichardson Dec 15, 2021
0e0912d
Move UnifiedDiffReader into sub folder
michaelprichardson Dec 15, 2021
efbfa8b
Add new test libraries
michaelprichardson Dec 17, 2021
911b629
Fix tests to test suspending function
michaelprichardson Dec 17, 2021
2c30906
Fix tail for optional string
michaelprichardson Dec 17, 2021
d64bbe0
Add temp hack to respect new line
michaelprichardson Dec 17, 2021
9f0245e
Add another hack for new lines
michaelprichardson Dec 20, 2021
dfd86af
Add additions and deletions
michaelprichardson Dec 21, 2021
b9f3600
simplify expect/actual implementation
nbransby Jan 13, 2022
21c9e3e
add check for binary file changed and return null for /dev/null
michaelprichardson Jan 20, 2022
617e37e
remove redundant stdlib-commo import
michaelprichardson Jan 20, 2022
07672a2
update to 1.6.10
michaelprichardson Feb 25, 2022
e86a3a9
Merge pull request #20 from GitLiveApp/1.6.10
nbransby Mar 1, 2022
880ffb3
update to 1.5.32
michaelprichardson Mar 18, 2022
dcfdb6b
Merge pull request #21 from GitLiveApp/1.5.32
nbransby Mar 19, 2022
6382af7
use both js compilers and update version
michaelprichardson Mar 29, 2022
3c444ad
Merge pull request #22 from GitLiveApp/use-both-js-compilers
nbransby Mar 29, 2022
d960355
Merge branch 'update_1.3_version_to_latest_java_diff_utils' into add-…
michaelprichardson Mar 30, 2022
a1dcdfd
fix corountines dependency
nbransby Mar 30, 2022
074eb5b
Merge pull request #19 from GitLiveApp/add-unified-diff-reader
nbransby Mar 30, 2022
8d47bcd
Merge branch 'master' into update_1.3_version_to_latest_java_diff_utils
michaelprichardson Mar 30, 2022
2cd10ba
remove duplicate prepareForGithubNpmPublish
michaelprichardson Mar 30, 2022
93cf96d
only build on pr
michaelprichardson Mar 30, 2022
d8877a0
fix tests
nbransby Mar 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Pull Request

on:
pull_request:
branches: [ master ]
on: pull_request

jobs:
build:
Expand All @@ -29,8 +27,7 @@ jobs:
- name: Change package version
uses: eskatos/gradle-command-action@v1
with:
arguments: :updateVersion

arguments: updateVersion
- name: Build
uses: eskatos/gradle-command-action@v1
with:
Expand All @@ -56,7 +53,11 @@ jobs:
run: npm config set //npm.pkg.github.com/:_authToken=$token
env:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup package name
uses: eskatos/gradle-command-action@v1
with:
arguments: prepareForGithubNpmPublish
- name: Publish npm
uses: eskatos/gradle-command-action@v1
with:
arguments: prepareForGithubNpmPublish publishToNpm
arguments: publishToNpm
33 changes: 25 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ version = project.property("version") as String
plugins {
`maven-publish`
signing
kotlin("native.cocoapods") version "1.5.30"
kotlin("multiplatform") version "1.5.30"
kotlin("multiplatform") version "1.5.32"
kotlin("native.cocoapods") version "1.5.32"
}

repositories {
Expand All @@ -19,7 +19,9 @@ repositories {
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions {
jvmTarget = "1.8"
}
}
testRuns["test"].executionTask.configure { useJUnit() }
}
Expand All @@ -36,24 +38,38 @@ kotlin {
}
}

iosArm64()
iosX64()
// iosArm64()
// iosX64()

sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jsMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${project.property("kotlinx-coroutines.version")}")
}
}
val jsMain by getting

val jvmMain by getting {
dependencies {
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.12")
implementation("org.assertj:assertj-core:3.11.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${project.property("kotlinx-coroutines.version")}")
}
}
}
Expand Down Expand Up @@ -100,7 +116,8 @@ tasks {
}

val updateVersion by registering(Exec::class) {
commandLine("npm", "--allow-same-version", "--no-git-tag-version", "--prefix", projectDir, "version", "${project.property("version")}")
commandLine("npm", "--allow-same-version", "--no-git-tag-version", "--prefix", projectDir, "version",
(project.property("version") as String).replace("""[_;\",\[\]]""".toRegex(), ""))
}

val prepareForGithubNpmPublish by registering(Copy::class) {
Expand All @@ -117,7 +134,7 @@ val javadocJar by tasks.creating(Jar::class) {
archiveClassifier.value("javadoc")
}

var shouldSign = true
var shouldSign = false

tasks.withType<Sign>().configureEach {
onlyIf { shouldSign }
Expand Down
9 changes: 6 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
version=4.11.4
kotlin_version = 1.5.32
kotlinx-coroutines.version=1.5.2

kotlin.code.style=official
kotlin_version=1.5.30
kotlin.incremental.multiplatform=true
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
version=5.1.4
kotlin.js.compiler=both
kotlin.js.compiler=both
2 changes: 1 addition & 1 deletion kotlin_diff_utils.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'kotlin_diff_utils'
spec.version = '5.1.4'
spec.version = '4.11.3-kotlin1.5.32'
spec.homepage = ''
spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }
spec.authors = ''
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "kotlin-diff-utils-js-legacy",
"name": "@gitliveapp/kotlin-diff-utils",
"version": "0",
"description": "The DiffUtils library for computing diffs, applying patches, generating side-by-side view in Java.",
"main": "kotlin-diff-utils-js-legacy.js",
Expand All @@ -11,7 +11,7 @@
"url": "git+https://github.com/GitLiveApp/kotlin-diff-utils"
},
"publishConfig": {
"registry":"https://registry.npmjs.org/"
"registry": "https://npm.pkg.github.com/"
},
"keywords": [
"diffs",
Expand Down
149 changes: 99 additions & 50 deletions src/commonMain/kotlin/dev/gitlive/difflib/DiffUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,124 +15,172 @@
*/
package dev.gitlive.difflib

import dev.gitlive.difflib.algorithm.DiffAlgorithmFactory
import dev.gitlive.difflib.algorithm.DiffAlgorithmI
import dev.gitlive.difflib.algorithm.DiffAlgorithmListener
import dev.gitlive.difflib.algorithm.DiffException
import dev.gitlive.difflib.algorithm.myers.MyersDiff
import dev.gitlive.difflib.patch.AbstractDelta
import dev.gitlive.difflib.algorithm.myers.MeyersDiff
import dev.gitlive.difflib.patch.Patch
import dev.gitlive.difflib.patch.PatchFailedException

internal typealias Predicate<T> = (T) -> Boolean
internal typealias BiPredicate<T,R> = (T, R) -> Boolean
internal typealias BiPredicate<T, R> = (T, R) -> Boolean
internal typealias Consumer<T> = (T) -> Unit
internal typealias Function<T,R> = (T) -> R
internal typealias Function<T, R> = (T) -> R
internal typealias BiFunction<T, T2, R> = (T, T2) -> R
internal typealias BiConsumer<T, U> = (T, U) -> Unit
internal typealias LineReader = suspend () -> String?

/**
* Implements the difference and patching engine
*
* @author [Dmitry Naumenko](dm.naumenko@gmail.com)
*/
object DiffUtils {
/**
* This factory generates the DEFAULT_DIFF algorithm for all these routines.
*/
var DEFAULT_DIFF: DiffAlgorithmFactory = MeyersDiff.Companion.factory()
@kotlin.jvm.JvmStatic
fun withDefaultDiffAlgorithmFactory(factory: DiffAlgorithmFactory) {
DEFAULT_DIFF = factory
}

/**
* Computes the difference between the original and revised list of elements with default diff algorithm
* Computes the difference between the original and revised list of elements
* with default diff algorithm
*
* @param <T> types to be diffed
* @param original The original text. Must not be `null`.
* @param revised The revised text. Must not be `null`.
* @param progress progress listener
* @return The patch describing the difference between the original and revised sequences. Never `null`.
* @throws dev.gitlive.difflib.algorithm.DiffException
*/
// @Throws(DiffException::class)
fun <T> diff(original: List<T>, revised: List<T>, progress: DiffAlgorithmListener): Patch<T> {
return diff(original, revised, MyersDiff(), progress)
* @return The patch describing the difference between the original and
* revised sequences. Never `null`.
</T> */
fun <T> diff(original: List<T>, revised: List<T>, progress: DiffAlgorithmListener?): Patch<T> {
return diff<T>(original, revised, DEFAULT_DIFF.create(), progress)
}

// @Throws(DiffException::class)
fun <T> diff(original: List<T>, revised: List<T>): Patch<T> {
return diff(original, revised, MyersDiff(), null)
return diff<T>(original, revised, DEFAULT_DIFF.create(), null)
}

fun <T> diff(original: List<T>, revised: List<T>, includeEqualParts: Boolean): Patch<T> {
return diff<T>(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts)
}

/**
* Computes the difference between the original and revised text.
*/
// @Throws(DiffException::class)
fun diff(sourceText: String, targetText: String,
progress: DiffAlgorithmListener): Patch<String> {
return diff(sourceText.lines(), targetText.lines(), progress)
fun diff(
sourceText: String, targetText: String,
progress: DiffAlgorithmListener?
): Patch<String> {
return diff(sourceText.trimEnd('\n').lines(), targetText.trimEnd('\n').lines(), progress)
}

/**
* Computes the difference between the original and revised list of elements with default diff algorithm
* Computes the difference between the original and revised list of elements
* with default diff algorithm
*
* @param source The original text. Must not be `null`.
* @param target The revised text. Must not be `null`.
*
* @param equalizer the equalizer object to replace the default compare algorithm (Object.equals). If `null`
* the default equalizer of the default algorithm is used..
* @return The patch describing the difference between the original and revised sequences. Never `null`.
* @param equalizer the equalizer object to replace the default compare
* algorithm (Object.equals). If `null` the default equalizer of the
* default algorithm is used..
* @return The patch describing the difference between the original and
* revised sequences. Never `null`.
*/
// @Throws(DiffException::class)
fun <T> diff(source: List<T>, target: List<T>,
equalizer: BiPredicate<T, T>?): Patch<T> {
fun <T> diff(
source: List<T>, target: List<T>,
equalizer: BiPredicate<T, T>?
): Patch<T> {
return if (equalizer != null) {
diff(
source, target,
DEFAULT_DIFF.create(equalizer)
)
} else diff(source, target, MeyersDiff())
}

fun <T> diff(
source: List<T>, target: List<T>,
includeEqualParts: Boolean,
equalizer: BiPredicate<T, T>?
): Patch<T> {
return if (equalizer != null) {
diff(source, target,
MyersDiff(equalizer))
} else diff(source, target, MyersDiff())
diff(source, target, DEFAULT_DIFF.create(equalizer), null, includeEqualParts)
} else diff(source, target, MeyersDiff())
}

fun <T> diff(
original: List<T>, revised: List<T>,
algorithm: DiffAlgorithmI<T>, progress: DiffAlgorithmListener?
): Patch<T> {
return diff(original, revised, algorithm, progress, false)
}

/**
* Computes the difference between the original and revised list of elements with default diff algorithm
* Computes the difference between the original and revised list of elements
* with default diff algorithm
*
* @param original The original text. Must not be `null`.
* @param revised The revised text. Must not be `null`.
* @param algorithm The diff algorithm. Must not be `null`.
* @param progress The diff algorithm listener.
* @return The patch describing the difference between the original and revised sequences. Never `null`.
* @param includeEqualParts Include equal data parts into the patch.
* @return The patch describing the difference between the original and
* revised sequences. Never `null`.
*/
// @Throws(DiffException::class)
fun <T> diff(original: List<T>, revised: List<T>,
algorithm: DiffAlgorithmI<T>, progress: DiffAlgorithmListener?): Patch<T> {
return Patch.generate(original, revised, algorithm.computeDiff(original, revised, progress))
fun <T> diff(
original: List<T>, revised: List<T>,
algorithm: DiffAlgorithmI<T>, progress: DiffAlgorithmListener?,
includeEqualParts: Boolean
): Patch<T> {
return Patch.Companion.generate<T>(
original,
revised,
algorithm.computeDiff(original, revised, progress),
includeEqualParts
)
}

/**
* Computes the difference between the original and revised list of elements with default diff algorithm
* Computes the difference between the original and revised list of elements
* with default diff algorithm
*
* @param original The original text. Must not be `null`.
* @param revised The revised text. Must not be `null`.
* @param algorithm The diff algorithm. Must not be `null`.
* @return The patch describing the difference between the original and revised sequences. Never `null`.
* @return The patch describing the difference between the original and
* revised sequences. Never `null`.
*/
// @Throws(DiffException::class)
fun <T> diff(original: List<T>, revised: List<T>,
algorithm: DiffAlgorithmI<T>): Patch<T> {
@kotlin.jvm.JvmStatic
fun <T> diff(original: List<T>, revised: List<T>, algorithm: DiffAlgorithmI<T>): Patch<T> {
return diff(original, revised, algorithm, null)
}

/**
* Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of
* characters, like DiffRowGenerator does and merges those changes at the end together again.
* Computes the difference between the given texts inline. This one uses the
* "trick" to make out of texts lists of characters, like DiffRowGenerator
* does and merges those changes at the end together again.
*
* @param original
* @param revised
* @return
*/
// @Throws(DiffException::class)
@kotlin.jvm.JvmStatic
fun diffInline(original: String, revised: String): Patch<String> {
val origList = ArrayList<String>()
val revList = ArrayList<String>()
val origList: MutableList<String> = ArrayList()
val revList: MutableList<String> = ArrayList()
for (character in original) {
origList.add(character.toString())
}
for (character in revised) {
revList.add(character.toString())
}
val patch = diff(origList, revList)
val patch: Patch<String> = diff(origList, revList)
for (delta in patch.getDeltas()) {
delta.source.lines = compressLines(delta.source.lines!!, "")
delta.target.lines = compressLines(delta.target.lines!!, "")
delta.source.lines = compressLines(delta.source.lines, "")
delta.target.lines = compressLines(delta.target.lines, "")
}
return patch
}
Expand All @@ -151,6 +199,7 @@ object DiffUtils {
* @return the revised text
* @throws PatchFailedException if can't apply patch
*/
@kotlin.jvm.JvmStatic
// @Throws(PatchFailedException::class)
fun <T> patch(original: List<T>, patch: Patch<T>): List<T> {
return patch.applyTo(original)
Expand All @@ -166,4 +215,4 @@ object DiffUtils {
fun <T> unpatch(revised: List<T>, patch: Patch<T>): List<T> {
return patch.restore(revised)
}
}
}
Loading