summaryrefslogtreecommitdiff
path: root/plugins/hg4idea/src/org
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-06-07 11:05:24 -0700
committerTor Norbye <tnorbye@google.com>2013-06-07 11:05:24 -0700
commit28d9ee094b1d352884aaf5b66b85b30335165c03 (patch)
tree0d244ca64930b7b7cb92b260747c6e6d4616fe9c /plugins/hg4idea/src/org
parentec3fb1e06285c0467a7a20360ca80453bc7635d4 (diff)
downloadidea-28d9ee094b1d352884aaf5b66b85b30335165c03.tar.gz
Snapshot 621d3b6adc5a7cb6f13e27610aa33af48f13da27 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I3e2f8acd6054389626ab7c0f9065c8d905e99436
Diffstat (limited to 'plugins/hg4idea/src/org')
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoStateException.java30
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java84
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryFiles.java21
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java139
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java122
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryUpdater.java58
6 files changed, 84 insertions, 370 deletions
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoStateException.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoStateException.java
deleted file mode 100644
index 6bcc816053bb..000000000000
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoStateException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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 org.zmlx.hg4idea.repo;
-
-/**
- * @author Nadya Zabrodina
- */
-public class HgRepoStateException extends RuntimeException {
-
- public HgRepoStateException(String message) {
- super(message);
- }
-
- public HgRepoStateException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java
index b7feda1d6246..c250b50cf788 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java
@@ -16,87 +16,21 @@
package org.zmlx.hg4idea.repo;
-import com.intellij.openapi.project.Project;
+import com.intellij.dvcs.repo.Repository;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import java.util.Collection;
-/**
- * <p>
- * HgRepository is a representation of a Hg repository stored under the specified directory.
- * It stores the information about the repository, which is frequently requested by other plugin components.
- * All get-methods (like {@link #getCurrentRevision()}) are just getters of the correspondent fields and thus are very fast.
- * </p>
- * <p>
- * The HgRepository is updated "externally" by the {@link org.zmlx.hg4idea.repo.HgRepositoryUpdater}, when correspondent {@code .hg/} service files
- * change.
- * </p>
- * Other components may subscribe to HgRepository changes via the STATUS_TOPIC {@link com.intellij.util.messages.Topic}
- * </p>
- *
- * @author Nadya Zabrodina
- */
-
-public interface HgRepository {
-
- String DEFAULT_BRANCH = "default";
-
- /**
- * Current state of the repository.
- */
-
- enum State {
- /**
- * HEAD is on branch, no merge process is in progress.
- */
-
- NORMAL,
- /**
- * During merge (for instance, merge failed with conflicts that weren't immediately resolved).
- */
-
- MERGING {
- @Override
- public String toString() {
- return "Merging";
- }
- },
-
- }
-
- @NotNull
- VirtualFile getRoot();
+public interface HgRepository extends Repository {
+ @NotNull String DEFAULT_BRANCH = "default";
@NotNull
VirtualFile getHgDir();
- @NotNull
- String getPresentableUrl();
-
- @NotNull
- Project getProject();
-
-
- @NotNull
- State getState();
-
-
- /**
- * Returns the hash of the revision, which HEAD currently points to.
- * Returns null only in the case of a fresh repository, when no commit have been made.
- */
-
- @Nullable
- String getCurrentRevision();
-
/**
* Returns the current branch of this Hg repository.
- * If the repository is being rebased, then the current branch is the branch being rebased (which was current before the rebase
- * operation has started).
- * Returns null, if the repository is not on a branch and not in the REBASING state.
*/
@NotNull
@@ -104,16 +38,4 @@ public interface HgRepository {
@NotNull
Collection<String> getBranches();
-
- /**
- * @return true if current repository is "fresh", i.e. if no commits have been made yet.
- */
-
- boolean isFresh();
-
- /**
- * Updates the HgRepository by reading information from .hg dir...
- */
-
- void update();
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryFiles.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryFiles.java
index 2ccdbd016d42..fdddaba01125 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryFiles.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryFiles.java
@@ -30,22 +30,26 @@ import java.util.Collection;
*/
public class HgRepositoryFiles {
- public static final String BRANCHHEADS = "cache/branchheads";
+ public static final String BRANCHHEADS = "cache/branchheads"; // can be branchheads or branchheads-served after approx 2.5,
+ // so check for starting branchheads
+ public static final String BRANCHEADSDIR = "cache";
public static final String MERGE = "merge";
public static final String BRANCH = "branch";
- private final String myBranchHeadsPath;
- private final String myMergePath;
- private final String myBranchPath;
-
+ @NotNull private final String myBranchHeadsPath;
+ @NotNull private final String myBranchHeadsDirPath;
+ @NotNull private final String myMergePath;
+ @NotNull private final String myBranchPath;
+ @NotNull
public static HgRepositoryFiles getInstance(@NotNull VirtualFile hgDir) {
return new HgRepositoryFiles(hgDir);
}
private HgRepositoryFiles(@NotNull VirtualFile hgDir) {
myBranchHeadsPath = hgDir.getPath() + slash(BRANCHHEADS);
+ myBranchHeadsDirPath = hgDir.getPath() + slash(BRANCHEADSDIR);
myBranchPath = hgDir.getPath() + slash(BRANCH);
myMergePath = hgDir.getPath() + slash(MERGE);
}
@@ -63,13 +67,14 @@ public class HgRepositoryFiles {
return Arrays.asList(slash(BRANCHHEADS), slash(MERGE));
}
- public String getBranchHeadsPath() {
- return myBranchHeadsPath;
+ @NotNull
+ public String getBranchHeadsDirPath() {
+ return myBranchHeadsDirPath;
}
public boolean isbranchHeadsFile(String filePath) {
- return filePath.equals(myBranchHeadsPath);
+ return filePath.startsWith(myBranchHeadsPath);
}
public boolean isBranchFile(String filePath) {
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java
index 75b8c3fe4345..339fe28ba5e7 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java
@@ -16,16 +16,13 @@
package org.zmlx.hg4idea.repo;
+import com.intellij.dvcs.repo.RepositoryImpl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.Consumer;
-import com.intellij.util.concurrency.QueueProcessor;
-import com.intellij.util.messages.MessageBus;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.HgVcs;
import org.zmlx.hg4idea.util.HgUtil;
@@ -37,45 +34,29 @@ import java.util.List;
* @author Nadya Zabrodina
*/
-public class HgRepositoryImpl implements HgRepository, Disposable {
+public class HgRepositoryImpl extends RepositoryImpl implements HgRepository {
- private static final Object STUB_OBJECT = new Object();
+ @NotNull private final HgRepositoryReader myReader;
+ @NotNull private final VirtualFile myHgDir;
- private final Project myProject;
- private final VirtualFile myRootDir;
- private final HgRepositoryReader myReader;
- private final VirtualFile myHgDir;
- private final QueueProcessor<Object> myNotifier;
-
- @NotNull private volatile State myState = State.NORMAL;
- @Nullable private volatile String myCurrentRevision = null;
@NotNull private volatile String myCurrentBranch = DEFAULT_BRANCH;
@NotNull private volatile List<String> myBranches = Collections.emptyList();
+ private boolean myIsFresh = true;
- /*
- * Get the HgRepository instance from the {@link HgRepositoryManager}.
- * If you need to have an instance of HgRepository for a repository outside the project, use
- * {@link #getLightInstance(com.intellij.openapi.vfs.VirtualFile, com.intellij.openapi.project.Project, PlatformFacade, com.intellij.openapi.Disposable)}.
-
- */
+ @SuppressWarnings("ConstantConditions")
protected HgRepositoryImpl(@NotNull VirtualFile rootDir, @NotNull Project project,
@NotNull Disposable parentDisposable) {
- myRootDir = rootDir;
- myProject = project;
- Disposer.register(parentDisposable, this);
-
- myHgDir = myRootDir.findChild(HgUtil.DOT_HG);
+ super(project, rootDir, parentDisposable);
+ myHgDir = rootDir.findChild(HgUtil.DOT_HG);
assert myHgDir != null : ".hg directory wasn't found under " + rootDir.getPresentableUrl();
-
+ myState = State.NORMAL;
+ myCurrentRevision = null;
myReader = new HgRepositoryReader(VfsUtilCore.virtualToIoFile(myHgDir));
-
- MessageBus messageBus = project.getMessageBus();
- myNotifier = new QueueProcessor<Object>(new NotificationConsumer(myProject, messageBus, this), myProject.getDisposed());
update();
}
-
+ @NotNull
public static HgRepository getFullInstance(@NotNull VirtualFile root, @NotNull Project project,
@NotNull Disposable parentDisposable) {
HgRepositoryImpl repository = new HgRepositoryImpl(root, project, parentDisposable);
@@ -88,48 +69,12 @@ public class HgRepositoryImpl implements HgRepository, Disposable {
Disposer.register(this, updater);
}
- @Override
- public void dispose() {
- }
-
- @Override
- @NotNull
- public VirtualFile getRoot() {
- return myRootDir;
- }
-
@NotNull
@Override
public VirtualFile getHgDir() {
return myHgDir;
}
-
- @Override
- @NotNull
- public String getPresentableUrl() {
- return getRoot().getPresentableUrl();
- }
-
- @Override
- @NotNull
- public Project getProject() {
- return myProject;
- }
-
-
- @Override
- @NotNull
- public State getState() {
- return myState;
- }
-
- @Override
- @Nullable
- public String getCurrentRevision() {
- return myCurrentRevision;
- }
-
@Override
@NotNull
public String getCurrentBranch() {
@@ -146,16 +91,25 @@ public class HgRepositoryImpl implements HgRepository, Disposable {
@Override
public boolean isFresh() {
- return !myReader.headExist();
+ return myIsFresh;
}
@Override
public void update() {
readRepository();
- notifyListeners();
+ if (!Disposer.isDisposed(getProject())) {
+ getMessageBus().syncPublisher(HgVcs.STATUS_TOPIC).update(getProject(), getRoot());
+ }
+ }
+
+ @Override
+ public String toLogString() {
+ return String.format("HgRepository{myCurrentBranch=%s, myCurrentRevision='%s', myState=%s, myRootDir=%s}",
+ myCurrentBranch, myCurrentRevision, myState, getRoot());
}
private void readRepository() {
+ myIsFresh = myIsFresh && myReader.checkIsFresh(); //if repository not fresh - it will be not fresh all time
if (!isFresh()) {
myState = myReader.readState();
myCurrentRevision = myReader.readCurrentRevision();
@@ -163,53 +117,4 @@ public class HgRepositoryImpl implements HgRepository, Disposable {
myBranches = myReader.readBranches();
}
}
-
- protected void notifyListeners() {
- myNotifier.add(STUB_OBJECT); // we don't have parameters for listeners
- }
-
- private static class NotificationConsumer implements Consumer<Object> {
-
- private final Project myProject;
- private final MessageBus myMessageBus;
- private final HgRepository myRepository;
-
- NotificationConsumer(Project project, MessageBus messageBus, HgRepository repository) {
- myProject = project;
- myMessageBus = messageBus;
- myRepository = repository;
- }
-
- @Override
- public void consume(Object o) {
- if (!Disposer.isDisposed(myProject)) {
- myMessageBus.syncPublisher(HgVcs.STATUS_TOPIC).update(myProject, myRepository.getRoot());
- }
- }
- }
-
- @Override
- public String toString() {
- return getPresentableUrl();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- HgRepositoryImpl that = (HgRepositoryImpl)o;
-
- if (!myProject.equals(that.myProject)) return false;
- if (!myRootDir.equals(that.myRootDir)) return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = myProject.hashCode();
- result = 31 * result + (myRootDir.hashCode());
- return result;
- }
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java
index e6d8820d28e0..0ee66e2ec7c3 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java
@@ -15,53 +15,51 @@
*/
package org.zmlx.hg4idea.repo;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.dvcs.repo.RepoStateException;
+import com.intellij.dvcs.repo.Repository;
+import com.intellij.dvcs.repo.RepositoryUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Reads information about the Hg repository from Hg service files located in the {@code .hg} folder.
* NB: works with {@link java.io.File}, i.e. reads from disk. Consider using caching.
- * Throws a {@link HgRepoStateException} in the case of incorrect Hg file format.
+ * Throws a {@link RepoStateException} in the case of incorrect Hg file format.
*
* @author Nadya Zabrodina
*/
-class HgRepositoryReader {
+public class HgRepositoryReader {
- private static final Logger LOG = Logger.getInstance(HgRepositoryReader.class);
private static Pattern BRANCH_PATTERN = Pattern.compile("\\s*(.+)\\s+(.+)");
- private static final int IO_RETRIES = 3; // number of retries before fail if an IOException happens during file read.
+ @NotNull private final File myHgDir; // .hg
+ @NotNull private final File myBranchHeadsFile; // .hg/cache/branchheads (does not exist before first commit)
+ @NotNull private final File myCurrentBranch; // .hg/branch
- private final File myHgDir; // .hg/
- private final File myBranchHeadsFile; // .hg/cache/branchheads - this file does not exist before first commit
- private final File myCurrentBranch; // .hg/branch
-
- HgRepositoryReader(@NotNull File hgDir) {
+ public HgRepositoryReader(@NotNull File hgDir) {
myHgDir = hgDir;
- assertFileExists(myHgDir, ".hg directory not found in " + hgDir);
- myBranchHeadsFile = new File(new File(myHgDir, "cache"), "branchheads");
+ 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,
+ //before 2.5 only branchheads exist
+ myBranchHeadsFile = branchesFile.exists() ? branchesFile : new File(new File(myHgDir, "cache"), "branchheads");
myCurrentBranch = new File(myHgDir, "branch");
}
-
/**
* Finds current revision value.
*
* @return The current revision hash, or <b>{@code null}</b> if current revision is unknown - it is the initial repository state.
*/
@Nullable
- String readCurrentRevision() {
- String[] branchesWithHeads = tryLoadFile(myBranchHeadsFile).trim().split("\n");
+ public String readCurrentRevision() {
+ if (checkIsFresh()) return null;
+ String[] branchesWithHeads = RepositoryUtil.tryLoadFile(myBranchHeadsFile).split("\n");
String head = branchesWithHeads[0];
Matcher matcher = BRANCH_PATTERN.matcher(head);
if (matcher.matches()) {
@@ -74,89 +72,37 @@ class HgRepositoryReader {
* Return current branch
*/
@NotNull
- String readCurrentBranch() {
- if (branchExist()) {
- String rev = tryLoadFile(myCurrentBranch);
- return rev.trim();
- }
- return HgRepository.DEFAULT_BRANCH;
+ public String readCurrentBranch() {
+ return branchExist() ? RepositoryUtil.tryLoadFile(myCurrentBranch) : HgRepository.DEFAULT_BRANCH;
}
-
- List<String> readBranches() {
+ @NotNull
+ public List<String> readBranches() {
List<String> branches = new ArrayList<String>();
- String[] branchesWithHeads = tryLoadFile(myBranchHeadsFile).trim().split("\n");
- // first one - is a head revision: head hash + head number;
- for (int i = 1; i < branchesWithHeads.length; ++i) {
- Matcher matcher = BRANCH_PATTERN.matcher(branchesWithHeads[i]);
- if (matcher.matches()) {
- branches.add(matcher.group(2));
+ if (!checkIsFresh()) {
+ 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) {
+ Matcher matcher = BRANCH_PATTERN.matcher(branchesWithHeads[i]);
+ if (matcher.matches()) {
+ branches.add(matcher.group(2));
+ }
}
}
return branches;
}
-
- private static void assertFileExists(File file, String message) {
- if (!file.exists()) {
- throw new HgRepoStateException(message);
- }
+ public boolean isMergeInProgress() {
+ return new File(myHgDir, "merge").exists();
}
- /**
- * Loads the file content.
- * Tries 3 times, then a {@link HgRepoStateException} is thrown.
- *
- * @param file File to read.
- * @return file content.
- */
@NotNull
- private static String tryLoadFile(final File file) {
- return tryOrThrow(new Callable<String>() {
- @Override
- public String call() throws Exception {
- return FileUtil.loadFile(file);
- }
- }, file);
- }
-
- /**
- * Tries to execute the given action.
- * If an IOException happens, tries again up to 3 times, and then throws a {@link HgRepoStateException}.
- * If an other exception happens, rethrows it as a {@link HgRepoStateException}.
- * In the case of success returns the result of the task execution.
- */
- private static String tryOrThrow(Callable<String> actionToTry, File fileToLoad) {
- IOException cause = null;
- for (int i = 0; i < IO_RETRIES; i++) {
- try {
- return actionToTry.call();
- }
- catch (IOException e) {
- LOG.info("IOException while loading " + fileToLoad, e);
- cause = e;
- }
- catch (Exception e) { // this shouldn't happen since only IOExceptions are thrown in clients.
- throw new HgRepoStateException("Couldn't load file " + fileToLoad, e);
- }
- }
- throw new HgRepoStateException("Couldn't load file " + fileToLoad, cause);
- }
-
- public HgRepository.State readState() {
- if (isMergeInProgress()) {
- return HgRepository.State.MERGING;
- }
- return HgRepository.State.NORMAL;
- }
-
- private boolean isMergeInProgress() {
- File mergeFile = new File(myHgDir, "merge");
- return mergeFile.exists();
+ public Repository.State readState() {
+ return isMergeInProgress() ? Repository.State.MERGING : Repository.State.NORMAL;
}
- public boolean headExist() {
- return myBranchHeadsFile.exists();
+ public boolean checkIsFresh() {
+ return !myBranchHeadsFile.exists();
}
public boolean branchExist() {
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryUpdater.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryUpdater.java
index e44213af5fe2..22983e18e05b 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryUpdater.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryUpdater.java
@@ -15,16 +15,14 @@
*/
package org.zmlx.hg4idea.repo;
+import com.intellij.dvcs.repo.RepositoryUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
-import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
-import com.intellij.util.Consumer;
-import com.intellij.util.Processor;
import com.intellij.util.concurrency.QueueProcessor;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.vcsUtil.VcsUtil;
@@ -39,24 +37,24 @@ import java.util.List;
* @author Nadya Zabrodina
*/
final class HgRepositoryUpdater implements Disposable, BulkFileListener {
- private final HgRepositoryFiles myRepositoryFiles;
- private final MessageBusConnection myMessageBusConnection;
- private final QueueProcessor<Object> myUpdateQueue;
- private final Object DUMMY_UPDATE_OBJECT = new Object();
- private final VirtualFile myBranchHeadsDir;
- private final LocalFileSystem.WatchRequest myWatchRequest;
+ @NotNull private final HgRepositoryFiles myRepositoryFiles;
+ @Nullable private final MessageBusConnection myMessageBusConnection;
+ @NotNull private final QueueProcessor<Object> myUpdateQueue;
+ @NotNull private final Object DUMMY_UPDATE_OBJECT = new Object();
+ @Nullable private final VirtualFile myBranchHeadsDir;
+ @Nullable private final LocalFileSystem.WatchRequest myWatchRequest;
- HgRepositoryUpdater(HgRepository repository) {
+ HgRepositoryUpdater(@NotNull HgRepository repository) {
VirtualFile hgDir = repository.getHgDir();
myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(hgDir.getPath(), true);
myRepositoryFiles = HgRepositoryFiles.getInstance(hgDir);
- visitHgDirVfs(hgDir);
+ RepositoryUtil.visitVcsDirVfs(hgDir, HgRepositoryFiles.getSubDirRelativePaths());
- myBranchHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getBranchHeadsPath());
+ myBranchHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getBranchHeadsDirPath());
Project project = repository.getProject();
- myUpdateQueue = new QueueProcessor<Object>(new Updater(repository), project.getDisposed());
+ myUpdateQueue = new QueueProcessor<Object>(new RepositoryUtil.Updater(repository), project.getDisposed());
if (!project.isDisposed()) {
myMessageBusConnection = project.getMessageBus().connect();
myMessageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, this);
@@ -66,26 +64,6 @@ final class HgRepositoryUpdater implements Disposable, BulkFileListener {
}
}
- private static void visitHgDirVfs(@NotNull VirtualFile hgDir) {
- hgDir.getChildren();
- for (String subdir : HgRepositoryFiles.getSubDirRelativePaths()) {
- VirtualFile dir = hgDir.findFileByRelativePath(subdir);
- // process recursively, because we need to visit all branches under cache/branchheads
- visitAllChildrenRecursively(dir);
- }
- }
-
- private static void visitAllChildrenRecursively(@Nullable VirtualFile dir) {
- if (dir == null) {
- return;
- }
- VfsUtil.processFilesRecursively(dir, new Processor<VirtualFile>() {
- @Override
- public boolean process(VirtualFile virtualFile) {
- return true;
- }
- });
- }
@Override
public void dispose() {
@@ -118,7 +96,7 @@ final class HgRepositoryUpdater implements Disposable, BulkFileListener {
}
else if (myRepositoryFiles.isBranchFile(filePath)) {
branchFileChanged = true;
- visitAllChildrenRecursively(myBranchHeadsDir);
+ RepositoryUtil.visitAllChildrenRecursively(myBranchHeadsDir);
}
else if (myRepositoryFiles.isMergeFile(filePath)) {
mergeFileChanged = true;
@@ -131,16 +109,4 @@ final class HgRepositoryUpdater implements Disposable, BulkFileListener {
}
}
- private static class Updater implements Consumer<Object> {
- private final HgRepository myRepository;
-
- public Updater(HgRepository repository) {
- myRepository = repository;
- }
-
- @Override
- public void consume(Object dummy) {
- myRepository.update();
- }
- }
}