Class AttributesHandler


  • public class AttributesHandler
    extends java.lang.Object
    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 Detail

      • BINARY_RULE_ATTRIBUTES

        private static final java.util.List<Attribute> BINARY_RULE_ATTRIBUTES
        This is the default binary rule that is present in any git folder [attr]binary -diff -merge -text
      • treeWalk

        private final TreeWalk treeWalk
      • expansions

        private final java.util.Map<java.lang.String,​java.util.List<Attribute>> expansions
    • Constructor Detail

      • AttributesHandler

        public AttributesHandler​(TreeWalk treeWalk)
                          throws java.io.IOException
        Create an AttributesHandler with default rules as well as merged rules from global, info and worktree root attributes
        Parameters:
        treeWalk - a TreeWalk
        Throws:
        java.io.IOException
    • Method Detail

      • mergeGlobalAttributes

        private void mergeGlobalAttributes​(java.lang.String entryPath,
                                           boolean isDirectory,
                                           Attributes result)
        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

        private void mergeInfoAttributes​(java.lang.String entryPath,
                                         boolean isDirectory,
                                         Attributes result)
        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​(java.lang.String entryPath,
                                                      int nameRoot,
                                                      boolean isDirectory,
                                                      @Nullable
                                                      WorkingTreeIterator workingTreeIterator,
                                                      @Nullable
                                                      DirCacheIterator dirCacheIterator,
                                                      @Nullable
                                                      CanonicalTreeParser otherTree,
                                                      Attributes result)
                                               throws java.io.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 none
        isDirectory - 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:
        java.io.IOException
      • mergeAttributes

        protected void mergeAttributes​(@Nullable
                                       AttributesNode node,
                                       java.lang.String entryPath,
                                       boolean isDirectory,
                                       Attributes result)
        Merges the matching node attributes for an entry path.
        Parameters:
        node - the node to scan for matches to entryPath
        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.
      • expandMacro

        protected void expandMacro​(Attribute attr,
                                   Attributes result)
        Expand a macro
        Parameters:
        attr - a Attribute
        result - 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 java.io.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 -
        workingTreeIterator -
        dirCacheIterator -
        otherTree -
        Returns:
        a AttributesNode of the current entry, NullPointerException otherwise.
        Throws:
        java.io.IOException - It raises an IOException if a problem appears while parsing one on the attributes file.