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 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; }
/** * Lookup a note for a specific ObjectId. * * @param id * the object to look for. * @return the note's blob ObjectId, or null if no note exists. * @throws java.io.IOException * a portion of the note space is not accessible. */ public ObjectId get(AnyObjectId id) throws IOException { Note n = root.getNote(id, reader); return n == null ? null : n.getData(); }
@Override InMemoryNoteBucket append(Note note) { if (shouldSplit()) { return split().append(note); } else { growIfFull(); notes[cnt++] = note; return this; } }
@Override InMemoryNoteBucket append(Note note) { int cell = cell(note); InMemoryNoteBucket b = (InMemoryNoteBucket) table[cell]; if (b == null) { LeafBucket n = new LeafBucket(prefixLen + 2); table[cell] = n.append(note); cnt++; } else { InMemoryNoteBucket n = b.append(note); if (n != b) table[cell] = n; } return this; }
InMemoryNoteBucket contractIfTooSmall(AnyObjectId noteOn, ObjectReader or) throws IOException { if (estimateSize(noteOn, or) < LeafBucket.MAX_SIZE) { // We are small enough to just contract to a single leaf. InMemoryNoteBucket r = new LeafBucket(prefixLen); for (Iterator<Note> i = iterator(noteOn, or); i.hasNext();) r = r.append(i.next()); r.nonNotes = nonNotes; return r; } return this; }
/** * Construct a new empty note map. * * @return an empty note map. */ public static NoteMap newEmptyMap() { NoteMap r = new NoteMap(null /* no reader */); r.root = new LeafBucket(0); return r; }
@Override int estimateSize(AnyObjectId objId, ObjectReader or) throws IOException { return load(objId, or).estimateSize(objId, or); }
FanoutBucket split() { FanoutBucket n = new FanoutBucket(prefixLen); for (int i = 0; i < cnt; i++) n.append(notes[i]); n.nonNotes = nonNotes; return n; } }
/** * Constructs a NoteMapMerger with * {@link org.eclipse.jgit.notes.DefaultNoteMerger} as the merger for notes * and the {@link org.eclipse.jgit.merge.MergeStrategy#RESOLVE} as the * strategy for resolving conflicts on non-notes * * @param db * Git repository */ public NoteMapMerger(Repository db) { this(db, new DefaultNoteMerger(), MergeStrategy.RESOLVE); }
/** * Determine if a note exists for the specified ObjectId. * * @param id * the object to look for. * @return true if a note exists; false if there is no note. * @throws java.io.IOException * a portion of the note space is not accessible. */ public boolean contains(AnyObjectId id) throws IOException { return get(id) != null; }
private InMemoryNoteBucket parse() { InMemoryNoteBucket r = parseTree(); r.nonNotes = firstNonNote; return r; }
/** * Lookup a note for a specific ObjectId. * * @param id * the object to look for. * @return the note for the given object id, or null if no note exists. * @throws java.io.IOException * a portion of the note space is not accessible. */ public Note getNote(AnyObjectId id) throws IOException { return root.getNote(id, reader); }