From bcdcbc1edd6e245383406e9f3e44e41fd095dff6 Mon Sep 17 00:00:00 2001 From: Constantine Plotnikov Date: Fri, 15 May 2009 13:29:15 +0400 Subject: [PATCH] git4idea: implemented root converter for the git --- .../git4idea/src/git4idea/GitRootConverter.java | 51 ++++++++++++++++++++++ plugins/git4idea/src/git4idea/GitVcs.java | 8 ++++ 2 files changed, 59 insertions(+) create mode 100644 plugins/git4idea/src/git4idea/GitRootConverter.java diff --git a/plugins/git4idea/src/git4idea/GitRootConverter.java b/plugins/git4idea/src/git4idea/GitRootConverter.java new file mode 100644 index 0000000000..ccb7b9db38 --- /dev/null +++ b/plugins/git4idea/src/git4idea/GitRootConverter.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2009 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 git4idea; + +import com.intellij.openapi.vcs.AbstractVcs; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.HashSet; + +import java.util.ArrayList; +import java.util.List; + +/** + * The converter for the VCS roots + */ +public class GitRootConverter implements AbstractVcs.RootsConvertor { + /** + * The static instance + */ + public static final GitRootConverter INSTANCE = new GitRootConverter(); + + /** + * {@inheritDoc} + */ + public List convertRoots(List result) { + // The method relies on the fact that VFS caches metadata about files, + // so the query should be relatively fast and work mostly with in-memory structures. + ArrayList roots = new ArrayList(); + HashSet listed = new HashSet(); + for (VirtualFile f : result) { + VirtualFile r = GitUtil.gitRootOrNull(f); + if (r != null && listed.add(r)) { + roots.add(r); + } + } + return roots; + } +} diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index c57372b47d..1942470475 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -534,4 +534,12 @@ public class GitVcs extends AbstractVcs { } return in; } + + /** + * {@inheritDoc} + */ + @Override + public RootsConvertor getCustomConvertor() { + return GitRootConverter.INSTANCE; + } } \ No newline at end of file -- 2.11.4.GIT