IDEA-115906 Throwable ; IDEA-117401 IAE fixed

*update isFresh method for repository;
*hgVersion used for appropriate branchheads file detection;
*tests updated;
*additional checks inserted in HgRepositoryReader for migrating between hg versions
This commit is contained in:
Nadya Zabrodina
2013-12-03 16:08:41 +04:00
parent 7793e6fabe
commit 4cc374269c
4 changed files with 21 additions and 9 deletions
@@ -24,6 +24,7 @@ import com.intellij.vcs.log.VcsLogObjectsFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgNameWithHashInfo;
import org.zmlx.hg4idea.HgVcs;
import java.io.File;
import java.util.*;
@@ -42,7 +43,8 @@ public class HgRepositoryReader {
private static Pattern HASH_NAME = Pattern.compile("\\s*([0-9a-fA-F]+)\\s+(.+)");
@NotNull private final File myHgDir; // .hg
@NotNull private final File myBranchHeadsFile; // .hg/cache/branchheads (does not exist before first commit)
@NotNull private final File myBranchHeadsFile; // .hg/cache/branchheads
@NotNull private final File myCacheDir; // .hg/cache (does not exist before first commit)
@NotNull private final File myCurrentBranch; // .hg/branch
@NotNull private final File myBookmarksFile; //.hg/bookmarks
@NotNull private final File myCurrentBookmark; //.hg/bookmarks.current
@@ -53,9 +55,11 @@ public class HgRepositoryReader {
public HgRepositoryReader(@NotNull Project project, @NotNull File hgDir) {
myHgDir = hgDir;
RepositoryUtil.assertFileExists(myHgDir, ".hg directory not found in " + myHgDir);
File branchesFile = new File(new File(myHgDir, "cache"), "branchheads-served"); //branchheads-served exist after mercurial 2.5,
myCacheDir = new File(myHgDir, "cache");
File branchesFile = new File(myCacheDir, "branchheads-served"); //branchheads-served exist after mercurial 2.5,
//before 2.5 only branchheads exist
myBranchHeadsFile = branchesFile.exists() ? branchesFile : new File(new File(myHgDir, "cache"), "branchheads");
HgVcs vcs = HgVcs.getInstance(project);
myBranchHeadsFile = vcs != null && vcs.getVersion().hasBranchHeadsServed() ? branchesFile : new File(myCacheDir, "branchheads");
myCurrentBranch = new File(myHgDir, "branch");
myBookmarksFile = new File(myHgDir, "bookmarks");
myCurrentBookmark = new File(myHgDir, "bookmarks.current");
@@ -71,7 +75,7 @@ public class HgRepositoryReader {
*/
@Nullable
public String readCurrentRevision() {
if (checkIsFresh()) return null;
if (checkIsFresh() || !myBranchHeadsFile.exists()) return null;
String[] branchesWithHeads = RepositoryUtil.tryLoadFile(myBranchHeadsFile).split("\n");
String head = branchesWithHeads[0];
Matcher matcher = HASH_NAME.matcher(head);
@@ -93,7 +97,7 @@ public class HgRepositoryReader {
public Collection<HgNameWithHashInfo> readBranches() {
List<HgNameWithHashInfo> branches = new ArrayList<HgNameWithHashInfo>();
// Set<String> branchNames = new HashSet<String>();
if (!checkIsFresh()) {
if (!checkIsFresh() && myBranchHeadsFile.exists()) {
String[] branchesWithHeads = RepositoryUtil.tryLoadFile(myBranchHeadsFile).split("\n");
// first one - is a head revision: head hash + head number;
for (int i = 1; i < branchesWithHeads.length; ++i) {
@@ -119,7 +123,7 @@ public class HgRepositoryReader {
}
public boolean checkIsFresh() {
return !myBranchHeadsFile.exists();
return !myCacheDir.exists();
}
public boolean branchExist() {
@@ -54,6 +54,7 @@ public final class HgVersion implements Comparable<HgVersion> {
// see http://mercurial.808500.n3.nabble.com/Bug-3887-New-hg-log-template-quot-rev-join-file-copies-n-quot-prints-literal-quot-sourcename-quot-fos-td4000129.html
public static final HgVersion BUILT_IN_FUNCTION_SUPPORTED = new HgVersion(2, 6, 0);
public static final HgVersion PARENT_REVISION_TEMPLATES_SUPPORTED = new HgVersion(2, 4, 0);
public static final HgVersion BRANCH_HEADS_SERVED_FILE_EXIST = new HgVersion(2, 5, 0);
//see http://selenic.com/pipermail/mercurial-devel/2013-May/051209.html fixed since 2.7
private static final HgVersion LARGEFILES_WITH_FOLLOW_SUPPORTED = new HgVersion(2, 7, 0);
@@ -157,6 +158,10 @@ public final class HgVersion implements Comparable<HgVersion> {
return !isNull() && compareTo(PARENT_REVISION_TEMPLATES_SUPPORTED) >= 0;
}
public boolean hasBranchHeadsServed() {
return !isNull() && compareTo(BRANCH_HEADS_SERVED_FILE_EXIST) >= 0;
}
/**
* Note: this class has a natural ordering that is inconsistent with equals.
* Two HgVersions are equal if their number versions are equal.
@@ -55,6 +55,7 @@ public abstract class HgPlatformTest extends UsefulTestCase {
protected VirtualFile myProjectRoot;
protected VirtualFile myRepository;
protected VirtualFile myChildRepo;
protected HgVcs myVcs;
protected static final String COMMIT_MESSAGE = "text";
@@ -79,9 +80,10 @@ public abstract class HgPlatformTest extends UsefulTestCase {
hg("version");
createRepository(myProjectRoot);
HgVcs hgVcs = HgVcs.getInstance(myProject);
assertNotNull(hgVcs);
hgVcs.getGlobalSettings().setHgExecutable(HgExecutor.getHgExecutable());
myVcs = HgVcs.getInstance(myProject);
assertNotNull(myVcs);
myVcs.getGlobalSettings().setHgExecutable(HgExecutor.getHgExecutable());
myVcs.checkVersion();
myRepository = myProjectRoot;
setUpHgrc(myRepository);
}
@@ -19,6 +19,7 @@ import com.intellij.dvcs.repo.Repository;
import com.intellij.openapi.vcs.VcsTestUtil;
import hg4idea.test.HgPlatformTest;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.HgVcs;
import org.zmlx.hg4idea.repo.HgRepositoryReader;
import org.zmlx.hg4idea.util.HgUtil;