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.
16 package git4idea
.changes
;
18 import com
.intellij
.openapi
.diagnostic
.Logger
;
19 import com
.intellij
.openapi
.fileEditor
.FileDocumentManager
;
20 import com
.intellij
.openapi
.progress
.ProgressIndicator
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.vcs
.*;
23 import com
.intellij
.openapi
.vcs
.changes
.*;
24 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import git4idea
.GitContentRevision
;
26 import git4idea
.GitRevisionNumber
;
27 import git4idea
.GitUtil
;
28 import git4idea
.GitVcs
;
29 import org
.jetbrains
.annotations
.NotNull
;
31 import java
.util
.Collection
;
32 import java
.util
.List
;
36 * Git repository change provider
38 public class GitChangeProvider
implements ChangeProvider
{
39 private static final Logger LOG
= Logger
.getInstance("#git4idea.changes.GitChangeProvider");
43 private final Project myProject
;
48 * @param project a project
50 public GitChangeProvider(@NotNull Project project
) {
57 public void getChanges(final VcsDirtyScope dirtyScope
,
58 final ChangelistBuilder builder
,
59 final ProgressIndicator progress
,
60 final ChangeListManagerGate addGate
) throws VcsException
{
61 final Collection
<VirtualFile
> affected
= dirtyScope
.getAffectedContentRoots();
62 Collection
<VirtualFile
> roots
= GitUtil
.gitRootsForPaths(affected
);
63 if (roots
.size() != affected
.size()) {
64 LOG
.info("affected content roots size: " + affected
.size() + " roots size: " + roots
.size());
67 final MyNonChangedHolder holder
= new MyNonChangedHolder(myProject
, dirtyScope
.getDirtyFilesNoExpand());
69 for (VirtualFile root
: roots
) {
70 ChangeCollector c
= new ChangeCollector(myProject
, dirtyScope
, root
);
71 final Collection
<Change
> changes
= c
.changes();
72 holder
.changed(changes
);
73 for (Change file
: changes
) {
74 builder
.processChange(file
, GitVcs
.getKey());
76 for (VirtualFile f
: c
.unversioned()) {
77 builder
.processUnversionedFile(f
);
79 holder
.feedBuilder(builder
);
83 private static class MyNonChangedHolder
{
84 private final Project myProject
;
85 private final Set
<FilePath
> myDirty
;
87 private MyNonChangedHolder(final Project project
, final Set
<FilePath
> dirty
) {
92 public void changed(final Collection
<Change
> changes
) {
93 for (Change change
: changes
) {
94 final FilePath beforePath
= ChangesUtil
.getBeforePath(change
);
95 if (beforePath
!= null) {
96 myDirty
.remove(beforePath
);
98 final FilePath afterPath
= ChangesUtil
.getBeforePath(change
);
99 if (afterPath
!= null) {
100 myDirty
.remove(afterPath
);
105 public void feedBuilder(final ChangelistBuilder builder
) throws VcsException
{
106 final VcsKey gitKey
= GitVcs
.getKey();
107 final ProjectLevelVcsManager vcsManager
= ProjectLevelVcsManager
.getInstance(myProject
);
108 final FileDocumentManager fileDocumentManager
= FileDocumentManager
.getInstance();
109 for (FilePath filePath
: myDirty
) {
110 final VirtualFile vf
= filePath
.getVirtualFile();
112 if (fileDocumentManager
.isFileModifiedAndDocumentUnsaved(vf
)) {
113 final VirtualFile root
= vcsManager
.getVcsRootFor(vf
);
115 final GitRevisionNumber beforeRevisionNumber
= GitChangeUtils
.loadRevision(myProject
, root
, "HEAD");
116 builder
.processChange(new Change(GitContentRevision
.createRevision(vf
, beforeRevisionNumber
, myProject
),
117 GitContentRevision
.createRevision(vf
, null, myProject
), FileStatus
.MODIFIED
), gitKey
);
128 public boolean isModifiedDocumentTrackingRequired() {
135 public void doCleanup(final List
<VirtualFile
> files
) {