VCS: file changed remotely hint
[fedora-idea.git] / vcs-impl / src / com / intellij / openapi / vcs / changes / ChangeListsIndexes.java
blob3ec563d2784f943d64fc448eb2f259abd04304bc
1 package com.intellij.openapi.vcs.changes;
3 import com.intellij.openapi.util.Comparing;
4 import com.intellij.openapi.util.Pair;
5 import com.intellij.openapi.vcs.FilePath;
6 import com.intellij.openapi.vcs.FileStatus;
7 import com.intellij.openapi.vcs.VcsKey;
8 import com.intellij.openapi.vfs.VirtualFile;
10 import java.io.File;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
16 public class ChangeListsIndexes {
17 private final Map<String, FileStatus> myFileToStatus;
18 private final Map<String, VcsKey> myFileToVcs;
20 ChangeListsIndexes() {
21 myFileToStatus = new HashMap<String, FileStatus>();
22 myFileToVcs = new HashMap<String, VcsKey>();
25 ChangeListsIndexes(final ChangeListsIndexes idx) {
26 myFileToStatus = new HashMap<String, FileStatus>(idx.myFileToStatus);
27 myFileToVcs = new HashMap<String, VcsKey>(idx.myFileToVcs);
30 void add(final FilePath file, final FileStatus status, final VcsKey key) {
31 final String fileKey = file.getIOFile().getAbsolutePath();
32 myFileToStatus.put(fileKey, status);
33 myFileToVcs.put(fileKey, key);
36 void remove(final FilePath file) {
37 final String fileKey = file.getIOFile().getAbsolutePath();
38 myFileToStatus.remove(fileKey);
39 myFileToVcs.remove(fileKey);
42 public FileStatus getStatus(final VirtualFile file) {
43 return myFileToStatus.get(new File(file.getPath()).getAbsolutePath());
46 public void changeAdded(final Change change, final VcsKey key) {
47 addChangeToIdx(change, key);
50 public void changeRemoved(final Change change) {
51 final ContentRevision afterRevision = change.getAfterRevision();
52 final ContentRevision beforeRevision = change.getBeforeRevision();
54 if (afterRevision != null) {
55 remove(afterRevision.getFile());
57 if (beforeRevision != null) {
58 remove(beforeRevision.getFile());
62 private void addChangeToIdx(final Change change, final VcsKey key) {
63 final ContentRevision afterRevision = change.getAfterRevision();
64 if (afterRevision != null) {
65 add(afterRevision.getFile(), change.getFileStatus(), key);
67 final ContentRevision beforeRevision = change.getBeforeRevision();
68 if (beforeRevision != null) {
69 if (afterRevision != null) {
70 if (! Comparing.equal(beforeRevision.getFile(), afterRevision.getFile())) {
71 add(beforeRevision.getFile(), FileStatus.DELETED, key);
73 } else {
74 add(beforeRevision.getFile(), change.getFileStatus(), key);
79 public List<Pair<String, VcsKey>> getAffectedFilesUnderVcs() {
80 final ArrayList<Pair<String, VcsKey>> result = new ArrayList<Pair<String, VcsKey>>();
81 for (Map.Entry<String, VcsKey> entry : myFileToVcs.entrySet()) {
82 result.add(new Pair<String, VcsKey>(entry.getKey(), entry.getValue()));
84 return result;
87 public List<File> getAffectedPaths() {
88 final List<File> result = new ArrayList<File>(myFileToStatus.size());
89 for (String path : myFileToStatus.keySet()) {
90 result.add(new File(path));
92 return result;