use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class MergeUtil method createMergeCommit.
public static RevCommit createMergeCommit(ObjectInserter inserter, Config repoConfig, RevCommit mergeTip, RevCommit originalCommit, String mergeStrategy, PersonIdent committerIndent, String commitMsg, RevWalk rw) throws IOException, MergeIdenticalTreeException, MergeConflictException {
if (!MergeStrategy.THEIRS.getName().equals(mergeStrategy) && rw.isMergedInto(originalCommit, mergeTip)) {
throw new ChangeAlreadyMergedException("'" + originalCommit.getName() + "' has already been merged");
}
Merger m = newMerger(inserter, repoConfig, mergeStrategy);
if (m.merge(false, mergeTip, originalCommit)) {
ObjectId tree = m.getResultTreeId();
CommitBuilder mergeCommit = new CommitBuilder();
mergeCommit.setTreeId(tree);
mergeCommit.setParentIds(mergeTip, originalCommit);
mergeCommit.setAuthor(committerIndent);
mergeCommit.setCommitter(committerIndent);
mergeCommit.setMessage(commitMsg);
return rw.parseCommit(inserter.insert(mergeCommit));
}
List<String> conflicts = ImmutableList.of();
if (m instanceof ResolveMerger) {
conflicts = ((ResolveMerger) m).getUnmergedPaths();
}
throw new MergeConflictException(createConflictMessage(conflicts));
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class GitReferenceUpdated method fire.
private void fire(Project.NameKey project, String ref, ObjectId oldObjectId, ObjectId newObjectId, ReceiveCommand.Type type, AccountInfo updater) {
if (!listeners.iterator().hasNext()) {
return;
}
ObjectId o = oldObjectId != null ? oldObjectId : ObjectId.zeroId();
ObjectId n = newObjectId != null ? newObjectId : ObjectId.zeroId();
Event event = new Event(project, ref, o.name(), n.name(), type, updater);
for (GitReferenceUpdatedListener l : listeners) {
try {
l.onGitReferenceUpdated(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class FixReplacementInterpreter method toTreeModifications.
/**
* Transforms the given {@code FixReplacement}s into {@code TreeModification}s.
*
* @param repository the affected Git repository
* @param projectState the affected project
* @param patchSetCommitId the patch set which should be modified
* @param fixReplacements the replacements which should be applied
* @return a list of {@code TreeModification}s representing the given replacements
* @throws ResourceNotFoundException if a file to which one of the replacements refers doesn't
* exist
* @throws ResourceConflictException if the replacements can't be transformed into {@code
* TreeModification}s
*/
public List<TreeModification> toTreeModifications(Repository repository, ProjectState projectState, ObjectId patchSetCommitId, List<FixReplacement> fixReplacements) throws ResourceNotFoundException, IOException, ResourceConflictException {
checkNotNull(fixReplacements, "Fix replacements must not be null");
Map<String, List<FixReplacement>> fixReplacementsPerFilePath = fixReplacements.stream().collect(Collectors.groupingBy(fixReplacement -> fixReplacement.path));
List<TreeModification> treeModifications = new ArrayList<>();
for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
TreeModification treeModification = toTreeModification(repository, projectState, patchSetCommitId, entry.getKey(), entry.getValue());
treeModifications.add(treeModification);
}
return treeModifications;
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class ChangeEditModifier method merge.
private static ObjectId merge(Repository repository, ChangeEdit changeEdit, ObjectId newTreeId) throws IOException, MergeConflictException {
PatchSet basePatchSet = changeEdit.getBasePatchSet();
ObjectId basePatchSetCommitId = getPatchSetCommitId(basePatchSet);
ObjectId editCommitId = changeEdit.getEditCommit();
ThreeWayMerger threeWayMerger = MergeStrategy.RESOLVE.newMerger(repository, true);
threeWayMerger.setBase(basePatchSetCommitId);
boolean successful = threeWayMerger.merge(newTreeId, editCommitId);
if (!successful) {
throw new MergeConflictException("The existing change edit could not be merged with another tree.");
}
return threeWayMerger.getResultTreeId();
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class ChangeEditModifier method createEdit.
/**
* Creates a new change edit.
*
* @param repository the affected Git repository
* @param changeControl the {@code ChangeControl} of the change for which the change edit should
* be created
* @throws AuthException if the user isn't authenticated or not allowed to use change edits
* @throws InvalidChangeOperationException if a change edit already existed for the change
* @throws PermissionBackendException
*/
public void createEdit(Repository repository, ChangeControl changeControl) throws AuthException, IOException, InvalidChangeOperationException, OrmException, PermissionBackendException {
assertCanEdit(changeControl);
Optional<ChangeEdit> changeEdit = lookupChangeEdit(changeControl);
if (changeEdit.isPresent()) {
throw new InvalidChangeOperationException(String.format("A change edit already exists for change %s", changeControl.getId()));
}
PatchSet currentPatchSet = lookupCurrentPatchSet(changeControl);
ObjectId patchSetCommitId = getPatchSetCommitId(currentPatchSet);
createEdit(repository, changeControl, currentPatchSet, patchSetCommitId, TimeUtil.nowTs());
}
Aggregations