List of usage examples for org.eclipse.jgit.notes NoteMap contains
public boolean contains(AnyObjectId id) throws IOException
From source file:com.google.gerrit.server.account.externalids.ExternalIdReader.java
License:Apache License
private static ExternalId parse(ExternalId.Key key, RevWalk rw, ObjectId rev) throws IOException, ConfigInvalidException { NoteMap noteMap = readNoteMap(rw, rev); ObjectId noteId = key.sha1();//from w w w . j a v a 2 s .c o m if (!noteMap.contains(noteId)) { return null; } byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); return ExternalId.parse(noteId.name(), raw); }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** * Inserts a new external ID and sets it in the note map. * * <p>If the external ID already exists, the insert fails with {@link OrmDuplicateKeyException}. *//* w ww . j ava 2s.co m*/ public static void insert(RevWalk rw, ObjectInserter ins, NoteMap noteMap, ExternalId extId) throws OrmDuplicateKeyException, ConfigInvalidException, IOException { if (noteMap.contains(extId.key().sha1())) { throw new OrmDuplicateKeyException(String.format("external id %s already exists", extId.key().get())); } upsert(rw, ins, noteMap, extId); }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** * Insert or updates an new external ID and sets it in the note map. * * <p>If the external ID already exists it is overwritten. *//* www . j a v a2 s . com*/ public static void upsert(RevWalk rw, ObjectInserter ins, NoteMap noteMap, ExternalId extId) throws IOException, ConfigInvalidException { ObjectId noteId = extId.key().sha1(); Config c = new Config(); if (noteMap.contains(extId.key().sha1())) { byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); try { c.fromText(new String(raw, UTF_8)); } catch (ConfigInvalidException e) { throw new ConfigInvalidException( String.format("Invalid external id config for note %s: %s", noteId, e.getMessage())); } } extId.writeToConfig(c); byte[] raw = c.toText().getBytes(UTF_8); ObjectId dataBlob = ins.insert(OBJ_BLOB, raw); noteMap.set(noteId, dataBlob); }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** * Removes an external ID from the note map. * * @throws IllegalStateException is thrown if there is an existing external ID that has the same * key, but otherwise doesn't match the specified external ID. *//*from w ww .java 2 s . c o m*/ public static void remove(RevWalk rw, NoteMap noteMap, ExternalId extId) throws IOException, ConfigInvalidException { ObjectId noteId = extId.key().sha1(); if (!noteMap.contains(noteId)) { return; } byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); ExternalId actualExtId = ExternalId.parse(noteId.name(), raw); checkState(extId.equals(actualExtId), "external id %s should be removed, but it's not matching the actual external id %s", extId.toString(), actualExtId.toString()); noteMap.remove(noteId); }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** * Removes an external ID from the note map by external ID key. * * @throws IllegalStateException is thrown if an expected account ID is provided and an external * ID with the specified key exists, but belongs to another account. *//*from w w w. j a v a 2s.c o m*/ private static void remove(RevWalk rw, NoteMap noteMap, ExternalId.Key extIdKey, Account.Id expectedAccountId) throws IOException, ConfigInvalidException { ObjectId noteId = extIdKey.sha1(); if (!noteMap.contains(noteId)) { return; } byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); ExternalId extId = ExternalId.parse(noteId.name(), raw); if (expectedAccountId != null) { checkState(expectedAccountId.equals(extId.accountId()), "external id %s should be removed for account %s," + " but external id belongs to account %s", extIdKey.get(), expectedAccountId.get(), extId.accountId().get()); } noteMap.remove(noteId); }
From source file:com.google.gerrit.server.git.BanCommit.java
License:Apache License
public BanCommitResult ban(final ProjectControl projectControl, final List<ObjectId> commitsToBan, final String reason) throws PermissionDeniedException, IOException, ConcurrentRefUpdateException { if (!projectControl.isOwner()) { throw new PermissionDeniedException("Not project owner: not permitted to ban commits"); }/* w w w .j av a 2 s .c om*/ final BanCommitResult result = new BanCommitResult(); NoteMap banCommitNotes = NoteMap.newEmptyMap(); // Add a note for each banned commit to notes. final Project.NameKey project = projectControl.getProject().getNameKey(); try (Repository repo = repoManager.openRepository(project); RevWalk revWalk = new RevWalk(repo); ObjectInserter inserter = repo.newObjectInserter()) { ObjectId noteId = null; for (final ObjectId commitToBan : commitsToBan) { try { revWalk.parseCommit(commitToBan); } catch (MissingObjectException e) { // Ignore exception, non-existing commits can be banned. } catch (IncorrectObjectTypeException e) { result.notACommit(commitToBan); continue; } if (noteId == null) { noteId = createNoteContent(reason, inserter); } banCommitNotes.set(commitToBan, noteId); } NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(project, repo, inserter); NoteMap newlyCreated = notesBranchUtil.commitNewNotes(banCommitNotes, REFS_REJECT_COMMITS, createPersonIdent(), buildCommitMessage(commitsToBan, reason)); for (Note n : banCommitNotes) { if (newlyCreated.contains(n)) { result.commitBanned(n); } else { result.commitAlreadyBanned(n); } } return result; } }
From source file:com.google.gerrit.server.notedb.ChangeNotesTest.java
License:Apache License
@Test public void patchLineCommentsDeleteAllDraftsForOneRevision() throws Exception { Change c = newChange();// w ww . j ava 2 s . c o m String uuid = "uuid"; String rev1 = "abcd1234abcd1234abcd1234abcd1234abcd1234"; String rev2 = "abcd4567abcd4567abcd4567abcd4567abcd4567"; ObjectId objId1 = ObjectId.fromString(rev1); ObjectId objId2 = ObjectId.fromString(rev2); CommentRange range = new CommentRange(1, 1, 2, 1); PatchSet.Id ps1 = c.currentPatchSetId(); String filename = "filename1"; short side = (short) 1; ChangeUpdate update = newUpdate(c, otherUser); Timestamp now = TimeUtil.nowTs(); PatchLineComment comment1 = newComment(ps1, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, rev1, Status.DRAFT); update.setPatchSetId(ps1); update.upsertComment(comment1); update.commit(); incrementPatchSet(c); PatchSet.Id ps2 = c.currentPatchSetId(); update = newUpdate(c, otherUser); now = TimeUtil.nowTs(); PatchLineComment comment2 = newComment(ps2, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps2", side, rev2, Status.DRAFT); update.setPatchSetId(ps2); update.upsertComment(comment2); update.commit(); ChangeNotes notes = newNotes(c); assertThat(notes.getDraftComments(otherUserId)).hasSize(2); update = newUpdate(c, otherUser); now = TimeUtil.nowTs(); update.setPatchSetId(ps2); update.deleteComment(comment2); update.commit(); notes = newNotes(c); assertThat(notes.getDraftComments(otherUserId)).hasSize(1); NoteMap noteMap = notes.getDraftCommentNotes().getNoteMap(); assertThat(noteMap.contains(objId1)).isTrue(); assertThat(noteMap.contains(objId2)).isFalse(); }