Top Description Fields Constructors Methods
org.eclipse.jgit.attributes

public Class AttributesHandler

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.HashMap, .List, .ListIterator, .Map, java.util.function.Supplier, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.attributes.Attribute.State, org.eclipse.jgit.dircache.DirCacheIterator, org.eclipse.jgit.lib.FileMode, org.eclipse.jgit.treewalk.AbstractTreeIterator, .CanonicalTreeParser, .TreeWalk, .TreeWalk.OperationType, .WorkingTreeIterator

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 org.eclipse.jgit.treewalk.TreeWalk

The implementation is based on the specifications in http://git-scm.com/docs/gitattributes

Since
4.3

Field Summary

Modifier and TypeField and Description
private final Supplier<CanonicalTreeParser>
private static final List<Attribute>
BINARY_RULE_ATTRIBUTES

This is the default binary rule that is present in any git folder [attr]binary -diff -merge -text

private static final String
private final Map<String, List<Attribute>>
private final AttributesNode
private final AttributesNode
private static final String
private final TreeWalk

Constructor Summary

AccessConstructor and Description
public
AttributesHandler(TreeWalk treeWalk)
Deprecated since 6.1, use AttributesHandler(TreeWalk, Supplier) instead

Create an org.eclipse.jgit.attributes.AttributesHandler with default rules as well as merged rules from global, info and worktree root attributes

public
AttributesHandler(TreeWalk treeWalk, Supplier<CanonicalTreeParser>
the tree to read .gitattributes from
attributesTree
)

Create an org.eclipse.jgit.attributes.AttributesHandler with default rules as well as merged rules from global, info and worktree root attributes

Method Summary

Modifier and TypeMethod and Description
private static AttributesNode

Returns:

a AttributesNode of the current entry, NullPointerException otherwise.
attributesNode
(TreeWalk
used to walk trees
treeWalk
,
WorkingTreeIterator
used to walk the working tree
workingTreeIterator
,
DirCacheIterator
used to walk the dircache
dirCacheIterator
,
CanonicalTreeParser
another tree
otherTree
)

Get the AttributesNode for the current entry.

protected void
expandMacro(Attribute attr, Attributes
contains the (recursive) expanded and merged macro attributes including the attribute iself
result
)

Expand a macro

public Attributes
protected void
mergeAttributes(AttributesNode
the node to scan for matches to entryPath
node
,
String
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 '\').
entryPath
,
boolean
true if the target item is a directory.
isDirectory
,
Attributes
that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
result
)

Merges the matching node attributes for an entry path.

private void
mergeGlobalAttributes(String
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 '\').
entryPath
,
boolean
true if the target item is a directory.
isDirectory
,
Attributes
that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
result
)

Merges the matching GLOBAL attributes for an entry path.

private void
mergeInfoAttributes(String
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 '\').
entryPath
,
boolean
true if the target item is a directory.
isDirectory
,
Attributes
that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
result
)

Merges the matching INFO attributes for an entry path.

private void
mergePerDirectoryEntryAttributes(String
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 '\').
entryPath
,
int
index of the '/' preceeding the current level, or -1 if none
nameRoot
,
boolean
true if the target item is a directory.
isDirectory
,
WorkingTreeIterator
the working tree iterator
workingTreeIterator
,
DirCacheIterator
the dircache iterator
dirCacheIterator
,
CanonicalTreeParser
another tree
otherTree
,
Attributes
that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.
result
)

Merges the matching working directory attributes for an entry path.

private static <T extends AbstractTreeIterator> T
parentOf(T node)

private static <T extends AbstractTreeIterator> T
rootOf(T node)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesTreeback to summary
private final Supplier<CanonicalTreeParser> attributesTree
BINARY_RULE_ATTRIBUTESback to summary
private static final List<Attribute> BINARY_RULE_ATTRIBUTES

This is the default binary rule that is present in any git folder [attr]binary -diff -merge -text

BINARY_RULE_KEYback to summary
private static final String BINARY_RULE_KEY
expansionsback to summary
private final Map<String, List<Attribute>> expansions
globalNodeback to summary
private final AttributesNode globalNode
infoNodeback to summary
private final AttributesNode infoNode
MACRO_PREFIXback to summary
private static final String MACRO_PREFIX
treeWalkback to summary
private final TreeWalk treeWalk

Constructor Detail

