Package org.eclipse.jgit.attributes
Class AttributesHandler
java.lang.Object
org.eclipse.jgit.attributes.AttributesHandler
The attributes handler knows how to retrieve, parse and merge attributes from
the various gitattributes files. Furthermore it collects and expands macro
expressions. The method
getAttributes() yields the ready processed
attributes for the current path represented by the
TreeWalk
The implementation is based on the specifications in http://git-scm.com/docs/gitattributes
- Since:
- 4.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Supplier<CanonicalTreeParser>This is the default binary rule that is present in any git folder[attr]binary -diff -merge -textprivate static final Stringprivate final AttributesNodeprivate final AttributesNodeprivate static final Stringprivate final TreeWalk -
Constructor Summary
ConstructorsConstructorDescriptionAttributesHandler(TreeWalk treeWalk) Deprecated.AttributesHandler(TreeWalk treeWalk, Supplier<CanonicalTreeParser> attributesTree) Create anAttributesHandlerwith default rules as well as merged rules from global, info and worktree root attributes -
Method Summary
Modifier and TypeMethodDescriptionprivate static AttributesNodeattributesNode(TreeWalk treeWalk, WorkingTreeIterator workingTreeIterator, DirCacheIterator dirCacheIterator, CanonicalTreeParser otherTree) Get theAttributesNodefor the current entry.protected voidexpandMacro(Attribute attr, Attributes result) Expand a macroprotected voidmergeAttributes(AttributesNode node, String entryPath, boolean isDirectory, Attributes result) Merges the matching node attributes for an entry path.private voidmergeGlobalAttributes(String entryPath, boolean isDirectory, Attributes result) Merges the matching GLOBAL attributes for an entry path.private voidmergeInfoAttributes(String entryPath, boolean isDirectory, Attributes result) Merges the matching INFO attributes for an entry path.private voidmergePerDirectoryEntryAttributes(String entryPath, int nameRoot, boolean isDirectory, WorkingTreeIterator workingTreeIterator, DirCacheIterator dirCacheIterator, CanonicalTreeParser otherTree, Attributes result) Merges the matching working directory attributes for an entry path.private static <T extends AbstractTreeIterator>
TparentOf(T node) private static <T extends AbstractTreeIterator>
TrootOf(T node)
-
Field Details
-
MACRO_PREFIX
- See Also:
-
BINARY_RULE_KEY
- See Also:
-
BINARY_RULE_ATTRIBUTES
This is the default binary rule that is present in any git folder[attr]binary -diff -merge -text -
treeWalk
-
attributesTree
-
globalNode
-
infoNode
-
expansions
-
-
Constructor Details
-
AttributesHandler
Deprecated.since 6.1, useAttributesHandler(TreeWalk, Supplier)insteadCreate anAttributesHandlerwith default rules as well as merged rules from global, info and worktree root attributes- Parameters:
treeWalk- aTreeWalk- Throws:
IOException
-
AttributesHandler
public AttributesHandler(TreeWalk treeWalk, Supplier<CanonicalTreeParser> attributesTree) throws IOException Create anAttributesHandlerwith default rules as well as merged rules from global, info and worktree root attributes- Parameters:
treeWalk- aTreeWalkattributesTree- the tree to read .gitattributes from- Throws:
IOException- Since:
- 6.1
-
-
Method Details
-
getAttributes
- Returns:
- the
Attributesfor the current path represented by theTreeWalk - Throws:
IOException
-
mergeGlobalAttributes
Merges the matching GLOBAL attributes for an entry path.- Parameters:
entryPath- the path to test. The path must be relative to this attribute node's own repository path, and in repository path format (uses '/' and not '\').isDirectory- true if the target item is a directory.result- that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
-
mergeInfoAttributes
Merges the matching INFO attributes for an entry path.- Parameters:
entryPath- the path to test. The path must be relative to this attribute node's own repository path, and in repository path format (uses '/' and not '\').isDirectory- true if the target item is a directory.result- that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
-
mergePerDirectoryEntryAttributes
private void mergePerDirectoryEntryAttributes(String entryPath, int nameRoot, boolean isDirectory, @Nullable WorkingTreeIterator workingTreeIterator, @Nullable DirCacheIterator dirCacheIterator, @Nullable CanonicalTreeParser otherTree, Attributes result) throws IOException Merges the matching working directory attributes for an entry path.- Parameters:
entryPath- the path to test. The path must be relative to this attribute node's own repository path, and in repository path format (uses '/' and not '\').nameRoot- index of the '/' preceeding the current level, or -1 if noneisDirectory- true if the target item is a directory.workingTreeIterator-dirCacheIterator-otherTree-result- that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.- Throws:
IOException
-
mergeAttributes
protected void mergeAttributes(@Nullable AttributesNode node, String entryPath, boolean isDirectory, Attributes result) Merges the matching node attributes for an entry path.- Parameters:
node- the node to scan for matches to entryPathentryPath- the path to test. The path must be relative to this attribute node's own repository path, and in repository path format (uses '/' and not '\').isDirectory- true if the target item is a directory.result- that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
-
expandMacro
Expand a macro- Parameters:
attr- aAttributeresult- contains the (recursive) expanded and merged macro attributes including the attribute iself
-
attributesNode
private static AttributesNode attributesNode(TreeWalk treeWalk, @Nullable WorkingTreeIterator workingTreeIterator, @Nullable DirCacheIterator dirCacheIterator, @Nullable CanonicalTreeParser otherTree) throws IOException Get theAttributesNodefor the current entry.This method implements the fallback mechanism between the index and the working tree depending on the operation type
- Parameters:
treeWalk-workingTreeIterator-dirCacheIterator-otherTree-- Returns:
- a
AttributesNodeof the current entry,NullPointerExceptionotherwise. - Throws:
IOException- It raises anIOExceptionif a problem appears while parsing one on the attributes file.
-
parentOf
-
rootOf
-
AttributesHandler(TreeWalk, Supplier)instead