private static String noteData(Note n) { if (n != null) return n.getData().name(); return ""; //$NON-NLS-1$ }
/** * 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(); }
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); } } } } }
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); } } }
ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out);
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; }
private static String noteData(Note n) { if (n != null) return n.getData().name(); return ""; //$NON-NLS-1$ }
/** * Get content of note as string * * @param note * @return string */ protected String getContent(final Note note) { return BlobUtils.getContent(repository, note.getData()); }
private static String noteData(Note n) { if (n != null) return n.getData().name(); return ""; //$NON-NLS-1$ }
/** * 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 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(); }
/** * 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(); }
/** * Utility method that converts a note to a string (assuming it's UTF-8). */ private String noteToString(Repository repo, Note note) throws MissingObjectException, IOException, UnsupportedEncodingException { ObjectLoader loader = repo.open(note.getData()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); loader.copyTo(baos); return new String(baos.toByteArray(), "UTF-8"); }
/** * Extracts the text from a Note. * * @param note - the note * @return - the text * @throws IOException - failed */ public String noteText(final Note note) throws IOException { val buffer = new StringBuilder(); try (OutputStream bytes = new ByteArrayOutputStream()) { git.getRepository().open(note.getData()).copyTo(bytes); buffer.append(bytes.toString().concat("\n\n")); } return buffer.toString(); }
/** * Pulls the text form a Note object and writes it to the passes Outputstream. * * @param note - The Note contained in the repository to read. * @param output - The stream to ouput the note text. * @throws IOException - failed. */ public void writeNote(final Note note, final OutputStream output) throws IOException { if (!isUndefined()) { git.getRepository().open(note.getData()).copyTo(output); } }
private void add(T noteRecord) throws MissingObjectException, IncorrectObjectTypeException, IOException, RuntimeException { ObjectId noteContent = createNoteContent(noteRecord); if (ours.contains(reviewCommit)) { // merge the existing and the new note as if they are both new // means: base == null // there is not really a common ancestry for these two note revisions // use the same NoteMerger that is used from the NoteMapMerger NoteMerger noteMerger = new DefaultNoteMerger(); Note newNote = new Note(reviewCommit, noteContent); noteContent = noteMerger.merge(null, newNote, ours.getNote(reviewCommit), reader, inserter).getData(); } ours.set(reviewCommit, noteContent); }