From fd9268290257105e54d3790833aa3d2bd48d9425 Mon Sep 17 00:00:00 2001 From: Erokhin Stanislav Date: Wed, 26 Mar 2014 21:10:09 +0400 Subject: [PATCH] [log] Cosmetics changes in VcsLogJoiner. --- .../intellij/vcs/log/data/VcsLogJoiner.java | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogJoiner.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogJoiner.java index 607246865851..be43a590b394 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogJoiner.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogJoiner.java @@ -34,6 +34,9 @@ import java.util.*; public class VcsLogJoiner { private final static int BOUND_SAVED_LOG = 10000; + public final static String NOT_ENOUGH_FIRST_BLOCK = "Not enough first block"; + public final static String ILLEGAL_DATA_RELOAD_ALL = "All data is illegal - request reload all"; + /** * Attaches the block of latest commits, which was read from the VCS, to the existing log structure. * @@ -50,17 +53,11 @@ public class VcsLogJoiner { @NotNull Collection newRefs) { Set previousRefsHashes = toHashes(previousRefs); Set newRefsHashes = toHashes(newRefs); - Pair> redCommitsAndSavedRedIndex = - getRedCommitsAndSavedRedIndex(savedLog, previousRefsHashes, firstBlock, newRefsHashes); Pair> newCommitsAndSavedGreenIndex = getNewCommitsAndSavedGreenIndex(savedLog, previousRefsHashes, firstBlock, newRefsHashes); + Pair> redCommitsAndSavedRedIndex = + getRedCommitsAndSavedRedIndex(savedLog, previousRefsHashes, firstBlock, newRefsHashes); - if (redCommitsAndSavedRedIndex.first == -1) { // firstBlock not enough or remove old commits - throw new IllegalStateException(); //todo - } - else if (newCommitsAndSavedGreenIndex.first == -1) { - throw new IllegalStateException(); // todo - } Set removeCommits = redCommitsAndSavedRedIndex.second; Set allNewsCommits = newCommitsAndSavedGreenIndex.second; @@ -85,7 +82,6 @@ public class VcsLogJoiner { return hashes; } - // return Pair(-1, null) if something bad :'( @NotNull private static Pair> getNewCommitsAndSavedGreenIndex(@NotNull List savedLog, @NotNull Collection previousRefs, @@ -104,28 +100,28 @@ public class VcsLogJoiner { } } int saveGreenIndex = getFirstUnTrackedIndex(savedLog, allUnresolvedLinkedHashes); - if (saveGreenIndex == -1) - return new Pair>(-1, null); return new Pair>(saveGreenIndex, getAllNewCommits(savedLog.subList(0, saveGreenIndex), firstBlock)); } private static int getFirstUnTrackedIndex(@NotNull List commits, @NotNull Set searchHashes) { - int lastIndex = 0; - for (VcsCommit commit : commits) { + int lastIndex; + for (lastIndex = 0; lastIndex < commits.size(); lastIndex++) { + VcsCommit commit = commits.get(lastIndex); if (searchHashes.size() == 0) return lastIndex; if (lastIndex > BOUND_SAVED_LOG) - return -1; + throw new IllegalStateException(ILLEGAL_DATA_RELOAD_ALL); searchHashes.remove(commit.getHash()); - lastIndex++; } - return searchHashes.size() == 0 ? lastIndex : -1; + if (searchHashes.size() != 0) + throw new IllegalStateException(ILLEGAL_DATA_RELOAD_ALL); + return lastIndex; } private static Set getAllNewCommits(@NotNull List unsafeGreenPartSavedLog, @NotNull List firstBlock) { - Set existedCommitHashes = new HashSet(); + Set existedCommitHashes = ContainerUtil.newHashSet(); for (VcsCommit commit : unsafeGreenPartSavedLog) { existedCommitHashes.add(commit.getHash()); } @@ -138,7 +134,6 @@ public class VcsLogJoiner { return allNewsCommits; } - // return Pair(-1, null) if something bad :'( @NotNull private static Pair> getRedCommitsAndSavedRedIndex(@NotNull List savedLog, @NotNull Collection previousRefs, @@ -153,8 +148,6 @@ public class VcsLogJoiner { } RedGreenSorter sorter = new RedGreenSorter(startRedCommits, startGreenNodes, savedLog); int saveRegIndex = sorter.getFirstSaveIndex(); - if (saveRegIndex == -1) - return new Pair>(-1, null); return new Pair>(saveRegIndex, sorter.getAllRedCommit()); } @@ -173,31 +166,31 @@ public class VcsLogJoiner { } private void markRealRedNode(@NotNull Hash node) { - assert currentRed.remove(node) : "Red node isn't marked as red"; + if (!currentRed.remove(node)) + throw new IllegalStateException(NOT_ENOUGH_FIRST_BLOCK); allRedCommit.add(node); } - // return -1 if something bad private int getFirstSaveIndex() { - int lastIndex = 0; - for (TimedVcsCommit commit : savedLog) { + for (int lastIndex = 0; lastIndex < savedLog.size(); lastIndex++) { + TimedVcsCommit commit = savedLog.get(lastIndex); if (lastIndex > BOUND_SAVED_LOG) - return -1; + throw new IllegalStateException(ILLEGAL_DATA_RELOAD_ALL); - boolean isGreen = currentGreen.remove(commit.getHash()); + boolean isGreen = currentGreen.contains(commit.getHash()); if (isGreen) { currentRed.remove(commit.getHash()); currentGreen.addAll(commit.getParents()); - } else { + } + else { markRealRedNode(commit.getHash()); currentRed.addAll(commit.getParents()); } - lastIndex++; if (currentRed.isEmpty()) - return lastIndex; + return lastIndex + 1; } - return -1; + throw new IllegalStateException(ILLEGAL_DATA_RELOAD_ALL); } public Set getAllRedCommit() { @@ -206,7 +199,7 @@ public class VcsLogJoiner { } - /*package*/ static class NewCommitIntegrator { + static class NewCommitIntegrator { private final List list; private final Map newCommitsMap; @@ -256,6 +249,7 @@ public class VcsLogJoiner { } } + @NotNull public List getResultList() { insertAllUseStack(); return list;