diff --git a/plugins/git4idea/src/git4idea/GitBranch.java b/plugins/git4idea/src/git4idea/GitBranch.java index acdd45a7f050..c3058f7405cc 100644 --- a/plugins/git4idea/src/git4idea/GitBranch.java +++ b/plugins/git4idea/src/git4idea/GitBranch.java @@ -17,11 +17,11 @@ package git4idea; import com.intellij.openapi.diagnostic.Logger; import com.intellij.vcs.log.Hash; -import com.intellij.vcs.log.impl.HashImpl; import git4idea.branch.GitBranchUtil; import git4idea.repo.GitRepository; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** *

Represents a Git branch, local or remote.

@@ -44,30 +44,17 @@ public abstract class GitBranch extends GitReference { @NonNls public static final String REFS_HEADS_PREFIX = "refs/heads/"; // Prefix for local branches ({@value}) @NonNls public static final String REFS_REMOTES_PREFIX = "refs/remotes/"; // Prefix for remote branches ({@value}) + private static final Logger LOG = Logger.getInstance(GitBranch.class); + /** * @deprecated All usages should be reviewed and substituted with actual GitBranch objects with Hashes retrieved from the GitRepository. */ @Deprecated - public static final Hash DUMMY_HASH = HashImpl.build(""); + @Nullable + public static final Hash DUMMY_HASH = null; - private static final Logger LOG = Logger.getInstance(GitBranch.class); - - @NotNull private final Hash myHash; - - protected GitBranch(@NotNull String name, @NotNull Hash hash) { + protected GitBranch(@NotNull String name) { super(GitBranchUtil.stripRefsPrefix(name)); - myHash = hash; - } - - /** - *

Returns the hash on which this branch is reference to.

- * - *

In certain cases (which are to be eliminated in the future) it may be empty, - * if this information wasn't supplied to the GitBranch constructor.

- */ - @NotNull - public Hash getHash() { - return myHash; } /** @@ -121,7 +108,7 @@ public abstract class GitBranch extends GitReference { @NotNull public String toLogString() { - return String.format("%s:%s:%s", getFullName(), getHash(), isRemote() ? "remote" : "local"); + return String.format("%s:%s", getFullName(), isRemote() ? "remote" : "local"); } } diff --git a/plugins/git4idea/src/git4idea/GitLocalBranch.java b/plugins/git4idea/src/git4idea/GitLocalBranch.java index 6996971c22c7..16c9feaa29be 100644 --- a/plugins/git4idea/src/git4idea/GitLocalBranch.java +++ b/plugins/git4idea/src/git4idea/GitLocalBranch.java @@ -15,7 +15,6 @@ */ package git4idea; -import com.intellij.vcs.log.Hash; import git4idea.repo.GitBranchTrackInfo; import git4idea.repo.GitRepository; import org.jetbrains.annotations.NotNull; @@ -26,8 +25,8 @@ import org.jetbrains.annotations.Nullable; */ public class GitLocalBranch extends GitBranch { - public GitLocalBranch(@NotNull String name, @NotNull Hash hash) { - super(name, hash); + public GitLocalBranch(@NotNull String name) { + super(name); } @Override diff --git a/plugins/git4idea/src/git4idea/GitRemoteBranch.java b/plugins/git4idea/src/git4idea/GitRemoteBranch.java index 36ddca4b29e5..a87bca59e38d 100644 --- a/plugins/git4idea/src/git4idea/GitRemoteBranch.java +++ b/plugins/git4idea/src/git4idea/GitRemoteBranch.java @@ -15,7 +15,6 @@ */ package git4idea; -import com.intellij.vcs.log.Hash; import git4idea.repo.GitRemote; import org.jetbrains.annotations.NotNull; @@ -24,8 +23,8 @@ import org.jetbrains.annotations.NotNull; */ public abstract class GitRemoteBranch extends GitBranch { - protected GitRemoteBranch(@NotNull String name, @NotNull Hash hash) { - super(name, hash); + protected GitRemoteBranch(@NotNull String name) { + super(name); } /** diff --git a/plugins/git4idea/src/git4idea/GitStandardRemoteBranch.java b/plugins/git4idea/src/git4idea/GitStandardRemoteBranch.java index 180a40527e7f..bbdc797eb48a 100644 --- a/plugins/git4idea/src/git4idea/GitStandardRemoteBranch.java +++ b/plugins/git4idea/src/git4idea/GitStandardRemoteBranch.java @@ -19,14 +19,20 @@ import com.intellij.vcs.log.Hash; import git4idea.branch.GitBranchUtil; import git4idea.repo.GitRemote; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class GitStandardRemoteBranch extends GitRemoteBranch { @NotNull private final GitRemote myRemote; @NotNull private final String myNameAtRemote; - public GitStandardRemoteBranch(@NotNull GitRemote remote, @NotNull String nameAtRemote, @NotNull Hash hash) { - super(formStandardName(remote, GitBranchUtil.stripRefsPrefix(nameAtRemote)), hash); + @Deprecated + public GitStandardRemoteBranch(@NotNull GitRemote remote, @NotNull String nameAtRemote, @Nullable Hash hash) { + this(remote, nameAtRemote); + } + + public GitStandardRemoteBranch(@NotNull GitRemote remote, @NotNull String nameAtRemote) { + super(formStandardName(remote, GitBranchUtil.stripRefsPrefix(nameAtRemote))); myRemote = remote; myNameAtRemote = GitBranchUtil.stripRefsPrefix(nameAtRemote); } diff --git a/plugins/git4idea/src/git4idea/GitSvnRemoteBranch.java b/plugins/git4idea/src/git4idea/GitSvnRemoteBranch.java index 09ebc6a5a671..49524952a839 100644 --- a/plugins/git4idea/src/git4idea/GitSvnRemoteBranch.java +++ b/plugins/git4idea/src/git4idea/GitSvnRemoteBranch.java @@ -15,7 +15,6 @@ */ package git4idea; -import com.intellij.vcs.log.Hash; import git4idea.repo.GitRemote; import org.jetbrains.annotations.NotNull; @@ -31,8 +30,8 @@ import org.jetbrains.annotations.NotNull; */ public class GitSvnRemoteBranch extends GitRemoteBranch { - public GitSvnRemoteBranch(@NotNull String fullName, @NotNull Hash hash) { - super(fullName, hash); + public GitSvnRemoteBranch(@NotNull String fullName) { + super(fullName); } @NotNull diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java index 0058a2e9c96c..c770dddf57d2 100644 --- a/plugins/git4idea/src/git4idea/GitUtil.java +++ b/plugins/git4idea/src/git4idea/GitUtil.java @@ -726,7 +726,7 @@ public class GitUtil { @NotNull GitRemote remote, @NotNull String branchName) { GitRemoteBranch remoteBranch = findRemoteBranch(repository, remote, branchName); - return ObjectUtils.notNull(remoteBranch, new GitStandardRemoteBranch(remote, branchName, GitBranch.DUMMY_HASH)); + return ObjectUtils.notNull(remoteBranch, new GitStandardRemoteBranch(remote, branchName)); } @Nullable diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java b/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java index 299d3f7a3f86..6711f007ea6e 100644 --- a/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java +++ b/plugins/git4idea/src/git4idea/branch/GitBranchUtil.java @@ -123,7 +123,7 @@ public class GitBranchUtil { try { String name = handler.run(); if (!name.equals("HEAD")) { - return new GitLocalBranch(name, GitBranch.DUMMY_HASH); + return new GitLocalBranch(name); } else { return null; @@ -180,12 +180,12 @@ public class GitBranchUtil { } if (".".equals(remoteName)) { - return new GitSvnRemoteBranch(branch, GitBranch.DUMMY_HASH); + return new GitSvnRemoteBranch(branch); } GitRemote remote = findRemoteByNameOrLogError(project, root, remoteName); if (remote == null) return null; - return new GitStandardRemoteBranch(remote, branch, GitBranch.DUMMY_HASH); + return new GitStandardRemoteBranch(remote, branch); } @Nullable diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchesCollection.java b/plugins/git4idea/src/git4idea/branch/GitBranchesCollection.java index 4f40fc68446d..d73151a1f221 100644 --- a/plugins/git4idea/src/git4idea/branch/GitBranchesCollection.java +++ b/plugins/git4idea/src/git4idea/branch/GitBranchesCollection.java @@ -17,6 +17,7 @@ package git4idea.branch; import com.intellij.openapi.util.Condition; import com.intellij.util.containers.ContainerUtil; +import com.intellij.vcs.log.Hash; import git4idea.GitBranch; import git4idea.GitLocalBranch; import git4idea.GitRemoteBranch; @@ -25,50 +26,60 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; +import java.util.Map; /** *

- * Storage for local, remote and current branches. - * The reason of creating this special collection is that - * in the terms of performance, they are detected by {@link git4idea.repo.GitRepositoryReader} at once; - * and also usually both sets of branches are needed by components, but are treated differently, - * so it is more convenient to have them separated, but in a single container. - *

- * + * Storage for local, remote and current branches. + * The reason of creating this special collection is that + * in the terms of performance, they are detected by {@link git4idea.repo.GitRepositoryReader} at once; + * and also usually both sets of branches are needed by components, but are treated differently, + * so it is more convenient to have them separated, but in a single container. + *

+ * * @author Kirill Likhodedov */ public final class GitBranchesCollection { - - public static final GitBranchesCollection EMPTY = new GitBranchesCollection(Collections.emptyList(), - Collections.emptyList()); - private final Collection myLocalBranches; - private final Collection myRemoteBranches; + public static final GitBranchesCollection EMPTY = + new GitBranchesCollection(Collections.emptyMap(), Collections.emptyMap()); - public GitBranchesCollection(@NotNull Collection localBranches, @NotNull Collection remoteBranches) { + @NotNull + private final Map myLocalBranches; + @NotNull + private final Map myRemoteBranches; + + public GitBranchesCollection(@NotNull Map localBranches, @NotNull Map remoteBranches) { myRemoteBranches = remoteBranches; myLocalBranches = localBranches; } @NotNull public Collection getLocalBranches() { - return Collections.unmodifiableCollection(myLocalBranches); + return Collections.unmodifiableCollection(myLocalBranches.keySet()); } @NotNull public Collection getRemoteBranches() { - return Collections.unmodifiableCollection(myRemoteBranches); + return Collections.unmodifiableCollection(myRemoteBranches.keySet()); + } + + @Nullable + public Hash getHash(@NotNull GitBranch branch) { + if (branch instanceof GitLocalBranch) return myLocalBranches.get(branch); + if (branch instanceof GitRemoteBranch) return myRemoteBranches.get(branch); + return null; } @Nullable public GitLocalBranch findLocalBranch(@NotNull String name) { - return findByName(myLocalBranches, name); + return findByName(myLocalBranches.keySet(), name); } @Nullable public GitBranch findBranchByName(@NotNull String name) { - GitLocalBranch branch = findByName(myLocalBranches, name); - return branch != null ? branch : findByName(myRemoteBranches, name); + GitLocalBranch branch = findByName(myLocalBranches.keySet(), name); + return branch != null ? branch : findByName(myRemoteBranches.keySet(), name); } @Nullable diff --git a/plugins/git4idea/src/git4idea/log/GitLogProvider.java b/plugins/git4idea/src/git4idea/log/GitLogProvider.java index a67c452e1503..6fb284755d3b 100644 --- a/plugins/git4idea/src/git4idea/log/GitLogProvider.java +++ b/plugins/git4idea/src/git4idea/log/GitLogProvider.java @@ -35,6 +35,7 @@ import com.intellij.vcs.log.impl.LogDataImpl; import com.intellij.vcs.log.util.StopWatch; import git4idea.*; import git4idea.branch.GitBranchUtil; +import git4idea.branch.GitBranchesCollection; import git4idea.config.GitVersionSpecialty; import git4idea.history.GitHistoryUtils; import git4idea.repo.GitRepository; @@ -351,15 +352,19 @@ public class GitLogProvider implements VcsLogProvider { StopWatch sw = StopWatch.start("readBranches in " + repository.getRoot().getName()); VirtualFile root = repository.getRoot(); repository.update(); - Collection localBranches = repository.getBranches().getLocalBranches(); - Collection remoteBranches = repository.getBranches().getRemoteBranches(); + GitBranchesCollection branches = repository.getBranches(); + Collection localBranches = branches.getLocalBranches(); + Collection remoteBranches = branches.getRemoteBranches(); Set refs = new THashSet(localBranches.size() + remoteBranches.size()); for (GitLocalBranch localBranch : localBranches) { - refs.add(myVcsObjectsFactory.createRef(localBranch.getHash(), localBranch.getName(), GitRefManager.LOCAL_BRANCH, root)); + Hash hash = branches.getHash(localBranch); + assert hash != null; + refs.add(myVcsObjectsFactory.createRef(hash, localBranch.getName(), GitRefManager.LOCAL_BRANCH, root)); } for (GitRemoteBranch remoteBranch : remoteBranches) { - refs.add( - myVcsObjectsFactory.createRef(remoteBranch.getHash(), remoteBranch.getNameForLocalOperations(), GitRefManager.REMOTE_BRANCH, root)); + Hash hash = branches.getHash(remoteBranch); + assert hash != null; + refs.add(myVcsObjectsFactory.createRef(hash, remoteBranch.getNameForLocalOperations(), GitRefManager.REMOTE_BRANCH, root)); } String currentRevision = repository.getCurrentRevision(); if (currentRevision != null) { // null => fresh repository diff --git a/plugins/git4idea/src/git4idea/push/GitPushSupport.java b/plugins/git4idea/src/git4idea/push/GitPushSupport.java index 6c7b44f6055f..e755b7a92082 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushSupport.java +++ b/plugins/git4idea/src/git4idea/push/GitPushSupport.java @@ -136,7 +136,7 @@ public class GitPushSupport extends PushSupport localBranches; - @NotNull private final Collection remoteBranches; + @NotNull private final Map localBranches; + @NotNull private final Map remoteBranches; GitBranchState(@Nullable String currentRevision, @Nullable GitLocalBranch currentBranch, @NotNull Repository.State state, - @NotNull Collection localBranches, - @NotNull Collection remoteBranches) { + @NotNull Map localBranches, + @NotNull Map remoteBranches) { this.currentRevision = currentRevision; this.currentBranch = currentBranch; this.state = state; @@ -58,12 +59,12 @@ class GitBranchState { } @NotNull - public Collection getLocalBranches() { + public Map getLocalBranches() { return localBranches; } @NotNull - public Collection getRemoteBranches() { + public Map getRemoteBranches() { return remoteBranches; } } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java index 33dc6a771f21..559ccbf678d5 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java @@ -16,6 +16,7 @@ package git4idea.repo; import com.intellij.dvcs.repo.Repository; +import com.intellij.vcs.log.Hash; import git4idea.GitBranch; import git4idea.GitLocalBranch; import git4idea.GitRemoteBranch; @@ -24,9 +25,7 @@ import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.*; /** * @author Kirill Likhodedov @@ -37,19 +36,23 @@ public class GitRepoInfo { @Nullable private final String myCurrentRevision; @NotNull private final Repository.State myState; @NotNull private final Set myRemotes; - @NotNull private final Set myLocalBranches; - @NotNull private final Set myRemoteBranches; + @NotNull private final Map myLocalBranches; + @NotNull private final Map myRemoteBranches; @NotNull private final Set myBranchTrackInfos; - public GitRepoInfo(@Nullable GitLocalBranch currentBranch, @Nullable String currentRevision, @NotNull Repository.State state, - @NotNull Collection remotes, @NotNull Collection localBranches, - @NotNull Collection remoteBranches, @NotNull Collection branchTrackInfos) { + public GitRepoInfo(@Nullable GitLocalBranch currentBranch, + @Nullable String currentRevision, + @NotNull Repository.State state, + @NotNull Collection remotes, + @NotNull Map localBranches, + @NotNull Map remoteBranches, + @NotNull Collection branchTrackInfos) { myCurrentBranch = currentBranch; myCurrentRevision = currentRevision; myState = state; myRemotes = new LinkedHashSet(remotes); - myLocalBranches = new LinkedHashSet(localBranches); - myRemoteBranches = new LinkedHashSet(remoteBranches); + myLocalBranches = new LinkedHashMap(localBranches); + myRemoteBranches = new LinkedHashMap(remoteBranches); myBranchTrackInfos = new LinkedHashSet(branchTrackInfos); } @@ -64,15 +67,21 @@ public class GitRepoInfo { } @NotNull - public Collection getLocalBranches() { + public Map getLocalBranchesWithHashes() { return myLocalBranches; } @NotNull - public Collection getRemoteBranches() { + public Map getRemoteBranchesWithHashes() { return myRemoteBranches; } + @NotNull + @Deprecated + public Collection getRemoteBranches() { + return myRemoteBranches.keySet(); + } + @NotNull public Collection getBranchTrackInfos() { return myBranchTrackInfos; @@ -120,34 +129,37 @@ public class GitRepoInfo { @Override public String toString() { - return String.format("GitRepoInfo{current=%s, remotes=%s, localBranches=%s, remoteBranches=%s, trackInfos=%s}", - myCurrentBranch, myRemotes, myLocalBranches, myRemoteBranches, myBranchTrackInfos); + return String + .format("GitRepoInfo{current=%s, remotes=%s, localBranches=%s, remoteBranches=%s, trackInfos=%s}", myCurrentBranch, myRemotes, + myLocalBranches, myRemoteBranches, myBranchTrackInfos); } - private static boolean areEqual(Collection c1, Collection c2) { + 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, new BranchesComparingStrategy()); - THashSet set2 = new THashSet(c2, new BranchesComparingStrategy()); + 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 { + private static class BranchesComparingStrategy implements TObjectHashingStrategy> { @Override - public int computeHashCode(@NotNull GitBranch branch) { - return 31 * branch.getName().hashCode() + branch.getHash().hashCode(); + public int computeHashCode(@NotNull Map.Entry branchEntry) { + return 31 * branchEntry.getKey().getName().hashCode() + branchEntry.getValue().hashCode(); } @Override - public boolean equals(@NotNull GitBranch b1, @NotNull GitBranch b2) { + 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.getName().equals(b2.getName()) && b1.getHash().equals(b2.getHash()); + return b1.getKey().getName().equals(b2.getKey().getName()) && b2.getValue().equals(b2.getValue()); } } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java index 02261494bafa..5774a47a4866 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java @@ -155,7 +155,7 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository { @NotNull public GitBranchesCollection getBranches() { GitRepoInfo info = myInfo; - return new GitBranchesCollection(info.getLocalBranches(), info.getRemoteBranches()); + return new GitBranchesCollection(info.getLocalBranchesWithHashes(), info.getRemoteBranchesWithHashes()); } @Override @@ -198,7 +198,7 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository { GitConfig config = GitConfig.read(myPlatformFacade, configFile); Collection remotes = config.parseRemotes(); GitBranchState state = myReader.readState(remotes); - Collection trackInfos = config.parseTrackInfos(state.getLocalBranches(), state.getRemoteBranches()); + Collection trackInfos = config.parseTrackInfos(state.getLocalBranches().keySet(), state.getRemoteBranches().keySet()); return new GitRepoInfo(state.getCurrentBranch(), state.getCurrentRevision(), state.getState(), remotes, state.getLocalBranches(), state.getRemoteBranches(), trackInfos); } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java index f7f0684baa60..3fbcd6d9bf76 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java @@ -79,8 +79,8 @@ class GitRepositoryReader { @NotNull GitBranchState readState(@NotNull Collection remotes) { - Pair, Set> branches = readBranches(remotes); - Set localBranches = branches.first; + Pair, Map> branches = readBranches(remotes); + Map localBranches = branches.first; HeadInfo headInfo = readHead(); Repository.State state = readRepositoryState(headInfo); @@ -92,11 +92,11 @@ class GitRepositoryReader { currentRevision = headInfo.content; } else if (!localBranches.isEmpty()) { - currentBranch = findCurrentBranch(headInfo, state, localBranches); - currentRevision = getCurrentRevision(headInfo, currentBranch); + currentBranch = findCurrentBranch(headInfo, state, localBranches.keySet()); + currentRevision = getCurrentRevision(headInfo, currentBranch == null ? null : localBranches.get(currentBranch)); } else if (headInfo.content != null) { - currentBranch = new GitLocalBranch(headInfo.content, GitBranch.DUMMY_HASH); + currentBranch = new GitLocalBranch(headInfo.content); currentRevision = null; } else { @@ -107,16 +107,16 @@ class GitRepositoryReader { } @Nullable - private static String getCurrentRevision(@NotNull HeadInfo headInfo, @Nullable GitLocalBranch currentBranch) { + private static String getCurrentRevision(@NotNull HeadInfo headInfo, @Nullable Hash currentBranchHash) { String currentRevision; if (!headInfo.isBranch) { currentRevision = headInfo.content; } - else if (currentBranch == null) { + else if (currentBranchHash == null) { currentRevision = null; } else { - currentRevision = currentBranch.getHash().asString(); + currentRevision = currentBranchHash.asString(); } return currentRevision; } @@ -220,7 +220,7 @@ class GitRepositoryReader { } @NotNull - private Pair, Set> readBranches(@NotNull Collection remotes) { + private Pair, Map> readBranches(@NotNull Collection remotes) { Map data = readBranchRefsFromFiles(); Map resolvedRefs = resolveRefs(data); return createBranchesFromData(remotes, resolvedRefs); @@ -236,20 +236,20 @@ class GitRepositoryReader { } @NotNull - private static Pair, Set> createBranchesFromData(@NotNull Collection remotes, - @NotNull Map data) { - Set localBranches = ContainerUtil.newHashSet(); - Set remoteBranches = ContainerUtil.newHashSet(); + private static Pair, Map> createBranchesFromData(@NotNull Collection remotes, + @NotNull Map data) { + Map localBranches = ContainerUtil.newHashMap(); + Map remoteBranches = ContainerUtil.newHashMap(); for (Map.Entry entry : data.entrySet()) { String refName = entry.getKey(); Hash hash = entry.getValue(); if (refName.startsWith(REFS_HEADS_PREFIX)) { - localBranches.add(new GitLocalBranch(refName, hash)); + localBranches.put(new GitLocalBranch(refName), hash); } else if (refName.startsWith(REFS_REMOTES_PREFIX)) { - GitRemoteBranch remoteBranch = parseRemoteBranch(refName, hash, remotes); + GitRemoteBranch remoteBranch = parseRemoteBranch(refName, remotes); if (remoteBranch != null) { - remoteBranches.add(remoteBranch); + remoteBranches.put(remoteBranch, hash); } } else { @@ -295,13 +295,12 @@ class GitRepositoryReader { @Nullable private static GitRemoteBranch parseRemoteBranch(@NotNull String fullBranchName, - @NotNull Hash hash, @NotNull Collection remotes) { String stdName = GitBranchUtil.stripRefsPrefix(fullBranchName); int slash = stdName.indexOf('/'); if (slash == -1) { // .git/refs/remotes/my_branch => git-svn - return new GitSvnRemoteBranch(fullBranchName, hash); + return new GitSvnRemoteBranch(fullBranchName); } else { GitRemote remote; @@ -319,9 +318,9 @@ class GitRepositoryReader { LOG.debug(String.format("No remote found with the name [%s]. All remotes: %s", remoteName, remotes)); GitRemote fakeRemote = new GitRemote(remoteName, ContainerUtil.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - return new GitStandardRemoteBranch(fakeRemote, branchName, hash); + return new GitStandardRemoteBranch(fakeRemote, branchName); } - return new GitStandardRemoteBranch(remote, branchName, hash); + return new GitStandardRemoteBranch(remote, branchName); } } diff --git a/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt b/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt index 2ec4e17f75d4..bd0c0d244062 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt +++ b/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt @@ -125,7 +125,7 @@ abstract class GitPushOperationBaseTest : GitPlatformTest() { if (target == null) { val firstSlash = to.indexOf('/') val remote = GitUtil.findRemoteByName(repository, to.substring(0, firstSlash))!! - target = GitStandardRemoteBranch(remote, to.substring(firstSlash + 1), GitBranch.DUMMY_HASH) + target = GitStandardRemoteBranch(remote, to.substring(firstSlash + 1)) newBranch = true } else { diff --git a/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java b/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java index a564b92142b9..0f4fc1b5bce7 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java +++ b/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java @@ -206,14 +206,14 @@ public class GitPushResultNotificationTest extends GitPlatformTest { } private static GitLocalBranch from(String from) { - return new GitLocalBranch(from, GitBranch.DUMMY_HASH); + return new GitLocalBranch(from); } private static GitRemoteBranch to(String to) { int firstSlash = to.indexOf('/'); GitRemote remote = new GitRemote(to.substring(0, firstSlash), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - return new GitStandardRemoteBranch(remote, to.substring(firstSlash + 1), GitBranch.DUMMY_HASH); + return new GitStandardRemoteBranch(remote, to.substring(firstSlash + 1)); } private GitPushResultNotification notification(GitPushRepoResult singleResult) { diff --git a/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java b/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java index 94bb705dd9c6..813ec29cf482 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java +++ b/plugins/git4idea/tests/git4idea/repo/GitConfigTest.java @@ -65,7 +65,7 @@ public class GitConfigTest extends GitPlatformTest { File gitDir = new File(myProjectPath, ".git"); GitConfig config = GitConfig.read(myPlatformFacade, new File(gitDir, "config")); GitBranchState state = new GitRepositoryReader(gitDir).readState(config.parseRemotes()); - Collection trackInfos = config.parseTrackInfos(state.getLocalBranches(), state.getRemoteBranches()); + Collection trackInfos = config.parseTrackInfos(state.getLocalBranches().keySet(), state.getRemoteBranches().keySet()); assertTrue("Couldn't find correct a#branch tracking information among: [" + trackInfos + "]", ContainerUtil.exists(trackInfos, new Condition() { @Override @@ -213,8 +213,8 @@ public class GitConfigTest extends GitPlatformTest { String remoteBranchAtRemote = info[2]; String remoteBranchHere = info[3]; boolean merge = info[4].equals("merge"); - remotes.add(new GitBranchTrackInfo(new GitLocalBranch(branch, GitBranch.DUMMY_HASH), - new GitStandardRemoteBranch(remote, remoteBranchAtRemote, GitBranch.DUMMY_HASH), + remotes.add(new GitBranchTrackInfo(new GitLocalBranch(branch), + new GitStandardRemoteBranch(remote, remoteBranchAtRemote), merge)); } return remotes; diff --git a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.java b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.java index 613acbefc10c..114c58edcab9 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.java +++ b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.java @@ -62,7 +62,7 @@ public class GitRepositoryReaderNewTest extends GitSingleRepoTest { final String INVALID_REMOTE_BRANCH = "master"; git("update-ref refs/remotes/" + INVALID_REMOTE + "/" + INVALID_REMOTE_BRANCH + " HEAD"); - Collection remoteBranches = readState().getRemoteBranches(); + Collection remoteBranches = readState().getRemoteBranches().keySet(); assertTrue("Remote branch not found", ContainerUtil.exists(remoteBranches, new Condition() { @Override public boolean value(GitRemoteBranch branch) { diff --git a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java index 599bbd9b1001..dc56a6eb1f84 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java +++ b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java @@ -42,6 +42,7 @@ import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.Map; @RunWith(Parameterized.class) public class GitRepositoryReaderTest extends GitPlatformTest { @@ -140,21 +141,21 @@ public class GitRepositoryReaderTest extends GitPlatformTest { GitBranchState state = myRepositoryReader.readState(remotes); assertEquals("HEAD revision is incorrect", readHead(myTempDir), state.getCurrentRevision()); - assertEqualBranches(readCurrentBranch(myTempDir), state.getCurrentBranch()); + assertEqualBranches(readCurrentBranch(myTempDir), state.getCurrentBranch(), state.getLocalBranches().get(state.getCurrentBranch())); assertBranches(state.getLocalBranches(), readBranches(myTempDir, true)); assertBranches(state.getRemoteBranches(), readBranches(myTempDir, false)); } - private static void assertEqualBranches(@NotNull Branch expected, @NotNull GitLocalBranch actual) { + private static void assertEqualBranches(@NotNull Branch expected, @NotNull GitLocalBranch actual, @NotNull Hash hash) { assertEquals(expected.name, actual.getName()); - assertEquals("Incorrect hash of branch " + actual.getName(), expected.hash, actual.getHash()); + assertEquals("Incorrect hash of branch " + actual.getName(), expected.hash, hash); } - private static void assertBranches(Collection actualBranches, Collection expectedBranches) { - VcsTestUtil.assertEqualCollections(actualBranches, expectedBranches, new VcsTestUtil.EqualityChecker() { + private static void assertBranches(Map actualBranches, Collection expectedBranches) { + VcsTestUtil.assertEqualCollections(actualBranches.entrySet(), expectedBranches, new VcsTestUtil.EqualityChecker, Branch>() { @Override - public boolean areEqual(GitBranch actual, Branch expected) { - return branchesAreEqual(actual, expected); + public boolean areEqual(Map.Entry actual, Branch expected) { + return branchesAreEqual(actual.getKey(), actual.getValue(), expected); } }); } @@ -169,8 +170,8 @@ public class GitRepositoryReaderTest extends GitPlatformTest { return branches; } - private static boolean branchesAreEqual(GitBranch actual, Branch expected) { - return actual.getFullName().equals(expected.name) && actual.getHash().equals(expected.hash); + private static boolean branchesAreEqual(GitBranch actualBranch, Hash actualHash, Branch expected) { + return actualBranch.getFullName().equals(expected.name) && actualHash.equals(expected.hash); } private static class Branch {