unnecessary methods from HgVersion deleted; HgVcs used instead of project; IllegalArgumentException thrown instead if assertion

This commit is contained in:
Nadya Zabrodina
2014-02-16 18:56:25 +04:00
parent 9ae90ef324
commit f0320f824b
5 changed files with 24 additions and 26 deletions
@@ -53,20 +53,24 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository {
@SuppressWarnings("ConstantConditions")
private HgRepositoryImpl(@NotNull VirtualFile rootDir, @NotNull Project project,
private HgRepositoryImpl(@NotNull VirtualFile rootDir, @NotNull HgVcs vcs,
@NotNull Disposable parentDisposable) {
super(project, rootDir, parentDisposable);
super(vcs.getProject(), rootDir, parentDisposable);
myHgDir = rootDir.findChild(HgUtil.DOT_HG);
assert myHgDir != null : ".hg directory wasn't found under " + rootDir.getPresentableUrl();
myReader = new HgRepositoryReader(project, VfsUtilCore.virtualToIoFile(myHgDir));
myConfig = HgConfig.getInstance(project, rootDir);
myReader = new HgRepositoryReader(vcs, VfsUtilCore.virtualToIoFile(myHgDir));
myConfig = HgConfig.getInstance(getProject(), rootDir);
update();
}
@NotNull
public static HgRepository getInstance(@NotNull VirtualFile root, @NotNull Project project,
@NotNull Disposable parentDisposable) {
HgRepositoryImpl repository = new HgRepositoryImpl(root, project, parentDisposable);
HgVcs vcs = HgVcs.getInstance(project);
if (vcs == null) {
throw new IllegalArgumentException("Vcs not found for project " + project);
}
HgRepositoryImpl repository = new HgRepositoryImpl(root, vcs, parentDisposable);
repository.setupUpdater();
return repository;
}
@@ -19,7 +19,6 @@ import com.intellij.dvcs.repo.RepoStateException;
import com.intellij.dvcs.repo.Repository;
import com.intellij.dvcs.repo.RepositoryUtil;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.VcsLogObjectsFactory;
import org.jetbrains.annotations.NotNull;
@@ -57,11 +56,9 @@ public class HgRepositoryReader {
@NotNull private final VcsLogObjectsFactory myVcsObjectsFactory;
private final boolean myStatusInBranchFile;
public HgRepositoryReader(@NotNull Project project, @NotNull File hgDir) {
public HgRepositoryReader(@NotNull HgVcs vcs, @NotNull File hgDir) {
myHgDir = hgDir;
RepositoryUtil.assertFileExists(myHgDir, ".hg directory not found in " + myHgDir);
HgVcs vcs = HgVcs.getInstance(project);
assert vcs != null : "Vcs not found for project " + project;
HgVersion version = vcs.getVersion();
myStatusInBranchFile = version.hasBranch2Served();
myCacheDir = new File(myHgDir, "cache");
@@ -71,7 +68,7 @@ public class HgRepositoryReader {
myCurrentBookmark = new File(myHgDir, "bookmarks.current");
myLocalTagsFile = new File(myHgDir, "localtags");
myTagsFile = new File(myHgDir.getParentFile(), ".hgtags");
myVcsObjectsFactory = ServiceManager.getService(project, VcsLogObjectsFactory.class);
myVcsObjectsFactory = ServiceManager.getService(vcs.getProject(), VcsLogObjectsFactory.class);
}
/**
@@ -80,9 +77,10 @@ public class HgRepositoryReader {
@NotNull
private static File identifyBranchHeadFile(@NotNull HgVersion version, @NotNull File parentCacheFile) {
//before 2.5 only branchheads exist; branchheads-served after mercurial 2.5; branch2-served after 2.9;
return version.hasBranch2Served()
? new File(parentCacheFile, "branch2-served")
: version.hasBranchHeadsServed() ? new File(parentCacheFile, "branchheads-served") : new File(parentCacheFile, "branchheads");
String branchFileName = version.hasBranch2Served()
? "branch2-served"
: version.hasBranchHeadsServed() ? "branchheads-served" : "branchheads";
return new File(parentCacheFile, branchFileName);
}
/**
@@ -144,31 +144,31 @@ public final class HgVersion implements Comparable<HgVersion> {
* @return true if the version is supported by the plugin
*/
public boolean isSupported() {
return !isNull() && compareTo(MIN) >= 0;
return compareTo(MIN) >= 0;
}
public boolean isAmendSupported() {
return !isNull() && compareTo(AMEND_SUPPORTED) >= 0;
return compareTo(AMEND_SUPPORTED) >= 0;
}
public boolean isBuiltInFunctionSupported() {
return !isNull() && compareTo(BUILT_IN_FUNCTION_SUPPORTED) >= 0;
return compareTo(BUILT_IN_FUNCTION_SUPPORTED) >= 0;
}
public boolean isLargeFilesWithFollowSupported() {
return !isNull() && compareTo(LARGEFILES_WITH_FOLLOW_SUPPORTED) >= 0;
return compareTo(LARGEFILES_WITH_FOLLOW_SUPPORTED) >= 0;
}
public boolean isParentRevisionTemplateSupported() {
return !isNull() && compareTo(PARENT_REVISION_TEMPLATES_SUPPORTED) >= 0;
return compareTo(PARENT_REVISION_TEMPLATES_SUPPORTED) >= 0;
}
public boolean hasBranchHeadsServed() {
return !isNull() && compareTo(BRANCH_HEADS_SERVED_FILE_EXIST) >= 0 && compareTo(BRANCH2_SERVED_FILE_EXIST) < 0;
return compareTo(BRANCH_HEADS_SERVED_FILE_EXIST) >= 0 && compareTo(BRANCH2_SERVED_FILE_EXIST) < 0;
}
public boolean hasBranch2Served() {
return !isNull() && compareTo(BRANCH2_SERVED_FILE_EXIST) >= 0;
return compareTo(BRANCH2_SERVED_FILE_EXIST) >= 0;
}
public boolean hasUnsupportedExtensions() {
@@ -221,8 +221,4 @@ public final class HgVersion implements Comparable<HgVersion> {
public String toString() {
return myMajor + "." + myMiddle + "." + myMinor;
}
public boolean isNull() {
return myMajor == 0 && myMiddle == 0 && myMinor == 0;
}
}
@@ -43,7 +43,7 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest {
File hgDir = new File(myRepository.getPath(), ".hg");
assertTrue(hgDir.exists());
createBranchesAndTags();
myRepositoryReader = new HgRepositoryReader(myProject, hgDir);
myRepositoryReader = new HgRepositoryReader(myVcs, hgDir);
}
public void testMergeState() {
@@ -63,7 +63,7 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
FileUtil.copy(testTagFile, new File(myHgDir.getParentFile(), ".hgtags"));
FileUtil.copy(testLocalTagFile, new File(myHgDir, "localtags"));
myRepositoryReader = new HgRepositoryReader(myProject, myHgDir);
myRepositoryReader = new HgRepositoryReader(myVcs, myHgDir);
myBranches = readBranches();
myBookmarks = readRefs(testBookmarkFile);
myTags = readRefs(testTagFile);