use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class DraftCommentNotes method onLoad.
@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
ObjectId rev = handle.id();
if (rev == null) {
loadDefaults();
return;
}
logger.atFine().log("Load draft comment notes for change %s of project %s", getChangeId(), getProjectName());
RevCommit tipCommit = handle.walk().parseCommit(rev);
ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap = RevisionNoteMap.parse(args.changeNoteJson, reader, NoteMap.read(reader, tipCommit), HumanComment.Status.DRAFT);
ImmutableListMultimap.Builder<ObjectId, HumanComment> cs = ImmutableListMultimap.builder();
for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (HumanComment c : rn.getEntities()) {
cs.put(c.getCommitId(), c);
}
}
comments = cs.build();
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class RobotCommentNotes method onLoad.
@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
metaId = handle.id();
if (metaId == null) {
loadDefaults();
return;
}
metaId = metaId.copy();
logger.atFine().log("Load robot comment notes for change %s of project %s", getChangeId(), getProjectName());
RevCommit tipCommit = handle.walk().parseCommit(metaId);
ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap = RevisionNoteMap.parseRobotComments(args.changeNoteJson, reader, NoteMap.read(reader, tipCommit));
ImmutableListMultimap.Builder<ObjectId, RobotComment> cs = ImmutableListMultimap.builder();
for (RobotCommentsRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (RobotComment c : rn.getEntities()) {
cs.put(c.getCommitId(), c);
}
}
comments = cs.build();
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class AutoMerger method createAutoMergeCommit.
/**
* Creates an auto-merge commit of the parents of the given merge commit.
*
* @return auto-merge commit. Headers of the returned RevCommit are parsed.
*/
private ObjectId createAutoMergeCommit(Config repoConfig, RevWalk rw, ObjectInserter ins, RevCommit merge, ThreeWayMergeStrategy mergeStrategy) throws IOException {
rw.parseHeaders(merge);
ResolveMerger m = (ResolveMerger) mergeStrategy.newMerger(ins, repoConfig);
DirCache dc = DirCache.newInCore();
m.setDirCache(dc);
// If we don't plan on saving results, use a fully in-memory inserter.
// Using just a non-flushing wrapper is not sufficient, since in particular DfsInserter might
// try to write to storage after exceeding an internal buffer size.
m.setObjectInserter(ins instanceof InMemoryInserter ? new NonFlushingWrapper(ins) : ins);
boolean couldMerge = m.merge(merge.getParents());
ObjectId treeId;
if (couldMerge) {
treeId = m.getResultTreeId();
} else {
treeId = MergeUtil.mergeWithConflicts(rw, ins, dc, "HEAD", merge.getParent(0), "BRANCH", merge.getParent(1), m.getMergeResults());
}
rw.parseHeaders(merge);
// For maximum stability, choose a single ident using the committer time of
// the input commit, using the server name and timezone.
PersonIdent ident = new PersonIdent(gerritIdentProvider.get(), merge.getCommitterIdent().getWhen(), gerritIdentProvider.get().getTimeZone());
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
cb.setTreeId(treeId);
cb.setMessage(AUTO_MERGE_MSG_PREFIX + merge.name() + '\n');
for (RevCommit p : merge.getParents()) {
cb.addParentId(p);
}
if (ins instanceof InMemoryInserter) {
// they are not available.
try (ObjectReader tmpReader = ins.newReader();
RevWalk tmpRw = new RevWalk(tmpReader)) {
return tmpRw.parseCommit(ins.insert(cb));
}
}
return rw.parseCommit(ins.insert(cb));
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class ExternalIdCacheLoader method buildAllExternalIds.
/**
* Build a new {@link AllExternalIds} from an old state by applying additions and removals that
* were performed since then.
*
* <p>Removals are applied before additions.
*
* @param repo open repository
* @param oldExternalIds prior state that is used as base
* @param additions map of name to blob ID for each external ID that should be added
* @param removals set of name {@link ObjectId}s that should be removed
*/
private AllExternalIds buildAllExternalIds(Repository repo, AllExternalIds oldExternalIds, Map<ObjectId, ObjectId> additions, Set<ObjectId> removals) throws IOException {
ImmutableMap.Builder<ExternalId.Key, ExternalId> byKey = ImmutableMap.builder();
ImmutableSetMultimap.Builder<Account.Id, ExternalId> byAccount = ImmutableSetMultimap.builder();
ImmutableSetMultimap.Builder<String, ExternalId> byEmail = ImmutableSetMultimap.builder();
// Copy over old ExternalIds but exclude deleted ones
for (ExternalId externalId : oldExternalIds.byAccount().values()) {
if (removals.contains(externalId.blobId())) {
continue;
}
byKey.put(externalId.key(), externalId);
byAccount.put(externalId.accountId(), externalId);
if (externalId.email() != null) {
byEmail.put(externalId.email(), externalId);
}
}
// Add newly discovered ExternalIds
try (ObjectReader reader = repo.newObjectReader()) {
for (Map.Entry<ObjectId, ObjectId> nameToBlob : additions.entrySet()) {
ExternalId parsedExternalId;
try {
parsedExternalId = externalIdFactory.parse(nameToBlob.getKey().name(), reader.open(nameToBlob.getValue()).getCachedBytes(), nameToBlob.getValue());
} catch (ConfigInvalidException | RuntimeException e) {
logger.atSevere().withCause(e).log("Ignoring invalid external ID note %s", nameToBlob.getKey().name());
continue;
}
byKey.put(parsedExternalId.key(), parsedExternalId);
byAccount.put(parsedExternalId.accountId(), parsedExternalId);
if (parsedExternalId.email() != null) {
byEmail.put(parsedExternalId.email(), parsedExternalId);
}
}
}
return new AutoValue_AllExternalIds(byKey.build(), byAccount.build(), byEmail.build());
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class CommitUtil method createRevertChange.
/**
* Allows creating a revert change.
*
* @param notes ChangeNotes of the change being reverted.
* @param user Current User performing the revert.
* @param input the RevertInput entity for conducting the revert.
* @param timestamp timestamp for the created change.
* @return ObjectId that represents the newly created commit.
*/
public Change.Id createRevertChange(ChangeNotes notes, CurrentUser user, RevertInput input, Instant timestamp) throws RestApiException, UpdateException, ConfigInvalidException, IOException {
String message = Strings.emptyToNull(input.message);
try (Repository git = repoManager.openRepository(notes.getProjectName());
ObjectInserter oi = git.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk revWalk = new RevWalk(reader)) {
ObjectId generatedChangeId = CommitMessageUtil.generateChangeId();
ObjectId revCommit = createRevertCommit(message, notes, user, timestamp, oi, revWalk, generatedChangeId);
return createRevertChangeFromCommit(revCommit, input, notes, user, generatedChangeId, timestamp, oi, revWalk, git);
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(notes.getChangeId().toString(), e);
}
}
Aggregations