some more work on improving repo merging

This commit is contained in:
Jake Potrebic 2024-03-29 12:07:45 -07:00
parent 200f6efc46
commit 59e26185ee
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
8 changed files with 48 additions and 27 deletions

View file

@ -318,22 +318,10 @@ open class AllTasks(
sourcePatchDir.set(targetDir.dir(SOURCE_PATCHES))
}
val mmPatchSpigotServerPatches by tasks.registering<ApplyRawDiffPatches> {
group = "mm"
inputDir.set(extension.spigot.craftBukkitPatchDir)
patchDir.set(extension.paper.spigotServerPatchPatchesDir.fileExists(project))
doLast {
val target = layout.cacheDir(MM_PATCHED_SPIGOT_PATCHES)
target.asFile.toPath().deleteRecursive()
unzip(outputZip.get().asFile, target)
}
}
val remapSpigot by tasks.registering<RemapSpigot> {
dependsOn(mmPatchSpigotServerPatches)
remappedCraftBukkitSource.set(rebuildCraftBukkitPerFilePatches.flatMap { it.outputDir })
unmappedCraftBukkitSource.set(extension.craftBukkit.craftBukkitDir)
spigotPerCommitPatches.set(layout.cacheDir(MM_PATCHED_SPIGOT_PATCHES))
spigotPerCommitPatches.set(extension.spigot.craftBukkitPatchDir)
unmappedCbCopy.set(remapCraftBukkit.flatMap { it.unmappedCopy })
directoriesToPatch.set(listOf("src/main/java/net/minecraft", "src/main/java/com/mojang/brigadier"))
spigotDecompiledSource.set(spigotDecompilerMojmapRemap.flatMap { it.remappedOutputSources })

View file

@ -59,7 +59,7 @@ abstract class ApplyServerSourceAndNmsPatches : BaseTask() {
if (paperDecompiledSource.isPresent && Files.notExists(nmsFile)) {
nmsFile = paperDecompiledSource.file(fileName).get().path
}
val patchFile = patchDir.resolve(fileName).resolveSibling((patchedFile.nameWithoutExtension + ".patch"))
val patchFile = patchDir.resolve(fileName).resolveSibling((patchedFile.name + ".patch")) // keep extension
val commandText =
listOf<String>("diff", "-u", "--label", "a/$fileName", nmsFile.absolutePathString(), "--label", "b/$fileName", patchedFile.absolutePath)

View file

@ -67,7 +67,7 @@ abstract class RebuildPerFilePatches : BaseTask() {
private fun createPerFilePatch(patchedFile: Path, originalSource: DirectoryProperty, patchDir: Path) {
val fileName = patchedFile.absolutePathString().split("src/main/java/", limit = 2)[1]
val nmsFile = originalSource.file(fileName).path
val patchFile = patchDir.resolve(fileName).resolveSibling((patchedFile.nameWithoutExtension + ".patch"))
val patchFile = patchDir.resolve(fileName).resolveSibling((patchedFile.name + ".patch")) // keep extension
val commandText = listOf("diff", "-u", "--label", "a/$fileName", nmsFile.absolutePathString(), "--label", "b/$fileName", patchedFile.absolutePathString())
val processBuilder = ProcessBuilder(commandText)

View file

@ -46,12 +46,14 @@ abstract class RewritePartialPaperHistory : BaseTask() {
}
println("Commits to rewrite: ${commitsToRewrite.size}")
git("filter-repo", "--force", "--commit-callback", """
if ${commitsToRewrite.joinToString(" or ")}:
${RewriteCommits.COMMIT_MSG}
commit.author_name = b'Spigot'
commit.author_email = b'spigot@github.com'
${RewriteCommits.RESET_CALLBACK.lines().joinToString("\n") { " $it" }}""".trimIndent()).executeOut()
val callbackArg = """
${RewriteCommits.UTILS}
if ${commitsToRewrite.joinToString(" or ")}:
${RewriteCommits.COMMIT_MSG.lines().joinToString("\n") { " $it" }}
commit.author_name = b'Spigot'
commit.author_email = b'spigot@github.com'
${RewriteCommits.RESET_CALLBACK}""".trimIndent()
git("filter-repo", "--force", "--commit-callback", callbackArg).executeOut()
firstCommit = git("log", "--grep=Rename to PaperSpigot", "--format=%H").getText().trim()
println("Removing index and line number changes from patch diff")

View file

@ -58,7 +58,7 @@ abstract class SetupCraftBukkit : BaseTask() {
val patchedFile = targetDir.file(toRecreate).path
val fileName = patchedFile.absolutePathString().split("src/main/java/", limit = 2)[1]
val nmsFile = sourceForPatchRecreation.get().file(fileName).asFile
val patchFile = newPatchesDir.resolve(fileName).resolveSibling((patchedFile.nameWithoutExtension + ".patch"))
val patchFile = newPatchesDir.resolve(fileName).resolveSibling((patchedFile.name + ".patch")) // keep extension
val commandText =
listOf<String>("diff", "-u", "--label", "a/$fileName", nmsFile.absolutePath, "--label", "b/$fileName", patchedFile.absolutePathString())

View file

@ -32,10 +32,15 @@ abstract class FinalizePaperHistory : BaseTask() {
@TaskAction
fun run() {
Git.checkForGit()
Git(paperDir).let { git ->
val paperMojangApi = outputDir.path.resolve("Paper-MojangAPI/src/main/java")
paperMojangApi.copyRecursivelyTo(outputDir.path.resolve("paper-api/src/main/java"))
paperMojangApi.deleteRecursive()
git("add", "paper-api/src/main/java", "Paper-MojangAPI").execute()
git("commit", "--message", "Merge Paper-MojangAPI into Paper API", "--author=Automated <auto@mated.null>").execute()
val deletionsArr = deletions.get().toTypedArray()
if (deletionsArr.isNotEmpty()) {
Git(paperDir).let { git ->
val deletionsArr = deletions.get().toTypedArray()
if (deletionsArr.isNotEmpty()) {
git("rm", "-r", *deletionsArr).execute()
git("commit", "-m", "OWW! That fork is HARD!", "--author=Automated <auto@mated.null>").execute()
}

View file

@ -16,6 +16,19 @@ import org.gradle.kotlin.dsl.*
abstract class RewriteCommits : BaseTask() {
companion object {
const val UTILS = """
def insert_into_commit_msg(text):
msg_split = commit.message.decode("utf-8").split("\n")
idx = min([i for i,x in enumerate(msg_split) if x.find("Co-authored-by:") != -1 or x.find("By:") != -1 or x.find("Also-by:") != -1], default=None)
if idx is not None:
msg_split.insert(idx, text.decode("utf-8"))
commit.message = "\n".join(msg_split).encode("utf-8")
else:
commit.message = commit.message + b'\n' + text
def replace_in_commit_msg(match, replace):
commit.message = commit.message.decode("utf-8").replace(match, replace).encode("utf-8")
"""
const val RESET_CALLBACK = """
commit.committer_name = commit.author_name
commit.committer_email = commit.author_email
@ -23,9 +36,13 @@ abstract class RewriteCommits : BaseTask() {
"""
@Suppress("MemberVisibilityCanBePrivate")
const val COMMIT_MSG = "commit.message = commit.message + b'By: ' + commit.author_name + b' <' + commit.author_email + b'>'"
const val COMMIT_MSG = """
insert_into_commit_msg(b'By: ' + commit.author_name + b' <' + commit.author_email + b'>')
replace_in_commit_msg("Co-authored-by:", "Also-by:")
"""
const val CRAFTBUKKIT_CALLBACK = """
$UTILS
$COMMIT_MSG
commit.author_name = b'CraftBukkit/Spigot'
commit.author_email = b'craftbukkit.spigot@github.com'
@ -33,18 +50,28 @@ abstract class RewriteCommits : BaseTask() {
"""
const val BUKKIT_CALLBACK = """
$UTILS
$COMMIT_MSG
commit.author_name = b'Bukkit/Spigot'
commit.author_email = b'bukkit.spigot@github.com'
$RESET_CALLBACK
"""
private const val MOVE_BACK_CALLBACK = """
$UTILS
import time
date = commit.author_date.decode('utf-8').split(' ')
commit.author_date = f'{int(date[0]) - 500000000} {date[1]}'.encode('utf-8')
insert_into_commit_msg(b'Original-Date: ' + time.ctime(int(date[0])).encode("utf-8"))
"""
const val PAPER_CALLBACK = """
msg = commit.message.decode('utf-8')
author = commit.author_email.decode('utf-8')
if author == 'aikar@aikar.co' and (msg.startswith('[CI-SKIP] [Auto]') or msg.startswith('[Auto]')):
commit.author_name = b'Automated'
commit.author_email = b'auto@mated.null'
$MOVE_BACK_CALLBACK
$RESET_CALLBACK
"""
}

View file

@ -130,7 +130,6 @@ const val SPIGOT_DECOMPILED_JAR_SRC = "$MM/spigotDecompiledJar"
const val PATCHES_DIR = "patches"
const val SOURCE_PATCHES = "$PATCHES_DIR/sources"
const val DATA_PATCHES = "$PATCHES_DIR/resources"
const val MM_PATCHED_SPIGOT_PATCHES = "$MM/patchedSpigotPatches"
const val DOWNLOAD_SERVICE_NAME = "paperweightDownloadService"