List of usage examples for org.eclipse.jgit.notes NoteMap writeTree
public ObjectId writeTree(ObjectInserter inserter) throws IOException
From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java
License:Open Source License
/** * Creates a merged notes commit.//from w w w. ja v a2 s . c o m */ private RevCommit createNotesCommit(NoteMap map, ObjectInserter inserter, RevWalk revWalk, String message, RevCommit... parents) throws IOException { CommitBuilder commitBuilder = new CommitBuilder(); commitBuilder.setTreeId(map.writeTree(inserter)); commitBuilder.setAuthor(author); commitBuilder.setCommitter(author); if (parents.length > 0) { commitBuilder.setParentIds(parents); } commitBuilder.setMessage(message); ObjectId commitId = inserter.insert(commitBuilder); inserter.flush(); return revWalk.parseCommit(commitId); }
From source file:com.google.appraise.eclipse.core.client.git.GitNoteWriter.java
License:Open Source License
private RevCommit createCommit(NoteMap map, PersonIdent author, String message, RevCommit... parents) throws IOException { CommitBuilder b = new CommitBuilder(); b.setTreeId(map.writeTree(inserter)); b.setAuthor(author);/*from w ww .ja v a 2s . c om*/ b.setCommitter(author); if (parents.length > 0) { b.setParentIds(parents); } b.setMessage(message); ObjectId commitId = inserter.insert(b); inserter.flush(); return revWalk.parseCommit(commitId); }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** Commits updates to the external IDs. */ public static ObjectId commit(Repository repo, RevWalk rw, ObjectInserter ins, ObjectId rev, NoteMap noteMap, String commitMessage, PersonIdent committerIdent, PersonIdent authorIdent) throws IOException { CommitBuilder cb = new CommitBuilder(); cb.setMessage(commitMessage);/* w w w . j a va2 s . c o m*/ cb.setTreeId(noteMap.writeTree(ins)); cb.setAuthor(authorIdent); cb.setCommitter(committerIdent); if (!rev.equals(ObjectId.zeroId())) { cb.setParentId(rev); } else { cb.setParentIds(); // Ref is currently nonexistent, commit has no parents. } if (cb.getTreeId() == null) { if (rev.equals(ObjectId.zeroId())) { cb.setTreeId(emptyTree(ins)); // No parent, assume empty tree. } else { RevCommit p = rw.parseCommit(rev); cb.setTreeId(p.getTree()); // Copy tree from parent. } } ObjectId commitId = ins.insert(cb); ins.flush(); RefUpdate u = repo.updateRef(RefNames.REFS_EXTERNAL_IDS); u.setRefLogIdent(committerIdent); u.setRefLogMessage("Update external IDs", false); u.setExpectedOldObjectId(rev); u.setNewObjectId(commitId); RefUpdate.Result res = u.update(); switch (res) { case NEW: case FAST_FORWARD: case NO_CHANGE: case RENAMED: case FORCED: break; case LOCK_FAILURE: throw new LockFailureException("Updating external IDs failed with " + res); case IO_FAILURE: case NOT_ATTEMPTED: case REJECTED: case REJECTED_CURRENT_BRANCH: default: throw new IOException("Updating external IDs failed with " + res); } return rw.parseCommit(commitId); }
From source file:com.google.gerrit.server.git.CreateCodeReviewNotes.java
License:Apache License
private RevCommit createCommit(NoteMap map, PersonIdent author, String message, RevCommit... parents) throws IOException { CommitBuilder b = new CommitBuilder(); b.setTreeId(map.writeTree(inserter)); b.setAuthor(author != null ? author : gerritIdent); b.setCommitter(gerritIdent);/*w w w .j av a 2 s.c o m*/ if (parents.length > 0) { b.setParentIds(parents); } b.setMessage(message); ObjectId commitId = inserter.insert(b); inserter.flush(); return revWalk.parseCommit(commitId); }
From source file:com.google.gerrit.server.notedb.ChangeDraftUpdate.java
License:Apache License
/** @return the tree id for the updated tree */ private ObjectId storeCommentsInNotes(AtomicBoolean removedAllComments) throws OrmException, IOException { if (isEmpty()) { return null; }/* ww w . j ava 2 s . co m*/ NoteMap noteMap = draftNotes.load().getNoteMap(); if (noteMap == null) { noteMap = NoteMap.newEmptyMap(); } Map<RevId, List<PatchLineComment>> allComments = new HashMap<>(); boolean hasComments = false; int n = deleteComments.size() + upsertComments.size(); Set<RevId> updatedRevs = Sets.newHashSetWithExpectedSize(n); Set<PatchLineComment.Key> updatedKeys = Sets.newHashSetWithExpectedSize(n); for (PatchLineComment c : deleteComments) { allComments.put(c.getRevId(), new ArrayList<PatchLineComment>()); updatedRevs.add(c.getRevId()); updatedKeys.add(c.getKey()); } for (PatchLineComment c : upsertComments) { hasComments = true; addCommentToMap(allComments, c); updatedRevs.add(c.getRevId()); updatedKeys.add(c.getKey()); } // Re-add old comments for updated revisions so the new note contents // includes both old and new comments merged in the right order. // // writeCommentsToNoteMap doesn't touch notes for SHA-1s that are not // mentioned in the input map, so by omitting comments for those revisions, // we avoid the work of having to re-serialize identical comment data for // those revisions. ListMultimap<RevId, PatchLineComment> existing = draftNotes.getComments(); for (Map.Entry<RevId, PatchLineComment> e : existing.entries()) { PatchLineComment c = e.getValue(); if (updatedRevs.contains(c.getRevId()) && !updatedKeys.contains(c.getKey())) { hasComments = true; addCommentToMap(allComments, e.getValue()); } } // If we touched every revision and there are no comments left, set the flag // for the caller to delete the entire ref. boolean touchedAllRevs = updatedRevs.equals(existing.keySet()); if (touchedAllRevs && !hasComments) { removedAllComments.set(touchedAllRevs && !hasComments); return null; } commentsUtil.writeCommentsToNoteMap(noteMap, allComments, inserter); return noteMap.writeTree(inserter); }
From source file:com.google.gerrit.server.notedb.ChangeUpdate.java
License:Apache License
/** @return the tree id for the updated tree */ private ObjectId storeCommentsInNotes() throws OrmException, IOException { ChangeNotes notes = ctl.getNotes().load(); NoteMap noteMap = notes.getNoteMap(); if (noteMap == null) { noteMap = NoteMap.newEmptyMap(); }/*from w ww . jav a 2s. com*/ if (comments.isEmpty()) { return null; } Map<RevId, List<PatchLineComment>> allComments = Maps.newHashMap(); for (Map.Entry<RevId, Collection<PatchLineComment>> e : notes.getComments().asMap().entrySet()) { List<PatchLineComment> comments = new ArrayList<>(); for (PatchLineComment c : e.getValue()) { comments.add(c); } allComments.put(e.getKey(), comments); } for (PatchLineComment c : comments) { addCommentToMap(allComments, c); } commentsUtil.writeCommentsToNoteMap(noteMap, allComments, inserter); return noteMap.writeTree(inserter); }