List of usage examples for org.eclipse.jgit.lib ObjectId fromString
public static ObjectId fromString(String str)
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
/** * Write comments for multiple revisions to a note map. * <p>/*from ww w .j a v a2 s. c o m*/ * Mutates the map in-place. only notes for SHA-1s found as keys in the map * are modified; all other notes are left untouched. * * @param noteMap note map to modify. * @param allComments map of revision to all comments for that revision; * callers are responsible for reading the original comments and applying * any changes. Differs from a multimap in that present-but-empty values * are significant, and indicate the note for that SHA-1 should be * deleted. * @param inserter object inserter for writing notes. * @throws IOException if an error occurred. */ public void writeCommentsToNoteMap(NoteMap noteMap, Map<RevId, List<PatchLineComment>> allComments, ObjectInserter inserter) throws IOException { for (Map.Entry<RevId, List<PatchLineComment>> e : allComments.entrySet()) { List<PatchLineComment> comments = e.getValue(); ObjectId commit = ObjectId.fromString(e.getKey().get()); if (comments.isEmpty()) { noteMap.remove(commit); continue; } Collections.sort(comments, PLC_ORDER); // We allow comments for multiple commits to be written in the same // update, even though the rest of the metadata update is associated with // a single patch set. noteMap.set(commit, inserter.insert(OBJ_BLOB, buildNote(comments))); } }
From source file:com.google.gerrit.server.notedb.NoteDbChangeState.java
License:Apache License
@VisibleForTesting static NoteDbChangeState parse(Change.Id id, String str) { if (str == null) { return null; }/* w w w.j a va2 s.c o m*/ List<String> parts = Splitter.on(',').splitToList(str); checkArgument(!parts.isEmpty(), "invalid state string for change %s: %s", id, str); ObjectId changeMetaId = ObjectId.fromString(parts.get(0)); Map<Account.Id, ObjectId> draftIds = Maps.newHashMapWithExpectedSize(parts.size() - 1); Splitter s = Splitter.on('='); for (int i = 1; i < parts.size(); i++) { String p = parts.get(i); List<String> draftParts = s.splitToList(p); checkArgument(draftParts.size() == 2, "invalid draft state part for change %s: %s", id, p); draftIds.put(Account.Id.parse(draftParts.get(0)), ObjectId.fromString(draftParts.get(1))); } return new NoteDbChangeState(id, changeMetaId, draftIds); }
From source file:com.google.gerrit.server.notedb.NoteDbUpdateManagerTest.java
License:Apache License
@SafeVarargs private static BatchRefUpdate newBatchRefUpdate(Consumer<ReceiveCommand>... resultSetters) { try (Repository repo = new InMemoryRepository(new DfsRepositoryDescription("repo"))) { BatchRefUpdate bru = repo.getRefDatabase().newBatchUpdate(); for (int i = 0; i < resultSetters.length; i++) { ReceiveCommand cmd = new ReceiveCommand(ObjectId.fromString(String.format("%039x1", i)), ObjectId.fromString(String.format("%039x2", i)), "refs/heads/branch" + i); bru.addCommand(cmd);// ww w . jav a 2 s . co m resultSetters[i].accept(cmd); } return bru; } }
From source file:com.google.gerrit.server.notedb.rebuild.PatchSetEvent.java
License:Apache License
private void setRevision(ChangeUpdate update, PatchSet ps) throws IOException { String rev = ps.getRevision().get(); String cert = ps.getPushCertificate(); ObjectId id;/*from ww w .j a v a2s. c o m*/ try { id = ObjectId.fromString(rev); } catch (InvalidObjectIdException e) { update.setRevisionForMissingCommit(rev, cert); return; } try { update.setCommit(rw, id, cert); } catch (MissingObjectException e) { update.setRevisionForMissingCommit(rev, cert); return; } }
From source file:com.google.gerrit.server.notedb.RobotCommentUpdate.java
License:Apache License
private CommitBuilder storeCommentsInNotes(RevWalk rw, ObjectInserter ins, ObjectId curr, CommitBuilder cb) throws ConfigInvalidException, OrmException, IOException { RevisionNoteMap<RobotCommentsRevisionNote> rnm = getRevisionNoteMap(rw, curr); Set<RevId> updatedRevs = Sets.newHashSetWithExpectedSize(rnm.revisionNotes.size()); RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm); for (RobotComment c : put) { cache.get(new RevId(c.revId)).putComment(c); }//from w w w . j a va2s. c o m Map<RevId, RevisionNoteBuilder> builders = cache.getBuilders(); boolean touchedAnyRevs = false; boolean hasComments = false; for (Map.Entry<RevId, RevisionNoteBuilder> e : builders.entrySet()) { updatedRevs.add(e.getKey()); ObjectId id = ObjectId.fromString(e.getKey().get()); byte[] data = e.getValue().build(noteUtil, true); if (!Arrays.equals(data, e.getValue().baseRaw)) { touchedAnyRevs = true; } if (data.length == 0) { rnm.noteMap.remove(id); } else { hasComments = true; ObjectId dataBlob = ins.insert(OBJ_BLOB, data); rnm.noteMap.set(id, dataBlob); } } // If we didn't touch any notes, tell the caller this was a no-op update. We // couldn't have done this in isEmpty() below because we hadn't read the old // data yet. if (!touchedAnyRevs) { return NO_OP_UPDATE; } // If we touched every revision and there are no comments left, tell the // caller to delete the entire ref. boolean touchedAllRevs = updatedRevs.equals(rnm.revisionNotes.keySet()); if (touchedAllRevs && !hasComments) { return null; } cb.setTreeId(rnm.noteMap.writeTree(ins)); return cb; }
From source file:com.google.gerrit.server.patch.PatchListCacheImpl.java
License:Apache License
@Override public PatchList get(Change change, PatchSet patchSet) throws PatchListNotAvailableException { Project.NameKey project = change.getProject(); ObjectId a = null;/*w w w. java2 s . c om*/ if (patchSet.getRevision() == null) { throw new PatchListNotAvailableException("revision is null for " + patchSet.getId()); } ObjectId b = ObjectId.fromString(patchSet.getRevision().get()); Whitespace ws = Whitespace.IGNORE_NONE; return get(new PatchListKey(a, b, ws), project); }
From source file:com.google.gerrit.server.patch.PatchScriptFactory.java
License:Apache License
private ObjectId toObjectId(final ReviewDb db, final PatchSet.Id psId) throws OrmException, NoSuchChangeException, AuthException, NoSuchChangeException, IOException { if (!changeId.equals(psId.getParentKey())) { throw new NoSuchChangeException(changeId); }//ww w . j av a2s . c om if (psId.get() == 0) { return getEditRev(); } PatchSet ps = db.patchSets().get(psId); if (ps == null || ps.getRevision() == null || ps.getRevision().get() == null) { throw new NoSuchChangeException(changeId); } try { return ObjectId.fromString(ps.getRevision().get()); } catch (IllegalArgumentException e) { log.error("Patch set " + psId + " has invalid revision"); throw new NoSuchChangeException(changeId, e); } }
From source file:com.google.gerrit.server.patch.PatchSetInfoFactory.java
License:Apache License
public PatchSetInfo get(Change change, PatchSet patchSet) throws PatchSetInfoNotAvailableException { try (Repository repo = repoManager.openRepository(change.getProject()); RevWalk rw = new RevWalk(repo)) { final RevCommit src = rw.parseCommit(ObjectId.fromString(patchSet.getRevision().get())); PatchSetInfo info = get(src, patchSet.getId()); info.setParents(toParentInfos(src.getParents(), rw)); return info; } catch (IOException e) { throw new PatchSetInfoNotAvailableException(e); }//from w w w. j a v a2 s.c om }
From source file:com.google.gerrit.server.project.BanCommit.java
License:Apache License
@Override public BanResultInfo apply(ProjectResource rsrc, Input input) throws UnprocessableEntityException, AuthException, ResourceConflictException, IOException, InterruptedException { BanResultInfo r = new BanResultInfo(); if (input != null && input.commits != null && !input.commits.isEmpty()) { List<ObjectId> commitsToBan = new ArrayList<>(input.commits.size()); for (String c : input.commits) { try { commitsToBan.add(ObjectId.fromString(c)); } catch (IllegalArgumentException e) { throw new UnprocessableEntityException(e.getMessage()); }//from w w w . j av a 2s . com } try { BanCommitResult result = banCommit.ban(rsrc.getControl(), commitsToBan, input.reason); r.newlyBanned = transformCommits(result.getNewlyBannedCommits()); r.alreadyBanned = transformCommits(result.getAlreadyBannedCommits()); r.ignored = transformCommits(result.getIgnoredObjectIds()); } catch (PermissionDeniedException e) { throw new AuthException(e.getMessage()); } catch (ConcurrentRefUpdateException e) { throw new ResourceConflictException(e.getMessage(), e); } } return r; }
From source file:com.google.gerrit.server.project.CommitsCollection.java
License:Apache License
@Override public CommitResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException { ObjectId objectId;//from w w w . j a v a 2 s. c o m try { objectId = ObjectId.fromString(id.get()); } catch (IllegalArgumentException e) { throw new ResourceNotFoundException(id); } try (Repository repo = repoManager.openRepository(parent.getNameKey()); RevWalk rw = new RevWalk(repo)) { RevCommit commit = rw.parseCommit(objectId); rw.parseBody(commit); if (!parent.getControl().canReadCommit(db.get(), rw, commit)) { throw new ResourceNotFoundException(id); } for (int i = 0; i < commit.getParentCount(); i++) { rw.parseBody(rw.parseCommit(commit.getParent(i))); } return new CommitResource(parent, commit); } catch (MissingObjectException | IncorrectObjectTypeException e) { throw new ResourceNotFoundException(id); } }