From 2f1967e909ed69e25bdbe359baf9aeb9495dc63d Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Thu, 4 Oct 2018 19:05:37 +0300 Subject: [PATCH] git: Refactor "GitRepoInfo.equals()" "Hash" instances will be checked for equality as part of "Map.equals()" anyway f88f0629f488f91c5fe3ff2e65fc49bc87d079bc, 9ea940ab07cbeb75157e824d397cb2a238799e81 follow-up --- .../src/git4idea/repo/GitRepoInfo.java | 52 ++----------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java index 12ccbd57e1fb..c2986f27a152 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java @@ -1,29 +1,12 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package git4idea.repo; import com.intellij.dvcs.repo.Repository; import com.intellij.vcs.log.Hash; -import git4idea.GitBranch; import git4idea.GitLocalBranch; import git4idea.GitReference; import git4idea.GitRemoteBranch; import gnu.trove.THashMap; -import gnu.trove.THashSet; -import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -142,8 +125,8 @@ public class GitRepoInfo { if (myCurrentBranch != null ? !myCurrentBranch.equals(info.myCurrentBranch) : info.myCurrentBranch != null) return false; if (!myRemotes.equals(info.myRemotes)) return false; if (!myBranchTrackInfos.equals(info.myBranchTrackInfos)) return false; - if (!areEqual(myLocalBranches, info.myLocalBranches)) return false; - if (!areEqual(myRemoteBranches, info.myRemoteBranches)) return false; + if (!myLocalBranches.equals(info.myLocalBranches)) return false; + if (!myRemoteBranches.equals(info.myRemoteBranches)) return false; if (!mySubmodules.equals(info.mySubmodules)) return false; if (!myHooksInfo.equals(info.myHooksInfo)) return false; if (myIsShallow != info.myIsShallow) return false; @@ -171,33 +154,4 @@ public class GitRepoInfo { return String.format("GitRepoInfo{current=%s, remotes=%s, localBranches=%s, remoteBranches=%s, trackInfos=%s, submodules=%s, hooks=%s}", myCurrentBranch, myRemotes, myLocalBranches, myRemoteBranches, myBranchTrackInfos, mySubmodules, myHooksInfo); } - - private static boolean areEqual(Map c1, Map c2) { - // GitBranch has perverted equals contract (see the comment there) - // until GitBranch is created only from a single place with correctly defined Hash, we can't change its equals - THashSet> set1 = - new THashSet<>(c1.entrySet(), new BranchesComparingStrategy()); - THashSet> set2 = - new THashSet<>(c2.entrySet(), new BranchesComparingStrategy()); - return set1.equals(set2); - } - - private static class BranchesComparingStrategy implements TObjectHashingStrategy> { - - @Override - public int computeHashCode(@NotNull Map.Entry branchEntry) { - return 31 * branchEntry.getKey().getName().hashCode() + branchEntry.getValue().hashCode(); - } - - @Override - public boolean equals(@NotNull Map.Entry b1, @NotNull Map.Entry b2) { - if (b1 == b2) { - return true; - } - if (b1.getClass() != b2.getClass()) { - return false; - } - return b1.getKey().getName().equals(b2.getKey().getName()) && b1.getValue().equals(b2.getValue()); - } - } }