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.project.Project;
19 import com.intellij.openapi.vcs.AbstractVcs;
20 import com.intellij.openapi.vcs.FilePath;
21 import com.intellij.openapi.vcs.impl.DefaultVcsRootPolicy;
22 import org.jetbrains.annotations.NotNull;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
30 private final Project myProject;
31 private final VcsGuess myGuess;
33 private boolean myEverythingDirty;
34 private final Map<AbstractVcs, VcsDirtyScopeImpl> myScopes;
36 public Scopes(final Project project, final VcsGuess guess) {
39 myScopes = new HashMap<AbstractVcs, VcsDirtyScopeImpl>();
42 private void markEverythingDirty() {
44 myEverythingDirty = true;
45 final DirtBuilder builder = new DirtBuilder(myGuess);
46 DefaultVcsRootPolicy.getInstance(myProject).markDefaultRootsDirty(builder, myGuess);
50 public void takeDirt(final DirtBuilderReader dirt) {
51 if (dirt.isEverythingDirty()) {
52 markEverythingDirty();
55 final List<FilePathUnderVcs> dirs = dirt.getDirsForVcs();
56 for (FilePathUnderVcs dir : dirs) {
57 getScope(dir.getVcs()).addDirtyDirRecursively(dir.getPath());
59 final List<FilePathUnderVcs> files = dirt.getFilesForVcs();
60 for (FilePathUnderVcs file : files) {
61 getScope(file.getVcs()).addDirtyFile(file.getPath());
65 public void addDirtyDirRecursively(@NotNull final AbstractVcs vcs, @NotNull final FilePath newcomer) {
66 getScope(vcs).addDirtyDirRecursively(newcomer);
69 public void addDirtyFile(@NotNull final AbstractVcs vcs, @NotNull final FilePath newcomer) {
70 getScope(vcs).addDirtyFile(newcomer);
74 public VcsInvalidated retrieveAndClear() {
75 final ArrayList<VcsDirtyScope> scopesList = new ArrayList<VcsDirtyScope>(myScopes.values());
76 final VcsInvalidated result = new VcsInvalidated(scopesList, myEverythingDirty);
77 myEverythingDirty = false;
82 private VcsDirtyScopeImpl getScope(final AbstractVcs vcs) {
83 VcsDirtyScopeImpl scope = myScopes.get(vcs);
85 scope = new VcsDirtyScopeImpl(vcs, myProject);
86 myScopes.put(vcs, scope);