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 com
.intellij
.openapi
.vcs
.changes
;
18 import com
.intellij
.openapi
.application
.ApplicationManager
;
19 import com
.intellij
.openapi
.diagnostic
.Logger
;
20 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
21 import com
.intellij
.openapi
.util
.Getter
;
22 import com
.intellij
.openapi
.vcs
.FilePath
;
23 import com
.intellij
.openapi
.vcs
.FilePathImpl
;
24 import com
.intellij
.openapi
.vcs
.VcsKey
;
25 import com
.intellij
.openapi
.vcs
.impl
.ExcludedFileIndex
;
26 import com
.intellij
.openapi
.vfs
.VirtualFile
;
27 import org
.jetbrains
.annotations
.Nullable
;
29 class UpdatingChangeListBuilder
implements ChangelistBuilder
{
30 private static final Logger LOG
= Logger
.getInstance("#com.intellij.openapi.vcs.changes.UpdatingChangeListBuilder");
31 private final ChangeListWorker myChangeListWorker
;
32 private final FileHolderComposite myComposite
;
34 private final Getter
<Boolean
> myDisposedGetter
;
35 private VcsDirtyScope myScope
;
36 private FoldersCutDownWorker myFoldersCutDownWorker
;
37 private final boolean myUpdateUnversioned
;
38 private final IgnoredFilesComponent myIgnoredFilesComponent
;
39 private final ExcludedFileIndex myIndex
;
40 private final ChangeListManagerGate myGate
;
42 UpdatingChangeListBuilder(final ChangeListWorker changeListWorker
,
43 final FileHolderComposite composite
,
44 final Getter
<Boolean
> disposedGetter
,
45 final boolean updateUnversioned
,
46 final IgnoredFilesComponent ignoredFilesComponent
, final ChangeListManagerGate gate
) {
47 myChangeListWorker
= changeListWorker
;
48 myComposite
= composite
;
49 myDisposedGetter
= disposedGetter
;
50 myUpdateUnversioned
= updateUnversioned
;
51 myIgnoredFilesComponent
= ignoredFilesComponent
;
53 myIndex
= ExcludedFileIndex
.getInstance(changeListWorker
.getProject());
56 private void checkIfDisposed() {
57 if (myDisposedGetter
.get()) throw new ChangeListManagerImpl
.DisposedException();
60 public void setCurrent(final VcsDirtyScope scope
, final FoldersCutDownWorker foldersWorker
) {
62 myFoldersCutDownWorker
= foldersWorker
;
65 public void processChange(final Change change
, VcsKey vcsKey
) {
66 processChangeInList( change
, (ChangeList
) null, vcsKey
);
69 public void processChangeInList(final Change change
, @Nullable final ChangeList changeList
, final VcsKey vcsKey
) {
72 LOG
.debug("[processChangeInList-1] entering, cl name: " + ((changeList
== null) ?
null: changeList
.getName()) +
73 " change: " + ChangesUtil
.getFilePath(change
).getPath());
74 final String fileName
= ChangesUtil
.getFilePath(change
).getName();
75 if (FileTypeManager
.getInstance().isFileIgnored(fileName
)) {
76 LOG
.debug("[processChangeInList-1] file type ignored");
80 ApplicationManager
.getApplication().runReadAction(new Runnable() {
82 if (ChangeListManagerImpl
.isUnder(change
, myScope
)) {
83 if (changeList
!= null) {
84 LOG
.debug("[processChangeInList-1] to add change to cl");
85 myChangeListWorker
.addChangeToList(changeList
.getName(), change
, vcsKey
);
87 LOG
.debug("[processChangeInList-1] to add to corresponding list");
88 myChangeListWorker
.addChangeToCorrespondingList(change
, vcsKey
);
91 LOG
.debug("[processChangeInList-1] not under scope");
97 public void processChangeInList(final Change change
, final String changeListName
, VcsKey vcsKey
) {
100 LocalChangeList list
= null;
101 if (changeListName
!= null) {
102 list
= myChangeListWorker
.getCopyByName(changeListName
);
104 list
= myGate
.addChangeList(changeListName
, null);
107 processChangeInList(change
, list
, vcsKey
);
110 private boolean isExcluded(final VirtualFile file
) {
111 return myIndex
.isExcludedFile(file
);
114 public void processUnversionedFile(final VirtualFile file
) {
115 if (file
== null || ! myUpdateUnversioned
) return;
117 if (isExcluded(file
)) return;
118 if (myScope
.belongsTo(new FilePathImpl(file
))) {
119 if (myIgnoredFilesComponent
.isIgnoredFile(file
)) {
120 myComposite
.getIgnoredFileHolder().addFile(file
, "", false);
121 } else if (myComposite
.getIgnoredFileHolder().containsFile(file
)) {
122 // does not need to add: parent dir is already added
125 myComposite
.getVFHolder(FileHolder
.HolderType
.UNVERSIONED
).addFile(file
);
127 // if a file was previously marked as switched through recursion, remove it from switched list
128 myChangeListWorker
.removeSwitched(file
);
132 public void processLocallyDeletedFile(final FilePath file
) {
133 processLocallyDeletedFile(new LocallyDeletedChange(file
));
136 public void processLocallyDeletedFile(LocallyDeletedChange locallyDeletedChange
) {
137 if (! myUpdateUnversioned
) return;
139 final FilePath file
= locallyDeletedChange
.getPath();
140 if (FileTypeManager
.getInstance().isFileIgnored(file
.getName())) return;
141 if (myScope
.belongsTo(file
)) {
142 myChangeListWorker
.addLocallyDeleted(locallyDeletedChange
);
146 public void processModifiedWithoutCheckout(final VirtualFile file
) {
147 if (file
== null || ! myUpdateUnversioned
) return;
149 if (isExcluded(file
)) return;
150 if (myScope
.belongsTo(new FilePathImpl(file
))) {
151 myComposite
.getVFHolder(FileHolder
.HolderType
.MODIFIED_WITHOUT_EDITING
).addFile(file
);
155 public void processIgnoredFile(final VirtualFile file
) {
156 if (file
== null || ! myUpdateUnversioned
) return;
158 if (isExcluded(file
)) return;
159 if (myScope
.belongsTo(new FilePathImpl(file
))) {
160 myComposite
.getIgnoredFileHolder().addFile(file
, "", false);
164 public void processLockedFolder(final VirtualFile file
) {
165 if (file
== null) return;
167 if (myScope
.belongsTo(new FilePathImpl(file
))) {
168 if (myFoldersCutDownWorker
.addCurrent(file
)) {
169 myComposite
.getVFHolder(FileHolder
.HolderType
.LOCKED
).addFile(file
);
174 public void processLogicallyLockedFolder(VirtualFile file
, LogicalLock logicalLock
) {
175 if (file
== null) return;
177 if (myScope
.belongsTo(new FilePathImpl(file
))) {
178 ((LogicallyLockedHolder
) myComposite
.get(FileHolder
.HolderType
.LOGICALLY_LOCKED
)).add(file
, logicalLock
);
182 public void processSwitchedFile(final VirtualFile file
, final String branch
, final boolean recursive
) {
183 if (file
== null || ! myUpdateUnversioned
) return;
185 if (isExcluded(file
)) return;
186 if (myScope
.belongsTo(new FilePathImpl(file
))) {
187 myChangeListWorker
.addSwitched(file
, branch
, recursive
);
191 public void processRootSwitch(VirtualFile file
, String branch
) {
192 if (file
== null) return;
194 if (myScope
.belongsTo(new FilePathImpl(file
))) {
195 ((SwitchedFileHolder
) myComposite
.get(FileHolder
.HolderType
.ROOT_SWITCH
)).addFile(file
, branch
, false);
199 public boolean isUpdatingUnversionedFiles() {
200 return myUpdateUnversioned
;
203 public boolean reportChangesOutsideProject() {