update copyright
[fedora-idea.git] / plugins / git4idea / src / git4idea / changes / GitCommittedChangeListProvider.java
blobc3f9a1ee64af0c54a7d685ee5b89cce986d9c4d4
1 /*
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.project.Project;
20 import com.intellij.openapi.util.text.StringUtil;
21 import com.intellij.openapi.vcs.*;
22 import com.intellij.openapi.vcs.changes.committed.DecoratorManager;
23 import com.intellij.openapi.vcs.changes.committed.VcsCommittedListsZipper;
24 import com.intellij.openapi.vcs.changes.committed.VcsCommittedViewAuxiliary;
25 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
26 import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
27 import com.intellij.openapi.vcs.versionBrowser.ChangesBrowserSettingsEditor;
28 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
29 import com.intellij.openapi.vfs.LocalFileSystem;
30 import com.intellij.openapi.vfs.VirtualFile;
31 import com.intellij.util.Consumer;
32 import git4idea.GitBranch;
33 import git4idea.GitRemote;
34 import git4idea.GitUtil;
35 import git4idea.commands.GitSimpleHandler;
36 import org.jetbrains.annotations.Nls;
37 import org.jetbrains.annotations.Nullable;
39 import java.io.DataInput;
40 import java.io.DataOutput;
41 import java.io.File;
42 import java.io.IOException;
43 import java.util.Collection;
44 import java.util.Date;
45 import java.util.List;
47 /**
48 * The provider for committed change lists
50 public class GitCommittedChangeListProvider implements CachingCommittedChangesProvider<CommittedChangeList, ChangeBrowserSettings> {
51 /**
52 * the logger
54 private static final Logger LOG = Logger.getInstance(GitCommittedChangeListProvider.class.getName());
57 /**
58 * The project for the service
60 private Project myProject;
62 /**
63 * The constructor
65 * @param project the project instance for this provider
67 public GitCommittedChangeListProvider(Project project) {
68 myProject = project;
71 /**
72 * {@inheritDoc}
74 public ChangeBrowserSettings createDefaultSettings() {
75 return new ChangeBrowserSettings();
78 /**
79 * {@inheritDoc}
81 public ChangesBrowserSettingsEditor<ChangeBrowserSettings> createFilterUI(boolean showDateFilter) {
82 return new GitVersionFilterComponent(showDateFilter);
85 /**
86 * {@inheritDoc}
88 public RepositoryLocation getLocationFor(FilePath root) {
89 VirtualFile gitRoot = GitUtil.getGitRootOrNull(root);
90 if (gitRoot == null) {
91 return null;
93 try {
94 GitBranch c = GitBranch.current(myProject, gitRoot);
95 if (c == null) {
96 return null;
98 String remote = c.getTrackedRemoteName(myProject, gitRoot);
99 if (StringUtil.isEmpty(remote)) {
100 return null;
102 File rootFile = new File(gitRoot.getPath());
103 if (".".equals(remote)) {
104 return new GitRepositoryLocation(gitRoot.getUrl(), rootFile);
106 else {
107 GitRemote r = GitRemote.find(myProject, gitRoot, remote);
108 return r == null ? null : new GitRepositoryLocation(r.fetchUrl(), rootFile);
111 catch (VcsException e) {
112 if (LOG.isDebugEnabled()) {
113 LOG.debug("Exception for determining repository location", e);
115 return null;
120 * {@inheritDoc}
122 public RepositoryLocation getLocationFor(FilePath root, String repositoryPath) {
123 return getLocationFor(root);
127 * {@inheritDoc}
129 public VcsCommittedListsZipper getZipper() {
130 return null;
134 * {@inheritDoc}
136 public List<CommittedChangeList> getCommittedChanges(ChangeBrowserSettings settings, RepositoryLocation location, final int maxCount)
137 throws VcsException {
138 GitRepositoryLocation l = (GitRepositoryLocation)location;
139 final Long beforeRev = settings.getChangeBeforeFilter();
140 final Long afterRev = settings.getChangeBeforeFilter();
141 final Date beforeDate = settings.getDateBeforeFilter();
142 final Date afterDate = settings.getDateBeforeFilter();
143 final String author = settings.getUserFilter();
144 VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(l.getRoot());
145 if (root == null) {
146 throw new VcsException("The repository does not exists anymore: " + l.getRoot());
149 return GitUtil.getLocalCommittedChanges(myProject, root, new Consumer<GitSimpleHandler>() {
150 public void consume(GitSimpleHandler h) {
151 if (!StringUtil.isEmpty(author)) {
152 h.addParameters("--author=" + author);
154 if (beforeDate != null) {
155 h.addParameters("--before=" + GitUtil.gitTime(beforeDate));
157 if (afterDate != null) {
158 h.addParameters("--after=" + GitUtil.gitTime(afterDate));
160 if (maxCount != getUnlimitedCountValue()) {
161 h.addParameters("-n" + maxCount);
163 if (beforeRev != null && afterRev != null) {
164 h.addParameters(GitUtil.formatLongRev(afterRev) + ".." + GitUtil.formatLongRev(beforeRev));
166 else if (beforeRev != null) {
167 h.addParameters(GitUtil.formatLongRev(beforeRev));
169 else if (afterRev != null) {
170 h.addParameters(GitUtil.formatLongRev(afterRev) + "..");
178 * {@inheritDoc}
180 public ChangeListColumn[] getColumns() {
181 return new ChangeListColumn[]{ChangeListColumn.NUMBER, ChangeListColumn.DATE, ChangeListColumn.DESCRIPTION, ChangeListColumn.NAME};
185 * {@inheritDoc}
187 public VcsCommittedViewAuxiliary createActions(DecoratorManager manager, RepositoryLocation location) {
188 return null;
192 * {@inheritDoc}
194 public int getUnlimitedCountValue() {
195 return -1;
198 public int getFormatVersion() {
199 return 0; //To change body of implemented methods use File | Settings | File Templates.
202 public void writeChangeList(DataOutput stream, CommittedChangeList list) throws IOException {
203 //To change body of implemented methods use File | Settings | File Templates.
206 public CommittedChangeList readChangeList(RepositoryLocation location, DataInput stream) throws IOException {
207 return null; //To change body of implemented methods use File | Settings | File Templates.
210 public boolean isMaxCountSupported() {
211 return false; //To change body of implemented methods use File | Settings | File Templates.
214 public Collection<FilePath> getIncomingFiles(RepositoryLocation location) throws VcsException {
215 return null; //To change body of implemented methods use File | Settings | File Templates.
218 public boolean refreshCacheByNumber() {
219 return false; //To change body of implemented methods use File | Settings | File Templates.
222 @Nls
223 public String getChangelistTitle() {
224 return null; //To change body of implemented methods use File | Settings | File Templates.
227 public boolean isChangeLocallyAvailable(FilePath filePath,
228 @Nullable VcsRevisionNumber localRevision,
229 VcsRevisionNumber changeRevision,
230 CommittedChangeList changeList) {
231 return false; //To change body of implemented methods use File | Settings | File Templates.
234 public boolean refreshIncomingWithCommitted() {
235 return false; //To change body of implemented methods use File | Settings | File Templates.