AttributesHandlerback to summary
public AttributesHandler(TreeWalk treeWalk) throws IOException

Deprecated

since 6.1, use AttributesHandler(TreeWalk, Supplier) instead

Create an org.eclipse.jgit.attributes.AttributesHandler with default rules as well as merged rules from global, info and worktree root attributes

Parameters
treeWalk:TreeWalk

a org.eclipse.jgit.treewalk.TreeWalk

Annotations
@Deprecated
Exceptions
IOException:
if an IO error occurred
AttributesHandlerback to summary
public AttributesHandler(TreeWalk treeWalk, Supplier<CanonicalTreeParser> attributesTree) throws IOException

Create an org.eclipse.jgit.attributes.AttributesHandler with default rules as well as merged rules from global, info and worktree root attributes

Parameters
treeWalk:TreeWalk

a org.eclipse.jgit.treewalk.TreeWalk

attributesTree:Supplier<CanonicalTreeParser>

the tree to read .gitattributes from

Exceptions
IOException:
if an IO error occurred
Since
6.1

Method Detail

attributesNodeback to summary
private static AttributesNode attributesNode(TreeWalk treeWalk, WorkingTreeIterator workingTreeIterator, DirCacheIterator dirCacheIterator, CanonicalTreeParser otherTree) throws IOException

Get the AttributesNode for the current entry.

This method implements the fallback mechanism between the index and the working tree depending on the operation type

Parameters
treeWalk:TreeWalk

used to walk trees

workingTreeIterator:WorkingTreeIterator

used to walk the working tree

dirCacheIterator:DirCacheIterator

used to walk the dircache

otherTree:CanonicalTreeParser

another tree

Returns:AttributesNode

a AttributesNode of the current entry, NullPointerException otherwise.

Exceptions
IOException:
It raises an IOException if a problem appears while parsing one on the attributes file.
expandMacroback to summary
protected void expandMacro(Attribute attr, Attributes result)

Expand a macro

Parameters
attr:Attribute

a org.eclipse.jgit.attributes.Attribute

result:Attributes

contains the (recursive) expanded and merged macro attributes including the attribute iself

getAttributesback to summary
public Attributes getAttributes() throws IOException

See org.eclipse.jgit.treewalk.TreeWalk#getAttributes()

Returns:Attributes

the org.eclipse.jgit.attributes.Attributes for the current path represented by the org.eclipse.jgit.treewalk.TreeWalk

Exceptions
IOException:
if an IO error occurred
mergeAttributesback to summary
protected void mergeAttributes(AttributesNode node, String entryPath, boolean isDirectory, Attributes result)

Merges the matching node attributes for an entry path.

Parameters
node:AttributesNode

the node to scan for matches to entryPath

entryPath:String

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:boolean

true if the target item is a directory.

result:Attributes

that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.

mergeGlobalAttributesback to summary
private void mergeGlobalAttributes(String entryPath, boolean isDirectory, Attributes result)

Merges the matching GLOBAL attributes for an entry path.

Parameters
entryPath:String

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:boolean

true if the target item is a directory.

result:Attributes

that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.

mergeInfoAttributesback to summary
private void mergeInfoAttributes(String entryPath, boolean isDirectory, Attributes result)

Merges the matching INFO attributes for an entry path.

Parameters
entryPath:String

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:boolean

true if the target item is a directory.

result:Attributes

that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.

mergePerDirectoryEntryAttributesback to summary
private void mergePerDirectoryEntryAttributes(String entryPath, int nameRoot, boolean isDirectory, WorkingTreeIterator workingTreeIterator, DirCacheIterator dirCacheIterator, CanonicalTreeParser otherTree, Attributes result) throws IOException

Merges the matching working directory attributes for an entry path.

Parameters
entryPath:String

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:int

index of the '/' preceeding the current level, or -1 if none

isDirectory:boolean

true if the target item is a directory.

workingTreeIterator:WorkingTreeIterator

the working tree iterator

dirCacheIterator:DirCacheIterator

the dircache iterator

otherTree:CanonicalTreeParser

another tree

result:Attributes

that will hold the attributes matching this entry path. This method will NOT override any existing entry in attributes.

Exceptions
IOException:
if an IO error occurred
parentOfback to summary
private static <T extends AbstractTreeIterator> T parentOf(T node)
rootOfback to summary
private static <T extends AbstractTreeIterator> T rootOf(T node)