mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-115780 Let branch and tag with same name in the log
The purpose of the special refs hashing strategy is to make sure we don't receive the same reference pointing to different hashes. However, type is still important, since we don't store "refs/tags" prefixes in the name.
This commit is contained in:
@@ -40,12 +40,7 @@ import com.intellij.vcs.log.*;
|
||||
import com.intellij.vcs.log.impl.HashImpl;
|
||||
import com.intellij.vcs.log.impl.LogDataImpl;
|
||||
import com.intellij.vcs.log.util.StopWatch;
|
||||
import git4idea.GitBranch;
|
||||
import git4idea.GitCommit;
|
||||
import git4idea.GitFileRevision;
|
||||
import git4idea.GitRevisionNumber;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.*;
|
||||
import git4idea.branch.GitBranchUtil;
|
||||
import git4idea.commands.*;
|
||||
import git4idea.config.GitVersionSpecialty;
|
||||
@@ -740,7 +735,7 @@ public class GitHistoryUtils {
|
||||
if (factory == null) {
|
||||
return LogDataImpl.empty();
|
||||
}
|
||||
final Set<VcsRef> refs = new OpenTHashSet<VcsRef>(GitLogProvider.REF_ONLY_NAME_STRATEGY);
|
||||
final Set<VcsRef> refs = new OpenTHashSet<VcsRef>(GitLogProvider.DONT_CONSIDER_SHA);
|
||||
final List<VcsCommitMetadata> commits =
|
||||
loadDetails(project, root, withRefs, false, new NullableFunction<GitLogRecord, VcsCommitMetadata>() {
|
||||
@Nullable
|
||||
|
||||
@@ -55,15 +55,15 @@ public class GitLogProvider implements VcsLogProvider {
|
||||
return ref.getType() == GitRefManager.TAG ? ref.getName() : null;
|
||||
}
|
||||
};
|
||||
public static final TObjectHashingStrategy<VcsRef> REF_ONLY_NAME_STRATEGY = new TObjectHashingStrategy<VcsRef>() {
|
||||
public static final TObjectHashingStrategy<VcsRef> DONT_CONSIDER_SHA = new TObjectHashingStrategy<VcsRef>() {
|
||||
@Override
|
||||
public int computeHashCode(@NotNull VcsRef ref) {
|
||||
return ref.getName().hashCode();
|
||||
return 31 * ref.getName().hashCode() + ref.getType().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@NotNull VcsRef ref1, @NotNull VcsRef ref2) {
|
||||
return ref1.getName().equals(ref2.getName());
|
||||
return ref1.getName().equals(ref2.getName()) && ref1.getType().equals(ref2.getType());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -104,7 +104,7 @@ public class GitLogProvider implements VcsLogProvider {
|
||||
DetailedLogData data = GitHistoryUtils.loadMetadata(myProject, root, true, params);
|
||||
|
||||
Set<VcsRef> safeRefs = data.getRefs();
|
||||
Set<VcsRef> allRefs = new OpenTHashSet<VcsRef>(safeRefs, REF_ONLY_NAME_STRATEGY);
|
||||
Set<VcsRef> allRefs = new OpenTHashSet<VcsRef>(safeRefs, DONT_CONSIDER_SHA);
|
||||
Set<VcsRef> branches = readBranches(repository);
|
||||
addNewElements(allRefs, branches);
|
||||
|
||||
|
||||
@@ -136,6 +136,29 @@ public class GitLogProviderTest extends GitSingleRepoTest {
|
||||
}));
|
||||
}
|
||||
|
||||
public void test_support_equally_named_branch_and_tag() throws Exception {
|
||||
prepareSomeHistory();
|
||||
git("branch build");
|
||||
git("tag build");
|
||||
|
||||
VcsLogProvider.DetailedLogData data = myLogProvider.readFirstBlock(myProjectRoot,
|
||||
new RequirementsImpl(1000, true, Collections.<VcsRef>emptySet()));
|
||||
List<VcsCommitMetadata> expectedLog = log();
|
||||
assertOrderedEquals(data.getCommits(), expectedLog);
|
||||
assertTrue(ContainerUtil.exists(data.getRefs(), new Condition<VcsRef>() {
|
||||
@Override
|
||||
public boolean value(VcsRef ref) {
|
||||
return ref.getName().equals("build") && ref.getType() == GitRefManager.LOCAL_BRANCH;
|
||||
}
|
||||
}));
|
||||
assertTrue(ContainerUtil.exists(data.getRefs(), new Condition<VcsRef>() {
|
||||
@Override
|
||||
public boolean value(VcsRef ref) {
|
||||
return ref.getName().equals("build") && ref.getType() == GitRefManager.TAG;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private static void prepareSomeHistory() {
|
||||
tac("a.txt");
|
||||
git("tag ATAG");
|
||||
|
||||
Reference in New Issue
Block a user