@@ -315,14 +315,12 @@ class CLVersion : IVersion {
315
315
return ancestors.filter { stopAt == null || it.getContentHash() != stopAt.getContentHash() }
316
316
}
317
317
318
- fun getAncestors (includeSelf : Boolean , stopAt : CLVersion ? ): List <CLVersion > {
319
- if (stopAt != null && this .getContentHash() == stopAt.getContentHash()) {
320
- return emptyList()
321
- }
322
- return if (includeSelf) {
323
- listOf (this ) + getAncestors(false , stopAt)
324
- } else {
325
- getParents(stopAt).flatMap { it.getAncestors(true , stopAt) }
318
+ fun collectAncestors (stopAt : CLVersion ? , result : MutableMap <String , CLVersion >) {
319
+ if (stopAt != null && this .getContentHash() == stopAt.getContentHash()) return
320
+ if (result.contains(getContentHash())) return
321
+ result[getContentHash()] = this
322
+ for (parent in getParents(stopAt)) {
323
+ parent.collectAncestors(stopAt, result)
326
324
}
327
325
}
328
326
}
@@ -348,8 +346,9 @@ fun CLVersion.fullDiff(baseVersion: CLVersion?): IStream.Many<IKVValue> {
348
346
349
347
fun CLVersion.historyDiff (baseVersion : CLVersion ? ): IStream .Many <CPVersion > {
350
348
val commonBase = VersionMerger .commonBaseVersion(this , baseVersion)
351
- val history = getAncestors(true , commonBase).map { it.data }
352
- return IStream .many(history)
349
+ val history = LinkedHashMap <String , CLVersion >()
350
+ collectAncestors(commonBase, history)
351
+ return IStream .many(history.values.map { it.data })
353
352
}
354
353
355
354
@Suppress(" UNCHECKED_CAST" )
0 commit comments