mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[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.
This commit is contained in:
@@ -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.<Hash>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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Hash> myParents;
|
||||
private final long myTime;
|
||||
|
||||
public SimpleCommit(Hash commitHash, List<Hash> 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<Hash> getParents() {
|
||||
return myParents;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user