summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJens Baumgart2010-08-04 04:52:25 (EDT)
committer Chris Aniszczyk2010-08-04 11:05:25 (EDT)
commitd418845e423fe8a39242bad850429ad84b814404 (patch)
tree3e8ddfb877500212e8a3545a36fbadd8abdb2814
parenta14361d8cfa4817de21bee61e4ac717935a9c728 (diff)
downloadegit-d418845e423fe8a39242bad850429ad84b814404.zip
egit-d418845e423fe8a39242bad850429ad84b814404.tar.gz
egit-d418845e423fe8a39242bad850429ad84b814404.tar.bz2
Provide gitignore support in commit dialogrefs/changes/34/1234/2
Gitignore support was added to the commit dialog. Furthermore the calculation of untracked files using a ResourceVisitor was removed. This is now done by the new TreeWalk based implementation of IndexDiff. Change-Id: I1a2e4d7048f21c039a9b7bde8f74e570573ec8a2 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java107
1 files changed, 10 insertions, 97 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
index 490cc17..9a3012c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
@@ -14,7 +14,6 @@
package org.eclipse.egit.ui.internal.actions;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -27,14 +26,15 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.egit.core.AdaptableFileTreeIterator;
+import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.egit.core.op.CommitOperation;
-import org.eclipse.egit.core.project.GitProjectData;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
@@ -45,19 +45,12 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.GitIndex;
-import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
-import org.eclipse.jgit.lib.Tree;
-import org.eclipse.jgit.lib.TreeEntry;
import org.eclipse.jgit.lib.UserConfig;
-import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.team.core.Team;
-import org.eclipse.team.core.TeamException;
import org.eclipse.ui.PlatformUI;
/**
@@ -93,10 +86,6 @@ public class CommitActionHandler extends RepositoryActionHandler {
Activator.handleError(UIText.CommitAction_errorComputingDiffs, e,
true);
return null;
- } catch (CoreException e) {
- Activator.handleError(UIText.CommitAction_errorComputingDiffs, e,
- true);
- return null;
}
Repository[] repos = getRepositoriesFor(getProjectsForSelectedResources(event));
@@ -257,7 +246,7 @@ public class CommitActionHandler extends RepositoryActionHandler {
}
private void buildIndexHeadDiffList(ExecutionEvent event)
- throws IOException, CoreException, ExecutionException {
+ throws IOException, ExecutionException {
HashMap<Repository, HashSet<IProject>> repositories = new HashMap<Repository, HashSet<IProject>>();
for (IProject project : getProjectsInRepositoryOfSelectedResources(event)) {
@@ -282,9 +271,11 @@ public class CommitActionHandler extends RepositoryActionHandler {
Repository repository = entry.getKey();
HashSet<IProject> projects = entry.getValue();
- Tree head = repository.mapTree(Constants.HEAD);
- GitIndex index = repository.getIndex();
- IndexDiff indexDiff = new IndexDiff(head, index);
+ AdaptableFileTreeIterator fileTreeIterator =
+ new AdaptableFileTreeIterator(repository.getWorkTree(),
+ ResourcesPlugin.getWorkspace().getRoot());
+
+ IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator);
indexDiff.diff();
for (IProject project : projects) {
@@ -293,47 +284,11 @@ public class CommitActionHandler extends RepositoryActionHandler {
includeList(project, indexDiff.getRemoved(), indexChanges);
includeList(project, indexDiff.getMissing(), notIndexed);
includeList(project, indexDiff.getModified(), notIndexed);
- addUntrackedFiles(repository, project);
+ includeList(project, indexDiff.getUntracked(), notTracked);
}
}
}
- private void addUntrackedFiles(final Repository repository,
- final IProject project) throws CoreException, IOException {
- final GitIndex index = repository.getIndex();
- final Tree headTree = repository.mapTree(Constants.HEAD);
- project.accept(new IResourceVisitor() {
-
- public boolean visit(IResource resource) throws CoreException {
- if (Team.isIgnoredHint(resource))
- return false;
- if (resource.getType() == IResource.FILE) {
-
- String repoRelativePath = RepositoryMapping.getMapping(
- project).getRepoRelativePath(resource);
- try {
- TreeEntry headEntry = (headTree == null ? null
- : headTree.findBlobMember(repoRelativePath));
- if (headEntry == null) {
- Entry indexEntry = null;
- indexEntry = index.getEntry(repoRelativePath);
-
- if (indexEntry == null) {
- notTracked.add((IFile) resource);
- files.add((IFile) resource);
- }
- }
- } catch (IOException e) {
- throw new TeamException(
- UIText.CommitAction_InternalError, e);
- }
- }
- return true;
- }
- });
-
- }
-
private void includeList(IProject project, HashSet<String> added,
ArrayList<IFile> category) {
String repoRelativePath = RepositoryMapping.getMapping(project)
@@ -362,48 +317,6 @@ public class CommitActionHandler extends RepositoryActionHandler {
}
}
- boolean tryAddResource(IFile resource, GitProjectData projectData,
- ArrayList<IFile> category) {
- if (files.contains(resource))
- return false;
-
- try {
- RepositoryMapping repositoryMapping = projectData
- .getRepositoryMapping(resource);
-
- if (isChanged(repositoryMapping, resource)) {
- files.add(resource);
- category.add(resource);
- return true;
- }
- } catch (Exception e) {
- if (GitTraceLocation.UI.isActive())
- GitTraceLocation.getTrace().trace(
- GitTraceLocation.UI.getLocation(), e.getMessage(), e);
- }
- return false;
- }
-
- private boolean isChanged(RepositoryMapping map, IFile resource) {
- try {
- Repository repository = map.getRepository();
- GitIndex index = repository.getIndex();
- String repoRelativePath = map.getRepoRelativePath(resource);
- Entry entry = index.getEntry(repoRelativePath);
- if (entry != null)
- return entry.isModified(map.getWorkTree());
- return false;
- } catch (UnsupportedEncodingException e) {
- if (GitTraceLocation.UI.isActive())
- GitTraceLocation.getTrace().trace(
- GitTraceLocation.UI.getLocation(), e.getMessage(), e);
- } catch (IOException e) {
- if (GitTraceLocation.UI.isActive())
- GitTraceLocation.getTrace().trace(
- GitTraceLocation.UI.getLocation(), e.getMessage(), e);
- }
- return false;
- }
@Override
public boolean isEnabled() {