android: retain aggregated file patches
This commit is contained in:
@@ -98,6 +98,16 @@ internal fun parseUnifiedPatch(patch: String?): FileDiff {
|
|||||||
current?.let { hunks += it.build() }
|
current?.let { hunks += it.build() }
|
||||||
current = HunkBuilder(line, hunkStart.oldStart, hunkStart.oldCount, hunkStart.newStart, hunkStart.newCount)
|
current = HunkBuilder(line, hunkStart.oldStart, hunkStart.oldCount, hunkStart.newStart, hunkStart.newCount)
|
||||||
}
|
}
|
||||||
|
// An aggregated entry can contain one complete patch from each
|
||||||
|
// contributing stage. A new file header closes the preceding hunk
|
||||||
|
// instead of being rendered as an unnumbered context line in it.
|
||||||
|
line.startsWith("--- ") || line.startsWith("+++ ") -> {
|
||||||
|
current?.let {
|
||||||
|
hunks += it.build()
|
||||||
|
current = null
|
||||||
|
}
|
||||||
|
headers += line
|
||||||
|
}
|
||||||
current == null -> headers += line
|
current == null -> headers += line
|
||||||
else -> current.lines += parseBodyLine(line, current)
|
else -> current.lines += parseBodyLine(line, current)
|
||||||
}
|
}
|
||||||
@@ -305,7 +315,12 @@ internal fun runChanges(steps: List<RunStep>): RunChanges {
|
|||||||
(file.beforeMode != null && file.afterMode != null &&
|
(file.beforeMode != null && file.afterMode != null &&
|
||||||
file.beforeMode != file.afterMode && !file.binary && parsed.added == 0 && parsed.removed == 0),
|
file.beforeMode != file.afterMode && !file.binary && parsed.added == 0 && parsed.removed == 0),
|
||||||
steps = mergedSteps,
|
steps = mergedSteps,
|
||||||
patch = file.patch?.takeIf { it.isNotBlank() } ?: existing?.patch,
|
// Preserve every recorded textual patch for a path. A file may be
|
||||||
|
// changed by several stages, and retaining only the first one
|
||||||
|
// would make the displayed hunks disagree with the aggregate stat.
|
||||||
|
patch = listOfNotNull(existing?.patch, file.patch?.takeIf { it.isNotBlank() })
|
||||||
|
.joinToString("\n")
|
||||||
|
.takeIf { it.isNotBlank() },
|
||||||
)
|
)
|
||||||
entries[file.path] = entry
|
entries[file.path] = entry
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,29 @@ class RunChangesTest {
|
|||||||
assertEquals("1 file changed · +4 -2", runChangesHeader(changes))
|
assertEquals("1 file changed · +4 -2", runChangesHeader(changes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun runChangesRetainsEveryRecordedPatchForAnAggregatedFile() {
|
||||||
|
val reviewedPatch = """
|
||||||
|
--- "a/a.txt"
|
||||||
|
+++ "b/a.txt"
|
||||||
|
@@ -4,0 +5 @@
|
||||||
|
+reviewed
|
||||||
|
""".trimIndent()
|
||||||
|
val changes = runChanges(
|
||||||
|
listOf(
|
||||||
|
step(stage = "implementer", changes = capture(file("a.txt", "modified", patch))),
|
||||||
|
step(stage = "reviewer", changes = capture(file("a.txt", "modified", reviewedPatch))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
val file = changes.files.single()
|
||||||
|
assertTrue(file.patch.orEmpty().contains("+reviewed"))
|
||||||
|
val rendered = parseUnifiedPatch(file.patch)
|
||||||
|
assertEquals(2, rendered.hunks.size)
|
||||||
|
assertEquals(3, rendered.added)
|
||||||
|
assertEquals(1, rendered.removed)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun runChangesSeedsAndReseedsFileEntriesInFirstSeenOrder() {
|
fun runChangesSeedsAndReseedsFileEntriesInFirstSeenOrder() {
|
||||||
val changes = runChanges(
|
val changes = runChanges(
|
||||||
|
|||||||
Reference in New Issue
Block a user