vcs-log: support hash-range in multi-repository projects: IDEA-216785

To filter by a range, we need to resolve the supplied ref to a CommitId. To speedup resolve for a full-size hash, no checks were performed: the string was simply converted to a Hash and a CommitId. Therefore in a multi-root project a full-size hash was resolved in all roots, although it existed only in one of them.

To fix this, check if the generated CommitId exists in the storage. If it doesn't, then we generated it incorrectly, and there is no such hash in the root.

GitOrigin-RevId: 3b34a6212e539355a0e0f40ed5ade9160ad855d9
This commit is contained in:
Kirill Likhodedov
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent 75ca1a1ff3
commit b36aabbb5d
2 changed files with 31 additions and 1 deletions
@@ -241,7 +241,8 @@ class VcsLogFiltererImpl(private val logProviders: Map<VirtualFile, VcsLogProvid
private fun resolveCommit(dataPack: DataPack, root: VirtualFile, refName: String): CommitId? {
if (refName.length == FULL_HASH_LENGTH && VcsLogUtil.HASH_REGEX.matcher(refName).matches()) {
return CommitId(HashImpl.build(refName), root)
val commitId = CommitId(HashImpl.build(refName), root)
return if (storage.containsCommit(commitId)) commitId else null
}
val ref = dataPack.refsModel.findBranch(refName, root)
@@ -189,6 +189,31 @@ class VisiblePackBuilderTest {
assertCommits(visiblePack.visibleGraph, 2)
}
@Test
fun `filter by hash range in multi-root project`() {
val root1 = MockVirtualFile("root1")
val root2 = MockVirtualFile("root2")
val graph = multiRootGraph {
root(root1) {
1(2) * "master"
2(3)
3()
}
root(root2) {
5(4) * "master"
4()
}
}
val hash1 = graph.getHash(1)
val hash2 = graph.getHash(2)
val filters = VcsLogFilterObject.collection(VcsLogFilterObject.fromRange(hash2.asString(), hash1.asString()))
val visiblePack = graph.build(filters)
assertCommits(visiblePack.visibleGraph, 1)
}
@Test
fun `filter by range where ref is unresolved`() {
val graph = graph {
@@ -273,6 +298,10 @@ class VisiblePackBuilderTest {
}
}
}
fun getHash(id: Int): Hash {
return hashMap.getCommitId(id).hash
}
}
fun VcsLogStorage.getHashes(ids: List<Int>) = ids.map { getCommitId(it)!!.hash }