/** * Parse a tree object into a {@link NoteBucket} instance. * * The type of note tree is automatically detected by examining the items * within the tree, and allocating the proper storage type based on the * first note-like entry encountered. Since the method parses by guessing * the type on the first element, malformed note trees can be read as the * wrong type of tree. * * This method is not recursive, it parses the one tree given to it and * returns the bucket. If there are subtrees for note storage, they are * setup as lazy pointers that will be resolved at a later time. * * @param prefix * common hex digits that all notes within this tree share. The * root tree has {@code prefix.length() == 0}, the first-level * subtrees should be {@code prefix.length()==2}, etc. * @param treeId * the tree to read from the repository. * @param reader * reader to access the tree object. * @return bucket to holding the notes of the specified tree. * @throws IOException * {@code treeId} cannot be accessed. */ static InMemoryNoteBucket parse(AbbreviatedObjectId prefix, final ObjectId treeId, final ObjectReader reader) throws IOException { return new NoteParser(prefix, reader, treeId).parse(); }
private InMemoryNoteBucket parseTree() { for (; !eof(); next(1)) { if (pathLen == pathPadding + OBJECT_ID_STRING_LENGTH && isHex()) return parseLeafTree(); else if (getNameLength() == 2 && isHex() && isTree()) return parseFanoutTree(); else storeNonNote(); } // If we cannot determine the style used, assume its a leaf. return new LeafBucket(prefixLen); }
private void storeNonNote() { ObjectId id = getEntryObjectId(); FileMode fileMode = getEntryFileMode(); byte[] name = new byte[getNameLength()]; getName(name, 0); NonNoteEntry ent = new NonNoteEntry(name, fileMode, id); if (firstNonNote == null) firstNonNote = ent; if (lastNonNote != null) lastNonNote.next = ent; lastNonNote = ent; }
private FanoutBucket parseFanoutTree() { final FanoutBucket fanout = new FanoutBucket(prefixLen); for (; !eof(); next(1)) { final int cell = parseFanoutCell(); if (0 <= cell) fanout.setBucket(cell, getEntryObjectId()); else storeNonNote(); } return fanout; }
private LeafBucket parseLeafTree() { final LeafBucket leaf = new LeafBucket(prefixLen); final MutableObjectId idBuf = new MutableObjectId(); for (; !eof(); next(1)) { if (parseObjectId(idBuf)) leaf.parseOneEntry(idBuf, getEntryObjectId()); else storeNonNote(); } return leaf; }
private int parseFanoutCell() { if (getNameLength() == 2 && isTree()) { try { return (parseHexInt4(path[pathOffset + 0]) << 4) | parseHexInt4(path[pathOffset + 1]); } catch (ArrayIndexOutOfBoundsException notHex) { return -1; } } else { return -1; } }
private void load(ObjectId rootTree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { AbbreviatedObjectId none = AbbreviatedObjectId.fromString(""); //$NON-NLS-1$ root = NoteParser.parse(none, rootTree, reader); } }
private FanoutBucket parseFanoutTree() { final FanoutBucket fanout = new FanoutBucket(prefixLen); for (; !eof(); next(1)) { final int cell = parseFanoutCell(); if (0 <= cell) fanout.setBucket(cell, getEntryObjectId()); else storeNonNote(); } return fanout; }
private LeafBucket parseLeafTree() { final LeafBucket leaf = new LeafBucket(prefixLen); final MutableObjectId idBuf = new MutableObjectId(); for (; !eof(); next(1)) { if (parseObjectId(idBuf)) leaf.parseOneEntry(idBuf, getEntryObjectId()); else storeNonNote(); } return leaf; }
private int parseFanoutCell() { if (getNameLength() == 2 && isTree()) { try { return (parseHexInt4(path[pathOffset + 0]) << 4) | parseHexInt4(path[pathOffset + 1]); } catch (ArrayIndexOutOfBoundsException notHex) { return -1; } } else { return -1; } }
private InMemoryNoteBucket load(AnyObjectId prefix, ObjectReader or) throws IOException { AbbreviatedObjectId p = prefix.abbreviate(prefixLen + 2); InMemoryNoteBucket self = NoteParser.parse(p, treeId, or); table[cell(prefix)] = self; return self; } }
private InMemoryNoteBucket parseTree() { for (; !eof(); next(1)) { if (pathLen == pathPadding + OBJECT_ID_STRING_LENGTH && isHex()) return parseLeafTree(); else if (getNameLength() == 2 && isHex() && isTree()) return parseFanoutTree(); else storeNonNote(); } // If we cannot determine the style used, assume its a leaf. return new LeafBucket(prefixLen); }
private FanoutBucket parseFanoutTree() { final FanoutBucket fanout = new FanoutBucket(prefixLen); for (; !eof(); next(1)) { final int cell = parseFanoutCell(); if (0 <= cell) fanout.setBucket(cell, getEntryObjectId()); else storeNonNote(); } return fanout; }
private LeafBucket parseLeafTree() { final LeafBucket leaf = new LeafBucket(prefixLen); final MutableObjectId idBuf = new MutableObjectId(); for (; !eof(); next(1)) { if (parseObjectId(idBuf)) leaf.parseOneEntry(idBuf, getEntryObjectId()); else storeNonNote(); } return leaf; }
private void storeNonNote() { ObjectId id = getEntryObjectId(); FileMode fileMode = getEntryFileMode(); byte[] name = new byte[getNameLength()]; getName(name, 0); NonNoteEntry ent = new NonNoteEntry(name, fileMode, id); if (firstNonNote == null) firstNonNote = ent; if (lastNonNote != null) lastNonNote.next = ent; lastNonNote = ent; }
private int parseFanoutCell() { if (getNameLength() == 2 && isTree()) { try { return (parseHexInt4(path[pathOffset + 0]) << 4) | parseHexInt4(path[pathOffset + 1]); } catch (ArrayIndexOutOfBoundsException notHex) { return -1; } } else { return -1; } }
/** * Parse a tree object into a {@link NoteBucket} instance. * * The type of note tree is automatically detected by examining the items * within the tree, and allocating the proper storage type based on the * first note-like entry encountered. Since the method parses by guessing * the type on the first element, malformed note trees can be read as the * wrong type of tree. * * This method is not recursive, it parses the one tree given to it and * returns the bucket. If there are subtrees for note storage, they are * setup as lazy pointers that will be resolved at a later time. * * @param prefix * common hex digits that all notes within this tree share. The * root tree has {@code prefix.length() == 0}, the first-level * subtrees should be {@code prefix.length()==2}, etc. * @param treeId * the tree to read from the repository. * @param reader * reader to access the tree object. * @return bucket to holding the notes of the specified tree. * @throws IOException * {@code treeId} cannot be accessed. */ static InMemoryNoteBucket parse(AbbreviatedObjectId prefix, final ObjectId treeId, final ObjectReader reader) throws IOException { return new NoteParser(prefix, reader, treeId).parse(); }
private NonNoteEntry mergeNonNotes(NonNoteEntry baseList, NonNoteEntry oursList, NonNoteEntry theirsList) throws IOException { if (baseList == null && oursList == null && theirsList == null) return null; ObjectId baseId = write(baseList); ObjectId oursId = write(oursList); ObjectId theirsId = write(theirsList); inserter.flush(); Merger m = nonNotesMergeStrategy.newMerger(db, true); if (m instanceof ThreeWayMerger) ((ThreeWayMerger) m).setBase(baseId); if (!m.merge(oursId, theirsId)) throw new NotesMergeConflictException(baseList, oursList, theirsList); ObjectId resultTreeId = m.getResultTreeId(); AbbreviatedObjectId none = AbbreviatedObjectId.fromString(""); //$NON-NLS-1$ return NoteParser.parse(none, resultTreeId, reader).nonNotes; }
private InMemoryNoteBucket parseTree() { for (; !eof(); next(1)) { if (pathLen == pathPadding + OBJECT_ID_STRING_LENGTH && isHex()) return parseLeafTree(); else if (getNameLength() == 2 && isHex() && isTree()) return parseFanoutTree(); else storeNonNote(); } // If we cannot determine the style used, assume its a leaf. return new LeafBucket(prefixLen); }
private void storeNonNote() { ObjectId id = getEntryObjectId(); FileMode fileMode = getEntryFileMode(); byte[] name = new byte[getNameLength()]; getName(name, 0); NonNoteEntry ent = new NonNoteEntry(name, fileMode, id); if (firstNonNote == null) firstNonNote = ent; if (lastNonNote != null) lastNonNote.next = ent; lastNonNote = ent; }