diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java index df31558ff..c24efe20a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java @@ -64,11 +64,11 @@ /** Parses raw Git trees from the canonical semi-text/semi-binary format. */ public class CanonicalTreeParser extends AbstractTreeIterator { - private static final int ATTRIBUTESLENGTH = Constants.DOT_GIT_ATTRIBUTES - .getBytes().length; - private static final byte[] EMPTY = {}; + private static final byte[] ATTRS = Constants + .encode(Constants.DOT_GIT_ATTRIBUTES); + private byte[] raw; /** First offset within {@link #raw} of the prior entry. */ @@ -375,11 +375,9 @@ private void parseEntry() { nextPtr = ptr + Constants.OBJECT_ID_LENGTH; // Check if this entry is a .gitattributes file - if (RawParseUtils.match(path, pathOffset, - Constants.DOT_GIT_ATTRIBUTES.getBytes()) == ATTRIBUTESLENGTH) - attributesNode = new LazyLoadingAttributesNode( - ObjectId.fromRaw(idBuffer(), idOffset())); - + if (path[pathOffset] == '.' + && RawParseUtils.match(path, pathOffset, ATTRS) > 0) + attributesNode = new LazyLoadingAttributesNode(idOffset()); } /** @@ -402,18 +400,18 @@ public AttributesNode getEntryAttributesNode(ObjectReader reader) /** * {@link AttributesNode} implementation that provides lazy loading */ - private static class LazyLoadingAttributesNode extends AttributesNode { - final ObjectId objectId; + private class LazyLoadingAttributesNode extends AttributesNode { + private final int idOffset; - LazyLoadingAttributesNode(ObjectId objectId) { + LazyLoadingAttributesNode(int idOffset) { super(Collections. emptyList()); - this.objectId = objectId; - + this.idOffset = idOffset; } AttributesNode load(ObjectReader reader) throws IOException { AttributesNode r = new AttributesNode(); - ObjectLoader loader = reader.open(objectId); + ObjectId id = ObjectId.fromRaw(raw, idOffset); + ObjectLoader loader = reader.open(id); if (loader != null) { InputStream in = loader.openStream(); try { @@ -425,5 +423,4 @@ AttributesNode load(ObjectReader reader) throws IOException { return r.getRules().isEmpty() ? null : r; } } - }