5 Commits

Author SHA1 Message Date
11e0b03904 Parse version from tag
All checks were successful
Test Workflow / Lint and test library (pull_request) Successful in 7m41s
2023-12-02 00:47:01 +00:00
c9a19c929d Commit publish workflow
All checks were successful
Test Workflow / Lint and test library (pull_request) Successful in 8m31s
Publish Workflow / Publish library (pull_request) Successful in 8m34s
2023-12-02 00:18:21 +00:00
da23105fe3 Change trigger for testing
All checks were successful
Test Workflow / Lint and test library (pull_request) Successful in 7m55s
2023-12-02 00:14:01 +00:00
cc64e21615 Cleanup workflows, fix deploy token
All checks were successful
Main Workflow / Lint and test library (pull_request) Successful in 8m9s
2023-12-02 00:12:09 +00:00
e84ea41dd7 Initial publish
Some checks failed
Main Workflow / Lint and test library (pull_request) Successful in 8m10s
Main Workflow / Publish package (pull_request) Failing after 9m8s
2023-12-01 23:17:03 +00:00
4 changed files with 13 additions and 34 deletions

View File

@@ -1,7 +1,6 @@
plugins {
kotlin("jvm") version "1.9.21"
id("org.jmailen.kotlinter") version "4.1.0"
id("org.jetbrains.dokka") version "1.9.10"
`maven-publish`
}
@@ -24,18 +23,10 @@ kotlin {
jvmToolchain(17)
}
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
publishing {
publications.register<MavenPublication>("gpr") {
artifactId = "tinyvm"
from(components["java"])
artifact(javadocJar)
pom {
name.set("TeamCity support for Gitea - Test Task - tiny version manager")
description.set("This is a small project to implement a subset of git's functionality in Kotlin and was " +

View File

@@ -2,36 +2,28 @@ package tinyvm
import java.security.MessageDigest
import java.time.Instant
import java.util.HexFormat
/**
* Represents an arbitrary version manager object.
*/
abstract class Object(val type: String) {
abstract class Object(
val type: String,
) {
abstract val data: String
fun hash(): String =
HexFormat.of().formatHex(
MessageDigest
.getInstance("SHA-1")
.digest("$type ${data.length}\u0000$data".toByteArray()),
)
MessageDigest
.getInstance("SHA-1")
.digest("$type ${data.length}\u0000$data".toByteArray())
.toHex()
}
/**
* Commits are a pointer to a 'head' tree with some metadata.
*/
class Commit(
val tree: Tree,
val author: Author,
val message: String,
val timestamp: Instant,
) : Object("commit") {
// Use \n\n for end of header in-case additional metadata is implemented in the future.
override val data: String
// Use \n\n for end of header in-case additional metadata is implemented in the future.
get() = "tree ${tree.hash()}\nauthor $author\ntimestamp ${timestamp.epochSecond}\n\n$message"
override fun toString(): String = "commit ${hash()}\n$data"
}
data class Author(

View File

@@ -0,0 +1,5 @@
package tinyvm
import java.util.HexFormat
fun ByteArray.toHex(): String = HexFormat.of().formatHex(this)

View File

@@ -1,13 +1,7 @@
package tinyvm
/**
* Tree nodes are either trees or blobs, represented by this sealed class.
*/
sealed class Node(type: String) : Object(type)
/**
* A tree is a set of named nodes.
*/
class Tree(val nodes: Map<String, Node>) : Node("tree") {
// For simplicity just use the hex-formatted hash, not the actual value like git does.
override val data: String
@@ -17,7 +11,4 @@ class Tree(val nodes: Map<String, Node>) : Node("tree") {
}.sorted().joinToString()
}
/**
* A blob is a data container.
*/
class Blob(override val data: String) : Node("blob")