git4idea: Added support for checking locally modified files
[fedora-idea.git] / plugins / git4idea / src / git4idea / GitRootConverter.java
blobccb7b9db38b9a2e4c149b000553a6cb643cf55a4
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package git4idea;
19 import com.intellij.openapi.vcs.AbstractVcs;
20 import com.intellij.openapi.vfs.VirtualFile;
21 import com.intellij.util.containers.HashSet;
23 import java.util.ArrayList;
24 import java.util.List;
26 /**
27 * The converter for the VCS roots
29 public class GitRootConverter implements AbstractVcs.RootsConvertor {
30 /**
31 * The static instance
33 public static final GitRootConverter INSTANCE = new GitRootConverter();
35 /**
36 * {@inheritDoc}
38 public List<VirtualFile> convertRoots(List<VirtualFile> result) {
39 // The method relies on the fact that VFS caches metadata about files,
40 // so the query should be relatively fast and work mostly with in-memory structures.
41 ArrayList<VirtualFile> roots = new ArrayList<VirtualFile>();
42 HashSet<VirtualFile> listed = new HashSet<VirtualFile>();
43 for (VirtualFile f : result) {
44 VirtualFile r = GitUtil.gitRootOrNull(f);
45 if (r != null && listed.add(r)) {
46 roots.add(r);
49 return roots;