From: Aleksey Pivovarov Date: Sat, 20 Jun 2015 11:22:23 +0000 (+0300) Subject: vcs annotate: fix possible issue with "commit number" X-Git-Tag: webstorm/142.4576~10^2~36 X-Git-Url: https://git.jetbrains.org/?p=idea%2Fcommunity.git;a=commitdiff_plain;h=5e1973701bf61e01087bb070c1ddb2cb42d310a1 vcs annotate: fix possible issue with "commit number" We know that fileAnnotation.getRevisions() are sorted properly, while old comparator could return invalid result (ex: for commits with the same timestamp in git) --- diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java index 1e09e53750ff..657a2df5fbf7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java @@ -47,7 +47,6 @@ import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; import com.intellij.openapi.vcs.impl.UpToDateLineNumberProviderImpl; import com.intellij.openapi.vcs.impl.VcsBackgroundableActions; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.containers.SortedList; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -267,7 +266,7 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann final Couple> bgColorMap = Registry.is("vcs.show.colored.annotations") ? computeBgColors(fileAnnotation) : null; - final Map historyIds = Registry.is("vcs.show.history.numbers") ? computeLineNumbers(fileAnnotation) : null; + final Map historyIds = Registry.is("vcs.show.history.numbers") ? computeLineNumbers(fileAnnotation) : null; if (switcher != null) { switcher.switchTo(switcher.getDefaultSource()); @@ -334,31 +333,16 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann } @Nullable - private static Map computeLineNumbers(@NotNull FileAnnotation fileAnnotation) { - final SortedList revisions = new SortedList(new Comparator() { - @Override - public int compare(VcsFileRevision o1, VcsFileRevision o2) { - try { - final int result = o1.getRevisionDate().compareTo(o2.getRevisionDate()); - return result != 0 ? result : o1.getRevisionNumber().compareTo(o2.getRevisionNumber()); - } - catch (Exception e) { - return 0; - } - } - }); - final Map numbers = new HashMap(); + private static Map computeLineNumbers(@NotNull FileAnnotation fileAnnotation) { + final Map numbers = new HashMap(); final List fileRevisionList = fileAnnotation.getRevisions(); if (fileRevisionList != null) { - revisions.addAll(fileRevisionList); - for (VcsFileRevision revision : fileRevisionList) { - final String revNumber = revision.getRevisionNumber().asString(); - if (!numbers.containsKey(revNumber)) { - final int num = revisions.indexOf(revision); - if (num != -1) { - numbers.put(revNumber, num + 1); - } - } + int size = fileRevisionList.size(); + for (int i = 0; i < size; i++) { + VcsFileRevision revision = fileRevisionList.get(i); + final VcsRevisionNumber number = revision.getRevisionNumber(); + + numbers.put(number, size - i); } } return numbers.size() < 2 ? null : numbers; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/HistoryIdColumn.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/HistoryIdColumn.java index e4cf739c39e9..5b4d50a58037 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/HistoryIdColumn.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/HistoryIdColumn.java @@ -29,13 +29,13 @@ import java.util.Map; * @author Konstantin Bulenkov */ class HistoryIdColumn extends AnnotationFieldGutter { - private final Map myHistoryIds; + private final Map myHistoryIds; HistoryIdColumn(FileAnnotation annotation, final Editor editor, final TextAnnotationPresentation presentation, Couple> colorScheme, - Map ids) { + Map ids) { super(annotation, editor, null, presentation, colorScheme); myHistoryIds = ids; } @@ -45,7 +45,7 @@ class HistoryIdColumn extends AnnotationFieldGutter { if (!isAvailable()) return ""; final VcsRevisionNumber revisionNumber = myAnnotation.getLineRevisionNumber(line); if (revisionNumber != null) { - final Integer num = myHistoryIds.get(revisionNumber.asString()); + final Integer num = myHistoryIds.get(revisionNumber); if (num != null) { final String size = String.valueOf(myHistoryIds.size()); String value = num.toString();