/** Returns all of the .gitattributes files which affect the given files. */ static List<File> gitAttributes(Iterable<File> files) { // build a radix tree out of all the parent folders in these files ConcurrentRadixTree<String> tree = new ConcurrentRadixTree<>(new DefaultCharSequenceNodeFactory()); for (File file : files) { String parentPath = file.getParent() + File.separator; tree.putIfAbsent(parentPath, parentPath); } // traverse the edge nodes to find the outermost folders List<File> edgeFolders = TreeStream.depthFirst(Node::getOutgoingEdges, tree.getNode()) .filter(node -> node.getOutgoingEdges().isEmpty() && node.getValue() != null) .map(node -> new File((String) node.getValue())) .collect(Collectors.toList()); List<File> gitAttrFiles = new ArrayList<>(); Set<File> visitedFolders = new HashSet<>(); for (File edgeFolder : edgeFolders) { gitAttrAddWithParents(edgeFolder, visitedFolders, gitAttrFiles); } return gitAttrFiles; }
/** Returns all of the .gitattributes files which affect the given files. */ static List<File> gitAttributes(Iterable<File> files) { // build a radix tree out of all the parent folders in these files ConcurrentRadixTree<String> tree = new ConcurrentRadixTree<>(new DefaultCharSequenceNodeFactory()); for (File file : files) { String parentPath = file.getParent() + File.separator; tree.putIfAbsent(parentPath, parentPath); } // traverse the edge nodes to find the outermost folders List<File> edgeFolders = TreeStream.depthFirst(Node::getOutgoingEdges, tree.getNode()) .filter(node -> node.getOutgoingEdges().isEmpty() && node.getValue() != null) .map(node -> new File((String) node.getValue())) .collect(Collectors.toList()); List<File> gitAttrFiles = new ArrayList<>(); Set<File> visitedFolders = new HashSet<>(); for (File edgeFolder : edgeFolders) { gitAttrAddWithParents(edgeFolder, visitedFolders, gitAttrFiles); } return gitAttrFiles; }