diff --git a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.kt b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.kt index c2986f27a152..8082858cfe79 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.kt +++ b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.kt @@ -1,157 +1,92 @@ // 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; +package git4idea.repo -import com.intellij.dvcs.repo.Repository; -import com.intellij.vcs.log.Hash; -import git4idea.GitLocalBranch; -import git4idea.GitReference; -import git4idea.GitRemoteBranch; -import gnu.trove.THashMap; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.intellij.dvcs.repo.Repository +import com.intellij.vcs.log.Hash +import git4idea.GitLocalBranch +import git4idea.GitReference +import git4idea.GitRemoteBranch +import gnu.trove.THashMap -import java.util.*; +import java.util.* -public class GitRepoInfo { +class GitRepoInfo(val currentBranch: GitLocalBranch?, + val currentRevision: String?, + val state: Repository.State, + remotes: Collection, + localBranches: Map, + remoteBranches: Map, + branchTrackInfos: Collection, + val submodules: Collection, + val hooksInfo: GitHooksInfo, + val isShallow: Boolean) { + private val myRemotes: Set + val localBranchesWithHashes: Map + val remoteBranchesWithHashes: Map + private val myBranchTrackInfos: Set + private val myBranchTrackInfosMap: MutableMap - @Nullable private final GitLocalBranch myCurrentBranch; - @Nullable private final String myCurrentRevision; - @NotNull private final Repository.State myState; - @NotNull private final Set myRemotes; - @NotNull private final Map myLocalBranches; - @NotNull private final Map myRemoteBranches; - @NotNull private final Set myBranchTrackInfos; - @NotNull private final Map myBranchTrackInfosMap; - @NotNull private final Collection mySubmodules; - @NotNull private final GitHooksInfo myHooksInfo; - private final boolean myIsShallow; + val remotes: Collection + get() = myRemotes - public GitRepoInfo(@Nullable GitLocalBranch currentBranch, - @Nullable String currentRevision, - @NotNull Repository.State state, - @NotNull Collection remotes, - @NotNull Map localBranches, - @NotNull Map remoteBranches, - @NotNull Collection branchTrackInfos, - @NotNull Collection submodules, - @NotNull GitHooksInfo hooksInfo, - boolean isShallow) { - myCurrentBranch = currentBranch; - myCurrentRevision = currentRevision; - myState = state; - myRemotes = new LinkedHashSet<>(remotes); - myLocalBranches = new HashMap<>(localBranches); - myRemoteBranches = new HashMap<>(remoteBranches); - myBranchTrackInfos = new LinkedHashSet<>(branchTrackInfos); - mySubmodules = submodules; - myHooksInfo = hooksInfo; - myIsShallow = isShallow; + val remoteBranches: Collection + @Deprecated("") + get() = remoteBranchesWithHashes.keys - myBranchTrackInfosMap = new THashMap<>(GitReference.BRANCH_NAME_HASHING_STRATEGY); - for (GitBranchTrackInfo info : branchTrackInfos) { - myBranchTrackInfosMap.put(info.getLocalBranch().getName(), info); + val branchTrackInfos: Collection + get() = myBranchTrackInfos + + val branchTrackInfosMap: Map + get() = myBranchTrackInfosMap + + init { + myRemotes = LinkedHashSet(remotes) + localBranchesWithHashes = HashMap(localBranches) + remoteBranchesWithHashes = HashMap(remoteBranches) + myBranchTrackInfos = LinkedHashSet(branchTrackInfos) + + myBranchTrackInfosMap = THashMap(GitReference.BRANCH_NAME_HASHING_STRATEGY) + for (info in branchTrackInfos) { + myBranchTrackInfosMap[info.localBranch.name] = info } } - @Nullable - public GitLocalBranch getCurrentBranch() { - return myCurrentBranch; + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o == null || javaClass != o.javaClass) return false + + val info = o as GitRepoInfo? + + if (state !== info!!.state) return false + if (if (currentRevision != null) currentRevision != info!!.currentRevision else info!!.currentRevision != null) return false + if (if (currentBranch != null) currentBranch != info.currentBranch else info.currentBranch != null) return false + if (myRemotes != info.myRemotes) return false + if (myBranchTrackInfos != info.myBranchTrackInfos) return false + if (localBranchesWithHashes != info.localBranchesWithHashes) return false + if (remoteBranchesWithHashes != info.remoteBranchesWithHashes) return false + if (submodules != info.submodules) return false + if (hooksInfo != info.hooksInfo) return false + return if (isShallow != info.isShallow) false else true + } - @NotNull - public Collection getRemotes() { - return myRemotes; + override fun hashCode(): Int { + var result = currentBranch?.hashCode() ?: 0 + result = 31 * result + (currentRevision?.hashCode() ?: 0) + result = 31 * result + state.hashCode() + result = 31 * result + myRemotes.hashCode() + result = 31 * result + localBranchesWithHashes.hashCode() + result = 31 * result + remoteBranchesWithHashes.hashCode() + result = 31 * result + myBranchTrackInfos.hashCode() + result = 31 * result + submodules.hashCode() + result = 31 * result + hooksInfo.hashCode() + result = 31 * result + if (isShallow) 1 else 0 + return result } - @NotNull - public Map getLocalBranchesWithHashes() { - return myLocalBranches; - } - - @NotNull - public Map getRemoteBranchesWithHashes() { - return myRemoteBranches; - } - - @NotNull - @Deprecated - public Collection getRemoteBranches() { - return myRemoteBranches.keySet(); - } - - @NotNull - public Collection getBranchTrackInfos() { - return myBranchTrackInfos; - } - - @NotNull - public Map getBranchTrackInfosMap() { - return myBranchTrackInfosMap; - } - - @Nullable - public String getCurrentRevision() { - return myCurrentRevision; - } - - @NotNull - public Repository.State getState() { - return myState; - } - - @NotNull - public Collection getSubmodules() { - return mySubmodules; - } - - @NotNull - public GitHooksInfo getHooksInfo() { - return myHooksInfo; - } - - public boolean isShallow() { - return myIsShallow; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - GitRepoInfo info = (GitRepoInfo)o; - - if (myState != info.myState) return false; - if (myCurrentRevision != null ? !myCurrentRevision.equals(info.myCurrentRevision) : info.myCurrentRevision != null) return false; - 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 (!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; - - return true; - } - - @Override - public int hashCode() { - int result = myCurrentBranch != null ? myCurrentBranch.hashCode() : 0; - result = 31 * result + (myCurrentRevision != null ? myCurrentRevision.hashCode() : 0); - result = 31 * result + myState.hashCode(); - result = 31 * result + myRemotes.hashCode(); - result = 31 * result + myLocalBranches.hashCode(); - result = 31 * result + myRemoteBranches.hashCode(); - result = 31 * result + myBranchTrackInfos.hashCode(); - result = 31 * result + mySubmodules.hashCode(); - result = 31 * result + myHooksInfo.hashCode(); - result = 31 * result + (myIsShallow ? 1 : 0); - return result; - } - - @Override - public String toString() { + override fun toString(): String { 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); + currentBranch, myRemotes, localBranchesWithHashes, remoteBranchesWithHashes, myBranchTrackInfos, submodules, + hooksInfo) } }