aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
diff options
context:
space:
mode:
authorIvan Motsch <ivan.motsch@bsiag.com>2015-11-17 13:32:20 +0100
committerIvan Motsch <ivan.motsch@bsiag.com>2015-11-27 11:40:34 +0100
commit75697adc5a0024449351aacac89618c3b83add11 (patch)
treee50cae59d87dc42ef2fe7ebc932e3371bf0602c9 /org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
parentadbe9006831a5d03a3513f4a09dbda8703e19f7c (diff)
downloadjgit-75697adc5a0024449351aacac89618c3b83add11.tar.gz
jgit-75697adc5a0024449351aacac89618c3b83add11.zip
Add the new class Attributes holding multiple Attribute(s)
Attributes represents a semantic collector of Attribute(s) and replaces the anonymous Map<String,Attribute>. This class will be returned by TreeWalk.getAttributes(). It offers convenient access to the attributes wrapped in the Attributes object. Adds preparations for a future Attribute Macro Expansion Change-Id: I8348c8c457a2a7f1f0c48050e10399b0fa1cdbe1 Signed-off-by: Ivan Motsch <ivan.motsch@bsiag.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java41
1 files changed, 23 insertions, 18 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
index 826ce0973d..8a59a700e3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
@@ -45,17 +45,16 @@
package org.eclipse.jgit.treewalk;
import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.attributes.Attribute;
+import org.eclipse.jgit.attributes.Attributes;
import org.eclipse.jgit.attributes.AttributesNode;
import org.eclipse.jgit.attributes.AttributesNodeProvider;
import org.eclipse.jgit.attributes.AttributesProvider;
+import org.eclipse.jgit.attributes.Attribute.State;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@@ -258,7 +257,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
AbstractTreeIterator currentHead;
/** Cached attribute for the current entry */
- private Map<String, Attribute> attrs = null;
+ private Attributes attrs = null;
/**
* Create a new tree walker for a given repository.
@@ -1119,7 +1118,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
* @return a {@link Set} of {@link Attribute}s that match the current entry.
* @since 4.2
*/
- public Map<String, Attribute> getAttributes() {
+ public Attributes getAttributes() {
if (attrs != null)
return attrs;
@@ -1138,35 +1137,42 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
&& other == null) {
// Can not retrieve the attributes without at least one of the above
// iterators.
- return Collections.<String, Attribute> emptyMap();
+ return new Attributes();
}
String path = currentHead.getEntryPathString();
final boolean isDir = FileMode.TREE.equals(currentHead.mode);
- Map<String, Attribute> attributes = new LinkedHashMap<String, Attribute>();
+ Attributes attributes = new Attributes();
try {
- // Gets the info attributes
+ // Gets the global attributes node
+ AttributesNode globalNodeAttr = attributesNodeProvider
+ .getGlobalAttributesNode();
+ // Gets the info attributes node
AttributesNode infoNodeAttr = attributesNodeProvider
.getInfoAttributesNode();
+
+ // Gets the info attributes
if (infoNodeAttr != null) {
infoNodeAttr.getAttributes(path, isDir, attributes);
}
-
// Gets the attributes located on the current entry path
getPerDirectoryEntryAttributes(path, isDir, operationType,
- workingTreeIterator, dirCacheIterator, other,
- attributes);
+ workingTreeIterator, dirCacheIterator, other, attributes);
// Gets the attributes located in the global attribute file
- AttributesNode globalNodeAttr = attributesNodeProvider
- .getGlobalAttributesNode();
if (globalNodeAttr != null) {
globalNodeAttr.getAttributes(path, isDir, attributes);
}
} catch (IOException e) {
throw new JGitInternalException("Error while parsing attributes", e); //$NON-NLS-1$
}
+ // now after all attributes are collected - in the correct hierarchy
+ // order - remove all unspecified entries (the ! marker)
+ for (Attribute a : attributes.getAll()) {
+ if (a.getState() == State.UNSPECIFIED)
+ attributes.remove(a.getKey());
+ }
return attributes;
}
@@ -1195,7 +1201,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
private void getPerDirectoryEntryAttributes(String path, boolean isDir,
OperationType opType, WorkingTreeIterator workingTreeIterator,
DirCacheIterator dirCacheIterator, CanonicalTreeParser other,
- Map<String, Attribute> attributes)
+ Attributes attributes)
throws IOException {
// Prevents infinite recurrence
if (workingTreeIterator != null || dirCacheIterator != null
@@ -1208,12 +1214,11 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
getPerDirectoryEntryAttributes(path, isDir, opType,
getParent(workingTreeIterator, WorkingTreeIterator.class),
getParent(dirCacheIterator, DirCacheIterator.class),
- getParent(other, CanonicalTreeParser.class),
- attributes);
+ getParent(other, CanonicalTreeParser.class), attributes);
}
}
- private <T extends AbstractTreeIterator> T getParent(T current,
+ private static <T extends AbstractTreeIterator> T getParent(T current,
Class<T> type) {
if (current != null) {
AbstractTreeIterator parent = current.parent;
@@ -1224,7 +1229,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
return null;
}
- private <T> T getTree(Class<T> type) {
+ private <T extends AbstractTreeIterator> T getTree(Class<T> type) {
for (int i = 0; i < trees.length; i++) {
AbstractTreeIterator tree = trees[i];
if (type.isInstance(tree)) {