/** * Whether the attribute with the given key is unspecified * * @param key * a {@link java.lang.String} object. * @return true if the key is * {@link org.eclipse.jgit.attributes.Attribute.State#UNSPECIFIED}, * false in all other cases */ public boolean isUnspecified(String key) { return (getState(key) == State.UNSPECIFIED); }
/** * Creates a new instance * * @param attributes * a {@link org.eclipse.jgit.attributes.Attribute} */ public Attributes(Attribute... attributes) { if (attributes != null) { for (Attribute a : attributes) { put(a); } } }
/** * Merges the matching GLOBAL attributes for an entry path. * * @param 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 '\'). * @param isDirectory * true if the target item is a directory. * @param result * that will hold the attributes matching this entry path. This * method will NOT override any existing entry in attributes. */ private void mergeGlobalAttributes(String entryPath, boolean isDirectory, Attributes result) { mergeAttributes(globalNode, entryPath, isDirectory, result); }
String entryPath = treeWalk.getPathString(); boolean isDirectory = (treeWalk.getFileMode() == FileMode.TREE); Attributes attributes = new Attributes(); mergeInfoAttributes(entryPath, isDirectory, attributes); mergePerDirectoryEntryAttributes(entryPath, entryPath.lastIndexOf('/'), isDirectory, treeWalk.getTree(WorkingTreeIterator.class), mergeGlobalAttributes(entryPath, isDirectory, attributes); for (Attribute a : attributes.getAll()) { if (a.getState() == State.UNSPECIFIED) attributes.remove(a.getKey());
AttributesNodeProvider attributesNodeProvider =treeWalk.getAttributesNodeProvider(); this.globalNode = attributesNodeProvider != null ? attributesNodeProvider.getGlobalAttributesNode() : null; this.infoNode = attributesNodeProvider != null ? attributesNodeProvider.getInfoAttributesNode() : null; AttributesNode rootNode = attributesNode(treeWalk, rootOf( treeWalk.getTree(WorkingTreeIterator.class)), rootOf( treeWalk.getTree(DirCacheIterator.class)), rootOf(treeWalk .getTree(CanonicalTreeParser.class))); continue; for (AttributesRule rule : node.getRules()) { if (rule.getPattern().startsWith(MACRO_PREFIX)) { expansions.put(rule.getPattern() .substring(MACRO_PREFIX.length()).trim(), rule.getAttributes());
/** Parses an attribute value from a list of rules, returning null if there is no match for the given key. */ private static @Nullable String findAttributeInRules(String subpath, boolean isFolder, String key, List<AttributesRule> rules) { String value = null; // later rules override earlier ones for (AttributesRule rule : rules) { if (rule.isMatch(subpath, isFolder)) { for (Attribute attribute : rule.getAttributes()) { if (attribute.getKey().equals(key)) { value = attribute.getValue(); } } } } return value; } }
AttributesNode load() throws IOException { AttributesNode r = new AttributesNode(); try (InputStream in = entry.openInputStream()) { r.parse(in); } return r.getRules().isEmpty() ? null : r; } }
/** * Test if the given attributes implies to handle the related entry as a * binary file (i.e. if the entry has an -merge or a merge=binary attribute) * or if it can be content merged. * * @return <code>true</code> if the entry can be content merged, * <code>false</code> otherwise * @since 4.9 */ public boolean canBeContentMerged() { if (isUnset(Constants.ATTR_MERGE)) { return false; } else if (isCustom(Constants.ATTR_MERGE) && getValue(Constants.ATTR_MERGE) .equals(Constants.ATTR_BUILTIN_BINARY_MERGER)) { return false; } return true; }
/** * Get attribute value * * @param key * an attribute key * @return the attribute value (may be <code>null</code>) */ public String getValue(String key) { Attribute a = map.get(key); return a != null ? a.getValue() : null; }
/** * Put an attribute * * @param a * an {@link org.eclipse.jgit.attributes.Attribute} */ public void put(Attribute a) { map.put(a.getKey(), a); }
private static AttributesNode noAttributes() { return new AttributesNode(Collections.<AttributesRule> emptyList()); } }
static void loadRulesFromFile(AttributesNode r, File attrs) throws FileNotFoundException, IOException { if (attrs.exists()) { try (FileInputStream in = new FileInputStream(attrs)) { r.parse(in); } } }
/** * Return the state. * * @param key * key of an attribute * @return the state (never returns <code>null</code>) */ public Attribute.State getState(String key) { Attribute a = map.get(key); return a != null ? a.getState() : Attribute.State.UNSPECIFIED; }
/** {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + key.hashCode(); result = prime * result + state.hashCode(); result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; }
private TreeWalk(final @Nullable Repository repo, final ObjectReader or, final boolean closeReader) { if (repo != null) { config = repo.getConfig(); attributesNodeProvider = repo.createAttributesNodeProvider(); filterCommands = FilterCommandRegistry .getRegisteredFilterCommands(); } else { config = null; attributesNodeProvider = null; } reader = or; filter = TreeFilter.ALL; trees = NO_TREES; this.closeReader = closeReader; }
AttributesNode load(ObjectReader reader) throws IOException { AttributesNode r = new AttributesNode(); ObjectLoader loader = reader.open(objectId); if (loader != null) { try (InputStream in = loader.openStream()) { r.parse(in); } } return r.getRules().isEmpty() ? null : r; } }
/** * Whether the attribute is unset * * @param key * a {@link java.lang.String} object. * @return true if the key is * {@link org.eclipse.jgit.attributes.Attribute.State#UNSET}, false * in all other cases */ public boolean isUnset(String key) { return (getState(key) == State.UNSET); }
/** * Merges the matching INFO attributes for an entry path. * * @param 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 '\'). * @param isDirectory * true if the target item is a directory. * @param result * that will hold the attributes matching this entry path. This * method will NOT override any existing entry in attributes. */ private void mergeInfoAttributes(String entryPath, boolean isDirectory, Attributes result) { mergeAttributes(infoNode, entryPath, isDirectory, result); }
/** * Whether the attribute is set * * @param key * a {@link java.lang.String} object. * @return true if the key is * {@link org.eclipse.jgit.attributes.Attribute.State#SET}, false in * all other cases */ public boolean isSet(String key) { return (getState(key) == State.SET); }
/** * Is this a custom attribute * * @param key * a {@link java.lang.String} object. * @return true if the key is * {@link org.eclipse.jgit.attributes.Attribute.State#CUSTOM}, false * in all other cases see {@link #getValue(String)} for the value of * the key */ public boolean isCustom(String key) { return (getState(key) == State.CUSTOM); }