/** {@inheritDoc} */ @Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) return theirs; if (theirs == null) return ours; if (ours.getData().equals(theirs.getData())) return ours; ObjectLoader lo = reader.open(ours.getData()); ObjectLoader lt = reader.open(theirs.getData()); try (UnionInputStream union = new UnionInputStream(lo.openStream(), lt.openStream())) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + lt.getSize(), union); return new Note(ours, noteData); } } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: "); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); } } } } }
private TreeFormatter build() { byte[] nameBuf = new byte[OBJECT_ID_STRING_LENGTH]; int nameLen = OBJECT_ID_STRING_LENGTH - prefixLen; TreeFormatter fmt = new TreeFormatter(treeSize(nameLen)); NonNoteEntry e = nonNotes; for (int i = 0; i < cnt; i++) { Note n = notes[i]; n.copyTo(nameBuf, 0); while (e != null && e.pathCompare(nameBuf, prefixLen, nameLen, REGULAR_FILE) < 0) { e.format(fmt); e = e.next; } fmt.append(nameBuf, prefixLen, nameLen, REGULAR_FILE, n.getData()); } for (; e != null; e = e.next) e.format(fmt); return fmt; }
@Override InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { int p = search(noteOn); if (0 <= p) { if (noteData != null) { notes[p].setData(noteData.copy()); return this; } else { System.arraycopy(notes, p + 1, notes, p, cnt - p - 1); cnt--; return 0 < cnt ? this : null; } } else if (noteData != null) { if (shouldSplit()) { return split().set(noteOn, noteData, or); } else { growIfFull(); p = -(p + 1); if (p < cnt) System.arraycopy(notes, p, notes, p + 1, cnt - p); notes[p] = new Note(noteOn, noteData.copy()); cnt++; return this; } } else { return this; } }
@Override public boolean equals(Object o){ if (o instanceof Note) { Note target = (Note) o; if(this.name.equals(target.getName()) && this.friends.equals(target.getFriends())){ return true; } } return false; }
void parseOneEntry(AnyObjectId noteOn, AnyObjectId noteData) { growIfFull(); notes[cnt++] = new Note(noteOn, noteData.copy()); }
/** * Retrieves all the reviews in the current project's repository by commit hash. */ public Map<String, Review> listReviews() throws GitClientException { // Get the most up-to-date list of reviews. syncCommentsAndReviews(); Map<String, Review> reviews = new LinkedHashMap<>(); Git git = new Git(repo); try { ListNotesCommand cmd = git.notesList(); cmd.setNotesRef(REVIEWS_REF); List<Note> notes = cmd.call(); for (Note note : notes) { String rawNoteDataStr = noteToString(repo, note); Review latest = extractLatestReviewFromNotes(rawNoteDataStr); if (latest != null) { reviews.put(note.getName(), latest); } } } catch (Exception e) { throw new GitClientException(e); } finally { git.close(); } return reviews; }
private TreeFormatter build() { byte[] nameBuf = new byte[OBJECT_ID_STRING_LENGTH]; int nameLen = OBJECT_ID_STRING_LENGTH - prefixLen; TreeFormatter fmt = new TreeFormatter(treeSize(nameLen)); NonNoteEntry e = nonNotes; for (int i = 0; i < cnt; i++) { Note n = notes[i]; n.copyTo(nameBuf, 0); while (e != null && e.pathCompare(nameBuf, prefixLen, nameLen, REGULAR_FILE) < 0) { e.format(fmt); e = e.next; } fmt.append(nameBuf, prefixLen, nameLen, REGULAR_FILE, n.getData()); } for (; e != null; e = e.next) e.format(fmt); return fmt; }
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { int p = search(noteOn); if (0 <= p) { if (noteData != null) { notes[p].setData(noteData.copy()); return this; } else { System.arraycopy(notes, p + 1, notes, p, cnt - p - 1); cnt--; return 0 < cnt ? this : null; } } else if (noteData != null) { if (shouldSplit()) { return split().set(noteOn, noteData, or); } else { growIfFull(); p = -(p + 1); if (p < cnt) System.arraycopy(notes, p, notes, p + 1, cnt - p); notes[p] = new Note(noteOn, noteData.copy()); cnt++; return this; } } else { return this; } }
/** {@inheritDoc} */ @SuppressWarnings("nls") @Override public String toString() { return "Note[" + name() + " -> " + data.name() + "]"; } }
void parseOneEntry(AnyObjectId noteOn, AnyObjectId noteData) { growIfFull(); notes[cnt++] = new Note(noteOn, noteData.copy()); }
private static String noteData(Note n) { if (n != null) return n.getData().name(); return ""; //$NON-NLS-1$ }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: "); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); } } } } }
/** {@inheritDoc} */ @Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) return theirs; if (theirs == null) return ours; if (ours.getData().equals(theirs.getData())) return ours; ObjectLoader lo = reader.open(ours.getData()); ObjectLoader lt = reader.open(theirs.getData()); try (UnionInputStream union = new UnionInputStream(lo.openStream(), lt.openStream())) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + lt.getSize(), union); return new Note(ours, noteData); } } }
private TreeFormatter build() { byte[] nameBuf = new byte[OBJECT_ID_STRING_LENGTH]; int nameLen = OBJECT_ID_STRING_LENGTH - prefixLen; TreeFormatter fmt = new TreeFormatter(treeSize(nameLen)); NonNoteEntry e = nonNotes; for (int i = 0; i < cnt; i++) { Note n = notes[i]; n.copyTo(nameBuf, 0); while (e != null && e.pathCompare(nameBuf, prefixLen, nameLen, REGULAR_FILE) < 0) { e.format(fmt); e = e.next; } fmt.append(nameBuf, prefixLen, nameLen, REGULAR_FILE, n.getData()); } for (; e != null; e = e.next) e.format(fmt); return fmt; }
@Override InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { int p = search(noteOn); if (0 <= p) { if (noteData != null) { notes[p].setData(noteData.copy()); return this; } else { System.arraycopy(notes, p + 1, notes, p, cnt - p - 1); cnt--; return 0 < cnt ? this : null; } } else if (noteData != null) { if (shouldSplit()) { return split().set(noteOn, noteData, or); } else { growIfFull(); p = -(p + 1); if (p < cnt) System.arraycopy(notes, p, notes, p + 1, cnt - p); notes[p] = new Note(noteOn, noteData.copy()); cnt++; return this; } } else { return this; } }