From ba4cf8d1b2d34d7bcf9c45ceb1358f121bec5c25 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sat, 28 Sep 2013 18:23:31 +0400 Subject: [PATCH] [log] create SimpleHash & SimpleCommit for tests to run w/o platform We could make graph tests to be UsefulTests instead, but it seems to be harder, and will slow down the tests. --- .../intellij/vcs/log/parser/CommitParser.java | 54 +++---------------- .../intellij/vcs/log/parser/SimpleCommit.java | 52 ++++++++++++++++++ .../intellij/vcs/log/parser/SimpleHash.java | 43 +++++++++++++++ 3 files changed, 101 insertions(+), 48 deletions(-) create mode 100644 platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleCommit.java create mode 100644 platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleHash.java diff --git a/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/CommitParser.java b/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/CommitParser.java index e2e4456961ca..877befc4a640 100644 --- a/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/CommitParser.java +++ b/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/CommitParser.java @@ -1,14 +1,14 @@ package com.intellij.vcs.log.parser; -import com.intellij.openapi.components.ServiceManager; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; -import com.intellij.vcs.log.*; +import com.intellij.vcs.log.Hash; +import com.intellij.vcs.log.TimedVcsCommit; +import com.intellij.vcs.log.VcsCommit; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; /** @@ -44,7 +44,7 @@ public class CommitParser { hashes.add(createHash(aParentsStr)); } } - return getFactory().createCommit(commitHash, hashes); + return new SimpleCommit(commitHash, hashes, -1); } /** @@ -69,49 +69,7 @@ public class CommitParser { } VcsCommit vcsCommit = parseCommitParents(line.substring(firstSeparatorIndex + 2)); - return getFactory().createTimedCommit(vcsCommit.getHash(), vcsCommit.getParents(), timestamp); - } - - /** - * @param line input format - * hash|-author name|-123124|-commit message - */ - @NotNull - public static VcsShortCommitDetails parseCommitData(@NotNull String line) { - int prevIndex = 0; - int nextIndex = nextSeparatorIndex(line, 0); - final String hashStr = line.substring(0, nextIndex); - - prevIndex = nextIndex; - nextIndex = nextSeparatorIndex(line, prevIndex + 1); - final String authorName = line.substring(prevIndex + 2, nextIndex); - - prevIndex = nextIndex; - nextIndex = nextSeparatorIndex(line, prevIndex + 1); - - String timestampStr = line.substring(prevIndex + 2, nextIndex); - final long timestamp; - try { - if (timestampStr.isEmpty()) { - timestamp = 0; - } - else { - timestamp = Long.parseLong(timestampStr); - } - } - catch (NumberFormatException e) { - throw new IllegalArgumentException("bad timestamp format: " + timestampStr + " in this Str: " + line); - } - - final String commitMessage = line.substring(nextIndex + 2); - - VcsLogObjectsFactory factory = getFactory(); - return factory.createShortDetails(factory.createHash(hashStr), Collections.emptyList(), timestamp, commitMessage, authorName); - } - - @NotNull - private static VcsLogObjectsFactory getFactory() { - return ServiceManager.getService(VcsLogObjectsFactory.class); + return new SimpleCommit(vcsCommit.getHash(), vcsCommit.getParents(), timestamp); } @NotNull @@ -126,7 +84,7 @@ public class CommitParser { @NotNull private static Hash createHash(@NotNull String s) { - return getFactory().createHash(s); + return new SimpleHash(s); } } diff --git a/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleCommit.java b/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleCommit.java new file mode 100644 index 000000000000..824880462eac --- /dev/null +++ b/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleCommit.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.vcs.log.parser; + +import com.intellij.vcs.log.Hash; +import com.intellij.vcs.log.TimedVcsCommit; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class SimpleCommit implements TimedVcsCommit { + + private final Hash myHash; + private final List myParents; + private final long myTime; + + public SimpleCommit(Hash commitHash, List parentHashes, long time) { + myHash = commitHash; + myParents = parentHashes; + myTime = time; + } + + @Override + public long getAuthorTime() { + return myTime; + } + + @NotNull + @Override + public Hash getHash() { + return myHash; + } + + @NotNull + @Override + public List getParents() { + return myParents; + } +} diff --git a/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleHash.java b/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleHash.java new file mode 100644 index 000000000000..92ad9e7a67f1 --- /dev/null +++ b/platform/vcs-log/graph/test/com/intellij/vcs/log/parser/SimpleHash.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.vcs.log.parser; + +import com.intellij.vcs.log.Hash; +import org.jetbrains.annotations.NotNull; + +/** + * @author Kirill Likhodedov + */ +class SimpleHash implements Hash { + + private final String myHash; + + public SimpleHash(String hash) { + myHash = hash; + } + + @NotNull + @Override + public String asString() { + return myHash; + } + + @NotNull + @Override + public String toShortString() { + return myHash.substring(0, 7); + } +}