mirror of https://github.com/sbt/sbt.git
Fixes Tracked.inputChanged
Tracked.inputChanged stores and reads hash correctly. Fixes #96
This commit is contained in:
parent
5b85002a69
commit
24d97aa104
|
|
@ -96,15 +96,19 @@ object Tracked {
|
||||||
|
|
||||||
private final class CacheHelp[I: JsonFormat](val sc: SingletonCache[Long]) {
|
private final class CacheHelp[I: JsonFormat](val sc: SingletonCache[Long]) {
|
||||||
import CacheImplicits.implicitHashWriter
|
import CacheImplicits.implicitHashWriter
|
||||||
|
import CacheImplicits.LongJsonFormat
|
||||||
def save(store: CacheStore, value: I): Unit = {
|
def save(store: CacheStore, value: I): Unit = {
|
||||||
store.write(value)
|
Hasher.hash(value) match {
|
||||||
|
case Success(keyHash) => store.write[Long](keyHash.toLong)
|
||||||
|
case Failure(e) => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def changed(store: CacheStore, value: I): Boolean =
|
def changed(store: CacheStore, value: I): Boolean =
|
||||||
Try { store.read[I] } match {
|
Try { store.read[Long] } match {
|
||||||
case Success(prev) =>
|
case Success(prev: Long) =>
|
||||||
Hasher.hash(value) match {
|
Hasher.hash(value) match {
|
||||||
case Success(keyHash) => keyHash.toLong != prev
|
case Success(keyHash: Int) => keyHash.toLong != prev
|
||||||
case Failure(_) => true
|
case Failure(_) => true
|
||||||
}
|
}
|
||||||
case Failure(_) => true
|
case Failure(_) => true
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,10 @@ class TrackedSpec extends UnitSpec {
|
||||||
|
|
||||||
"inputChanged" should "detect that the input has not changed" in {
|
"inputChanged" should "detect that the input has not changed" in {
|
||||||
withStore { store =>
|
withStore { store =>
|
||||||
val input0 = 0
|
val input0 = "foo"
|
||||||
|
|
||||||
val res0 =
|
val res0 =
|
||||||
Tracked.inputChanged[Int, Int](store) {
|
Tracked.inputChanged[String, String](store) {
|
||||||
case (true, in) =>
|
case (true, in) =>
|
||||||
assert(in === input0)
|
assert(in === input0)
|
||||||
in
|
in
|
||||||
|
|
@ -64,7 +64,7 @@ class TrackedSpec extends UnitSpec {
|
||||||
assert(res0 === input0)
|
assert(res0 === input0)
|
||||||
|
|
||||||
val res1 =
|
val res1 =
|
||||||
Tracked.inputChanged[Int, Int](store) {
|
Tracked.inputChanged[String, String](store) {
|
||||||
case (true, in) =>
|
case (true, in) =>
|
||||||
fail()
|
fail()
|
||||||
case (false, in) =>
|
case (false, in) =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue