9ef77863a96d24d7072aa7c09a58ea2d9651fb99
[idea/community.git] / plugins / git4idea / src / git4idea / changes / GitChangeProvider.java
1 package git4idea.changes;
2 /*
3  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at:
5  *
6  *   http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
9  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
10  * the specific language governing permissions and limitations under the License.
11  *
12  * Copyright 2007 Decentrix Inc
13  * Copyright 2007 Aspiro AS
14  * Copyright 2008 MQSoftware
15  * Copyright 2008 JetBrains s.r.o.
16  * Authors: gevession, Erlend Simonsen & Mark Scott
17  *
18  * This code was originally derived from the MKS & Mercurial IDEA VCS plugins
19  */
20
21 import com.intellij.openapi.progress.ProgressIndicator;
22 import com.intellij.openapi.project.Project;
23 import com.intellij.openapi.vcs.VcsException;
24 import com.intellij.openapi.vcs.changes.*;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import git4idea.GitUtil;
27 import git4idea.GitVcs;
28 import org.jetbrains.annotations.NotNull;
29
30 import java.util.Collection;
31 import java.util.List;
32
33 /**
34  * Git repository change provider
35  */
36 public class GitChangeProvider implements ChangeProvider {
37   /**
38    * the project
39    */
40   private final Project myProject;
41
42   /**
43    * A constructor
44    *
45    * @param project a project
46    */
47   public GitChangeProvider(@NotNull Project project) {
48     myProject = project;
49   }
50
51   /**
52    * {@inheritDoc}
53    */
54   public void getChanges(final VcsDirtyScope dirtyScope,
55                          final ChangelistBuilder builder,
56                          final ProgressIndicator progress,
57                          final ChangeListManagerGate addGate) throws VcsException {
58     Collection<VirtualFile> roots = GitUtil.gitRootsForPaths(dirtyScope.getAffectedContentRoots());
59     for (VirtualFile root : roots) {
60       ChangeCollector c = new ChangeCollector(myProject, dirtyScope, root);
61       for (Change file : c.changes()) {
62         builder.processChange(file, GitVcs.getKey());
63       }
64       for (VirtualFile f : c.unversioned()) {
65         builder.processUnversionedFile(f);
66       }
67     }
68   }
69
70   /**
71    * {@inheritDoc}
72    */
73   public boolean isModifiedDocumentTrackingRequired() {
74     return false;
75   }
76
77   /**
78    * {@inheritDoc}
79    */
80   public void doCleanup(final List<VirtualFile> files) {
81   }
82
83 }