From 4cc374269cf90f221d712f563bede91c137c5a84 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Tue, 3 Dec 2013 16:01:01 +0400 Subject: [PATCH] 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 --- .../zmlx/hg4idea/repo/HgRepositoryReader.java | 16 ++++++++++------ .../src/org/zmlx/hg4idea/util/HgVersion.java | 5 +++++ .../testSrc/hg4idea/test/HgPlatformTest.java | 8 +++++--- .../test/repo/HgRealRepositoryReaderTest.java | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java index aaf7fb58e0eb..877725c0855a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java @@ -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 readBranches() { List branches = new ArrayList(); // Set branchNames = new HashSet(); - 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() { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java index 40da22a8aa99..5ee0faaae75d 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java @@ -54,6 +54,7 @@ public final class HgVersion implements Comparable { // 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 { 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. diff --git a/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java b/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java index 95c834c004b6..1b4519a8caa5 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/HgPlatformTest.java @@ -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); } diff --git a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java index 079a6d265268..306aade615ba 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java @@ -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;