Skip to content

Instantly share code, notes, and snippets.

@chetkhatri
Created December 20, 2019 22:34
Show Gist options
  • Save chetkhatri/6524b2d940ee4176c0361c17dba99a5e to your computer and use it in GitHub Desktop.
Save chetkhatri/6524b2d940ee4176c0361c17dba99a5e to your computer and use it in GitHub Desktop.
private def monotonizeCommitTimestamps[T <: CommitMarker](commits: Array[T]): Array[T] = {
var i = 0
val length = commits.length
while (i < length - 1) {
val prevTimestamp = commits(i).getTimestamp
assert(commits(i).getVersion < commits(i + 1).getVersion, "Unordered commits provided.")
if (prevTimestamp >= commits(i + 1).getTimestamp) {
logWarning(s"Found Delta commit ${commits(i).getVersion} with a timestamp $prevTimestamp " +
s"which is greater than the next commit timestamp ${commits(i + 1).getTimestamp}.")
commits(i + 1) = commits(i + 1).withTimestamp(prevTimestamp + 1).asInstanceOf[T]
}
i += 1
}
commits
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment