aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2010-08-13 20:15:08 (EDT)
committerChris Aniszczyk2010-08-16 13:05:15 (EDT)
commitd97e8442fb3d5981d5f279e4a13af9a1fdcb5ae6 (patch)
tree017e0222507d6b34ff1a69f1356760f68ee5a4e4
parentdac60da0ec8882d7da32c6d2f93ed9f6f81b60fa (diff)
downloadegit-d97e8442fb3d5981d5f279e4a13af9a1fdcb5ae6.zip
egit-d97e8442fb3d5981d5f279e4a13af9a1fdcb5ae6.tar.gz
egit-d97e8442fb3d5981d5f279e4a13af9a1fdcb5ae6.tar.bz2
Respect .gitignore in Synchronization viewrefs/changes/05/1305/3
Respect repository wide .gitignore configuration in Synchronize view. Bug: 322454 Change-Id: I2ab2a676e850024e8e316c94c678bad4e38815d8 Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java6
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java26
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java2
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java29
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitTreeMapping.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java29
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java21
8 files changed, 97 insertions, 31 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java
index 45f1fff..b9b3110 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBlobResourceVariant.java
@@ -44,10 +44,8 @@ public class GitBlobResourceVariant extends GitResourceVariant {
throws IOException {
super(repo, objectId, path);
- if (getObjectId() != null) {
- ObjectLoader blob = repo.open(getObjectId());
- bytes = blob.getBytes();
- }
+ ObjectLoader blob = repo.open(getObjectId());
+ bytes = blob.getBytes();
}
public boolean isContainer() {
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java
index f3ee793..7c5ed87 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitFolderResourceVariant.java
@@ -11,6 +11,8 @@
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
+import static org.eclipse.jgit.lib.ObjectId.zeroId;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -21,7 +23,9 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.egit.core.CoreText;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.IResourceVariant;
@@ -64,28 +68,32 @@ public class GitFolderResourceVariant extends GitResourceVariant {
progress.done();
}
- TreeWalk tw = new TreeWalk(getRepository());
+ Repository repo = getRepository();
+ TreeWalk tw = new TreeWalk(repo);
tw.reset();
+
int nth = tw.addTree(getObjectId());
+ int iteratorNth = tw.addTree(new FileTreeIterator(repo));
+
+ tw.setFilter(new NotIgnoredFilter(iteratorNth));
IProgressMonitor monitor = SubMonitor.convert(progress);
monitor.beginTask(
NLS.bind(CoreText.GitFolderResourceVariant_fetchingMembers, this),
tw.getTreeCount());
- Repository repo = getRepository();
List<IResourceVariant> result = new ArrayList<IResourceVariant>();
-
try {
while (tw.next()) {
ObjectId newObjectId = tw.getObjectId(nth);
String path = getPath() + "/" + new String(tw.getRawPath()); //$NON-NLS-1$
- if (tw.isSubtree())
- result.add(new GitFolderResourceVariant(repo, newObjectId,
- path));
- else
- result.add(new GitBlobResourceVariant(repo, newObjectId,
- path));
+ if (!newObjectId.equals(zeroId()))
+ if (tw.isSubtree())
+ result.add(new GitFolderResourceVariant(repo,
+ newObjectId, path));
+ else
+ result.add(new GitBlobResourceVariant(repo,
+ newObjectId, path));
monitor.worked(1);
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java
index 136de20..aa1ecd8 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariant.java
@@ -121,7 +121,7 @@ abstract class GitResourceVariant implements IResourceVariant {
}
public boolean exists() {
- return objectId != null && !objectId.equals(ObjectId.zeroId());
+ return true;
}
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java
index 1bd320d..757ebe4 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitResourceVariantTree.java
@@ -11,6 +11,8 @@
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
+import static org.eclipse.jgit.lib.ObjectId.zeroId;
+
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -21,11 +23,17 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.egit.core.CoreText;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
+import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
+import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter;
import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.IResourceVariant;
@@ -68,21 +76,23 @@ abstract class GitResourceVariantTree extends ResourceVariantTree {
if (path.length() == 0)
return handleRepositoryRoot(resource, repo, revCommit);
- TreeWalk tw = initializeTreeWalk(repo, path);
-
try {
+ TreeWalk tw = initializeTreeWalk(repo, path);
+
int nth = tw.addTree(revCommit.getTree());
if (resource.getType() == IResource.FILE) {
tw.setRecursive(true);
- if (tw.next())
+ if (tw.next() && !tw.getObjectId(nth).equals(zeroId()))
return new GitBlobResourceVariant(repo,
tw.getObjectId(nth), path);
} else {
while (tw.next() && !path.equals(tw.getPathString()))
if (tw.isSubtree())
tw.enterSubtree();
- return new GitFolderResourceVariant(repo, tw.getObjectId(nth),
- path);
+
+ ObjectId objectId = tw.getObjectId(nth);
+ if (!objectId.equals(zeroId()))
+ return new GitFolderResourceVariant(repo, objectId, path);
}
} catch (IOException e) {
throw new TeamException(
@@ -149,10 +159,15 @@ abstract class GitResourceVariantTree extends ResourceVariantTree {
}
}
- private TreeWalk initializeTreeWalk(Repository repo, String path) {
+ private TreeWalk initializeTreeWalk(Repository repo, String path)
+ throws CorruptObjectException {
TreeWalk tw = new TreeWalk(repo);
tw.reset();
- tw.setFilter(PathFilter.create(path));
+ int ignoreNth = tw.addTree(new FileTreeIterator(repo));
+
+ TreeFilter pathFilter = PathFilter.create(path);
+ TreeFilter ignoreFilter = new NotIgnoredFilter(ignoreNth);
+ tw.setFilter(AndTreeFilter.create(pathFilter, ignoreFilter));
return tw;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitTreeMapping.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitTreeMapping.java
index 8ecc716..f5ba356 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitTreeMapping.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitTreeMapping.java
@@ -54,6 +54,9 @@ class GitTreeMapping extends GitObjectMapping {
private IResource[] getResources(GitModelBlob modelBlob) {
IFile file = root.getFileForLocation(modelBlob.getLocation());
+ if (file == null)
+ file = root.getFile(modelBlob.getLocation());
+
return new IResource[] { file };
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
index 23a5807..b885283 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCommit.java
@@ -31,6 +31,7 @@ import org.eclipse.egit.core.Activator;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -248,14 +249,21 @@ public class GitModelCommit extends GitModelObject implements ISynchronizationCo
private void getChildrenImpl() {
TreeWalk tw = createTreeWalk();
List<GitModelObject> result = new ArrayList<GitModelObject>();
+
try {
- int ancestorNth = tw.addTree(ancestorCommit.getTree());
+ RevTree actualTree = remoteCommit.getTree();
+ List<String> notIgnored = getNotIgnoredNodes(actualTree);
+
+ int actualNth = tw.addTree(actualTree);
int baseNth = -1;
if (baseCommit != null)
baseNth = tw.addTree(baseCommit.getTree());
- int actualNth = tw.addTree(remoteCommit.getTree());
+ int ancestorNth = tw.addTree(ancestorCommit.getTree());
while (tw.next()) {
+ if (!notIgnored.contains(tw.getNameString()))
+ continue;
+
GitModelObject obj = getModelObject(tw, ancestorNth, baseNth,
actualNth);
if (obj != null)
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java
index dc688e0..21cdb18 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelObject.java
@@ -9,14 +9,19 @@
package org.eclipse.egit.ui.internal.synchronize.model;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
/**
@@ -110,4 +115,28 @@ public abstract class GitModelObject extends PlatformObject {
return tw;
}
+ /**
+ * Return list of not ignored children in root node.
+ *
+ * @param root
+ * @return list of not ignored nodes
+ * @throws IOException
+ */
+ protected List<String> getNotIgnoredNodes(ObjectId root) throws IOException {
+ Repository repo = getRepository();
+ List<String> resutl = new ArrayList<String>();
+
+ TreeWalk tw = new TreeWalk(repo);
+ tw.reset();
+ tw.addTree(root);
+
+ int ignoreNth = tw.addTree(new FileTreeIterator(repo));
+ tw.setFilter(new NotIgnoredFilter(ignoreNth));
+
+ while (tw.next())
+ resutl.add(tw.getNameString());
+
+ return resutl;
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java
index 475ef14..8fdb1f1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelTree.java
@@ -129,19 +129,22 @@ public class GitModelTree extends GitModelCommit {
List<GitModelObject> result = new ArrayList<GitModelObject>();
try {
- int ancestorNth = -1;
- if (!ancestorId.equals(zeroId()))
- ancestorNth = tw.addTree(ancestorId);
+ List<String> notIgnored = getNotIgnoredNodes(remoteId);
+
+ int remoteNth = tw.addTree(remoteId);
int baseNth = -1;
if (!baseId.equals(zeroId()))
baseNth = tw.addTree(baseId);
- int remoteNth = -1;
- if (!remoteId.equals(zeroId()))
- remoteNth = tw.addTree(remoteId);
+ int ancestorNth = -1;
+ if (!ancestorId.equals(zeroId()))
+ ancestorNth = tw.addTree(ancestorId);
while (tw.next()) {
+ if (!notIgnored.contains(tw.getNameString()))
+ continue;
+
GitModelObject obj = createChildren(tw, ancestorNth, baseNth,
remoteNth);
if (obj != null)
@@ -156,10 +159,12 @@ public class GitModelTree extends GitModelCommit {
private GitModelObject createChildren(TreeWalk tw, int ancestorNth,
int baseNth, int remoteNth) throws IOException {
+ ObjectId objRemoteId = tw.getObjectId(remoteNth);
+ if (objRemoteId.equals(zeroId()))
+ return null;
+
String objName = tw.getNameString();
ObjectId objBaseId = baseNth != -1 ? tw.getObjectId(baseNth) : zeroId();
- ObjectId objRemoteId = remoteNth != -1 ? tw.getObjectId(remoteNth)
- : zeroId();
ObjectId objAncestorId = ancestorNth != -1 ? tw
.getObjectId(ancestorNth) : zeroId();
int objectType = tw.getFileMode(remoteNth).getObjectType();