1 package com
.intellij
.openapi
.vcs
.changes
;
3 import com
.intellij
.openapi
.application
.ApplicationManager
;
4 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
5 import com
.intellij
.openapi
.util
.Getter
;
6 import com
.intellij
.openapi
.vcs
.FilePath
;
7 import com
.intellij
.openapi
.vcs
.FilePathImpl
;
8 import com
.intellij
.openapi
.vcs
.VcsKey
;
9 import com
.intellij
.openapi
.vcs
.impl
.ExcludedFileIndex
;
10 import com
.intellij
.openapi
.vfs
.VirtualFile
;
11 import org
.jetbrains
.annotations
.Nullable
;
13 class UpdatingChangeListBuilder
implements ChangelistBuilder
{
14 private final ChangeListWorker myChangeListWorker
;
15 private final FileHolderComposite myComposite
;
17 private final Getter
<Boolean
> myDisposedGetter
;
18 private VcsDirtyScope myScope
;
19 private FoldersCutDownWorker myFoldersCutDownWorker
;
20 private final boolean myUpdateUnversioned
;
21 private final IgnoredFilesComponent myIgnoredFilesComponent
;
22 private final ExcludedFileIndex myIndex
;
23 private final ChangeListManagerGate myGate
;
25 UpdatingChangeListBuilder(final ChangeListWorker changeListWorker
,
26 final FileHolderComposite composite
,
27 final Getter
<Boolean
> disposedGetter
,
28 final boolean updateUnversioned
,
29 final IgnoredFilesComponent ignoredFilesComponent
, final ChangeListManagerGate gate
) {
30 myChangeListWorker
= changeListWorker
;
31 myComposite
= composite
;
32 myDisposedGetter
= disposedGetter
;
33 myUpdateUnversioned
= updateUnversioned
;
34 myIgnoredFilesComponent
= ignoredFilesComponent
;
36 myIndex
= ExcludedFileIndex
.getInstance(changeListWorker
.getProject());
39 private void checkIfDisposed() {
40 if (myDisposedGetter
.get()) throw new ChangeListManagerImpl
.DisposedException();
43 public void setCurrent(final VcsDirtyScope scope
, final FoldersCutDownWorker foldersWorker
) {
45 myFoldersCutDownWorker
= foldersWorker
;
48 public void processChange(final Change change
, VcsKey vcsKey
) {
49 processChangeInList( change
, (ChangeList
) null, vcsKey
);
52 public void processChangeInList(final Change change
, @Nullable final ChangeList changeList
, VcsKey vcsKey
) {
55 final String fileName
= ChangesUtil
.getFilePath(change
).getName();
56 if (FileTypeManager
.getInstance().isFileIgnored(fileName
)) return;
58 ApplicationManager
.getApplication().runReadAction(new Runnable() {
60 if (ChangeListManagerImpl
.isUnder(change
, myScope
)) {
61 if (changeList
!= null) {
62 myChangeListWorker
.addChangeToList(changeList
.getName(), change
);
64 myChangeListWorker
.addChangeToCorrespondingList(change
);
71 public void processChangeInList(final Change change
, final String changeListName
, VcsKey vcsKey
) {
74 LocalChangeList list
= null;
75 if (changeListName
!= null) {
76 list
= myChangeListWorker
.getCopyByName(changeListName
);
78 list
= myGate
.addChangeList(changeListName
, null);
81 processChangeInList(change
, list
, vcsKey
);
84 private boolean isExcluded(final VirtualFile file
) {
85 return myIndex
.isExcludedFile(file
);
88 public void processUnversionedFile(final VirtualFile file
) {
89 if (file
== null || ! myUpdateUnversioned
) return;
91 if (isExcluded(file
)) return;
92 if (myScope
.belongsTo(new FilePathImpl(file
))) {
93 if (myIgnoredFilesComponent
.isIgnoredFile(file
)) {
94 myComposite
.getIgnoredFileHolder().addFile(file
, "", false);
95 } else if (myComposite
.getIgnoredFileHolder().containsFile(file
)) {
96 // does not need to add: parent dir is already added
99 myComposite
.getVFHolder(FileHolder
.HolderType
.UNVERSIONED
).addFile(file
);
101 // if a file was previously marked as switched through recursion, remove it from switched list
102 myChangeListWorker
.removeSwitched(file
);
106 public void processLocallyDeletedFile(final FilePath file
) {
107 processLocallyDeletedFile(new LocallyDeletedChange(file
));
110 public void processLocallyDeletedFile(LocallyDeletedChange locallyDeletedChange
) {
111 if (! myUpdateUnversioned
) return;
113 final FilePath file
= locallyDeletedChange
.getPath();
114 if (FileTypeManager
.getInstance().isFileIgnored(file
.getName())) return;
115 if (myScope
.belongsTo(file
)) {
116 myChangeListWorker
.addLocallyDeleted(locallyDeletedChange
);
120 public void processModifiedWithoutCheckout(final VirtualFile file
) {
121 if (file
== null || ! myUpdateUnversioned
) return;
123 if (isExcluded(file
)) return;
124 if (myScope
.belongsTo(new FilePathImpl(file
))) {
125 myComposite
.getVFHolder(FileHolder
.HolderType
.MODIFIED_WITHOUT_EDITING
).addFile(file
);
129 public void processIgnoredFile(final VirtualFile file
) {
130 if (file
== null || ! myUpdateUnversioned
) return;
132 if (isExcluded(file
)) return;
133 if (myScope
.belongsTo(new FilePathImpl(file
))) {
134 myComposite
.getIgnoredFileHolder().addFile(file
, "", false);
138 public void processLockedFolder(final VirtualFile file
) {
139 if (file
== null) return;
141 if (myScope
.belongsTo(new FilePathImpl(file
))) {
142 if (myFoldersCutDownWorker
.addCurrent(file
)) {
143 myComposite
.getVFHolder(FileHolder
.HolderType
.LOCKED
).addFile(file
);
148 public void processLogicallyLockedFolder(VirtualFile file
, LogicalLock logicalLock
) {
149 if (file
== null) return;
151 if (myScope
.belongsTo(new FilePathImpl(file
))) {
152 ((LogicallyLockedHolder
) myComposite
.get(FileHolder
.HolderType
.LOGICALLY_LOCKED
)).add(file
, logicalLock
);
156 public void processSwitchedFile(final VirtualFile file
, final String branch
, final boolean recursive
) {
157 if (file
== null || ! myUpdateUnversioned
) return;
159 if (isExcluded(file
)) return;
160 if (myScope
.belongsTo(new FilePathImpl(file
))) {
161 myChangeListWorker
.addSwitched(file
, branch
, recursive
);
165 public boolean isUpdatingUnversionedFiles() {
166 return myUpdateUnversioned
;
169 public boolean reportChangesOutsideProject() {