List of usage examples for org.eclipse.jgit.notes Note getData
public ObjectId getData()
From source file:com.buildautomation.jgit.api.AddAndListNoteOfCommit.java
License:Apache License
public static void addAndListNoteOfCommit() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.exactRef("refs/heads/master"); System.out.println("Found head: " + head); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Found Commit: " + commit); try (Git git = new Git(repository)) { git.notesAdd().setMessage("some note message").setObjectId(commit).call(); System.out.println("Added Note to commit " + commit); List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { // check if we found the note for this commit if (!note.getName().equals(head.getObjectId().getName())) { System.out.println("Note " + note + " did not match commit " + head); continue; }// w w w. ja va 2s .c o m System.out.println("Found note: " + note + " for commit " + head); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); } } walk.dispose(); } } }
From source file:com.buildautomation.jgit.api.ListNotes.java
License:Apache License
public static void listNotes() 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); }/*from www. ja v a2 s . c o m*/ } } }
From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java
License:Open Source License
/** * Utility method that converts a note to a string (assuming it's UTF-8). *//* w w w . j av a2 s . c o m*/ 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"); }
From source file:com.google.gerrit.gpg.PublicKeyStore.java
License:Apache License
/** * Read public keys with the given key ID. * <p>/*from ww w.j ava 2 s . c om*/ * Keys should not be trusted unless checked with {@link PublicKeyChecker}. * <p> * Multiple calls to this method use the same state of the key ref; to reread * the ref, call {@link #close()} first. * * @param keyId key ID. * @return any keys found that could be successfully parsed. * @throws PGPException if an error occurred parsing the key data. * @throws IOException if an error occurred reading the repository data. */ public PGPPublicKeyRingCollection get(long keyId) throws PGPException, IOException { if (reader == null) { load(); } if (notes == null) { return empty(); } Note note = notes.getNote(keyObjectId(keyId)); if (note == null) { return empty(); } List<PGPPublicKeyRing> keys = new ArrayList<>(); try (InputStream in = reader.open(note.getData(), OBJ_BLOB).openStream()) { while (true) { @SuppressWarnings("unchecked") Iterator<Object> it = new BcPGPObjectFactory(new ArmoredInputStream(in)).iterator(); if (!it.hasNext()) { break; } Object obj = it.next(); if (obj instanceof PGPPublicKeyRing) { keys.add((PGPPublicKeyRing) obj); } checkState(!it.hasNext(), "expected one PGP object per ArmoredInputStream"); } return new PGPPublicKeyRingCollection(keys); } }
From source file:com.google.gerrit.server.account.externalids.ExternalIdReader.java
License:Apache License
/** Reads and returns all external IDs. */ private Set<ExternalId> all(Repository repo, ObjectId rev) throws IOException { if (rev.equals(ObjectId.zeroId())) { return ImmutableSet.of(); }//from www .ja va2 s .c o m try (Timer0.Context ctx = readAllLatency.start(); RevWalk rw = new RevWalk(repo)) { NoteMap noteMap = readNoteMap(rw, rev); Set<ExternalId> extIds = new HashSet<>(); for (Note note : noteMap) { byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); try { extIds.add(ExternalId.parse(note.getName(), raw)); } catch (Exception e) { log.error(String.format("Ignoring invalid external ID note %s", note.getName()), e); } } return extIds; } }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsConsistencyChecker.java
License:Apache License
private List<ConsistencyProblemInfo> check(Repository repo, ObjectId commit) throws IOException { List<ConsistencyProblemInfo> problems = new ArrayList<>(); ListMultimap<String, ExternalId.Key> emails = MultimapBuilder.hashKeys().arrayListValues().build(); try (RevWalk rw = new RevWalk(repo)) { NoteMap noteMap = ExternalIdReader.readNoteMap(rw, commit); for (Note note : noteMap) { byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB) .getCachedBytes(ExternalIdReader.MAX_NOTE_SZ); try { ExternalId extId = ExternalId.parse(note.getName(), raw); problems.addAll(validateExternalId(extId)); if (extId.email() != null) { emails.put(extId.email(), extId.key()); }/*from www . j a v a 2 s . c o m*/ } catch (ConfigInvalidException e) { addError(String.format(e.getMessage()), problems); } } } emails.asMap().entrySet().stream().filter(e -> e.getValue().size() > 1).forEach(e -> addError( String.format("Email '%s' is not unique, it's used by the following external IDs: %s", e.getKey(), e.getValue().stream().map(k -> "'" + k.get() + "'").sorted().collect(joining(", "))), problems)); return problems; }
From source file:com.google.gerrit.server.git.NotesBranchUtil.java
License:Apache License
/** * Create a new commit in the {@code notesBranch} by creating not yet * existing notes from the {@code notes} map. The notes from the * {@code notes} map which already exist in the note-tree of the * tip of the {@code notesBranch} will not be updated. * * @param notes map of notes/*from w w w.j a v a 2 s .c o m*/ * @param notesBranch notes branch to update * @param commitAuthor author of the commit in the notes branch * @param commitMessage for the commit in the notes branch * @return map with those notes from the {@code notes} that were newly * created * @throws IOException * @throws ConcurrentRefUpdateException */ public final NoteMap commitNewNotes(NoteMap notes, String notesBranch, PersonIdent commitAuthor, String commitMessage) throws IOException, ConcurrentRefUpdateException { this.overwrite = false; commitNotes(notes, notesBranch, commitAuthor, commitMessage); NoteMap newlyCreated = NoteMap.newEmptyMap(); for (Note n : notes) { if (base == null || !base.contains(n)) { newlyCreated.set(n, n.getData()); } } return newlyCreated; }
From source file:com.google.gerrit.server.git.NotesBranchUtil.java
License:Apache License
private void addNewNotes(NoteMap notes) throws IOException { for (Note n : notes) { if (!ours.contains(n)) { ours.set(n, n.getData()); }/*from ww w .j av a 2 s .c o m*/ } }
From source file:com.google.gerrit.server.git.NotesBranchUtil.java
License:Apache License
private void addAllNotes(NoteMap notes) throws IOException { for (Note n : notes) { if (ours.contains(n)) { // Merge the existing and the new note as if they are both new, // means: base == null // There is no really a common ancestry for these two note revisions ObjectId noteContent = getNoteMerger().merge(null, n, ours.getNote(n), reader, inserter).getData(); ours.set(n, noteContent);/* ww w .jav a 2s .c o m*/ } else { ours.set(n, n.getData()); } } }
From source file:com.google.gerrit.server.git.ReviewNoteMerger.java
License:Eclipse Distribution License
@Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) { return theirs; }// w w w . ja va2 s . c o m if (theirs == null) { return ours; } if (ours.getData().equals(theirs.getData())) { return ours; } ObjectLoader lo = reader.open(ours.getData()); byte[] sep = new byte[] { '\n' }; ObjectLoader lt = reader.open(theirs.getData()); try (ObjectStream os = lo.openStream(); ByteArrayInputStream b = new ByteArrayInputStream(sep); ObjectStream ts = lt.openStream(); UnionInputStream union = new UnionInputStream(os, b, ts)) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union); return new Note(ours, noteData); } }