Search in sources :

Example 6 with DiffNotAvailableException

use of com.google.gerrit.server.patch.DiffNotAvailableException in project gerrit by GerritCodeReview.

the class CommentSender method getGroupedInlineComments.

/**
 * Returns a list of FileCommentGroup objects representing the inline comments grouped by the
 * file.
 */
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
    List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
    // Loop over the comments and collect them into groups based on the file
    // location of the comment.
    FileCommentGroup currentGroup = null;
    for (Comment c : inlineComments) {
        // If it's a new group:
        if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
            currentGroup = new FileCommentGroup();
            currentGroup.filename = c.key.filename;
            currentGroup.patchSetId = c.key.patchSetId;
            // Get the modified files:
            Map<String, FileDiffOutput> modifiedFiles = null;
            try {
                modifiedFiles = listModifiedFiles(c.key.patchSetId);
            } catch (DiffNotAvailableException e) {
                logger.atSevere().withCause(e).log("Failed to get modified files");
            }
            groups.add(currentGroup);
            if (modifiedFiles != null && !modifiedFiles.isEmpty()) {
                try {
                    currentGroup.fileData = new PatchFile(repo, modifiedFiles, c.key.filename);
                } catch (IOException e) {
                    logger.atWarning().withCause(e).log("Cannot load %s from %s in %s", c.key.filename, modifiedFiles.values().iterator().next().newCommitId().name(), projectState.getName());
                    currentGroup.fileData = null;
                }
            }
        }
        if (currentGroup.filename.equals(PATCHSET_LEVEL) || currentGroup.fileData != null) {
            currentGroup.comments.add(c);
        }
    }
    groups.sort(Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
    return groups;
}
Also used : Patch(com.google.gerrit.entities.Patch) EmailException(com.google.gerrit.exceptions.EmailException) Protocol(com.google.gerrit.server.mail.receive.Protocol) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) CommentsUtil(com.google.gerrit.server.CommentsUtil) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) HashSet(java.util.HashSet) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) Strings(com.google.common.base.Strings) Config(org.eclipse.jgit.lib.Config) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) Map(java.util.Map) RobotComment(com.google.gerrit.entities.RobotComment) NoSuchEntityException(com.google.gerrit.exceptions.NoSuchEntityException) Change(com.google.gerrit.entities.Change) FieldName(org.apache.james.mime4j.dom.field.FieldName) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) StorageException(com.google.gerrit.exceptions.StorageException) Account(com.google.gerrit.entities.Account) MailHeader(com.google.gerrit.mail.MailHeader) IOException(java.io.IOException) ZoneId(java.time.ZoneId) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) FilenameComparator(com.google.gerrit.common.data.FilenameComparator) List(java.util.List) NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) Project(com.google.gerrit.entities.Project) MailProcessingUtil(com.google.gerrit.mail.MailProcessingUtil) LabelVote(com.google.gerrit.server.util.LabelVote) Optional(java.util.Optional) PatchFile(com.google.gerrit.server.patch.PatchFile) Comparator(java.util.Comparator) Collections(java.util.Collections) FluentLogger(com.google.common.flogger.FluentLogger) Repository(org.eclipse.jgit.lib.Repository) Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) RobotComment(com.google.gerrit.entities.RobotComment) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) PatchFile(com.google.gerrit.server.patch.PatchFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput)

Example 7 with DiffNotAvailableException

use of com.google.gerrit.server.patch.DiffNotAvailableException in project gerrit by GerritCodeReview.

the class EventFactory method addPatchSetFileNames.

public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute, Change change, PatchSet patchSet) {
    try {
        Map<String, FileDiffOutput> modifiedFiles = diffOperations.listModifiedFilesAgainstParent(change.getProject(), patchSet.commitId(), /* parentNum= */
        0, DiffOptions.DEFAULTS);
        for (FileDiffOutput diff : modifiedFiles.values()) {
            if (patchSetAttribute.files == null) {
                patchSetAttribute.files = new ArrayList<>();
            }
            PatchAttribute p = new PatchAttribute();
            p.file = FilePathAdapter.getNewPath(diff.oldPath(), diff.newPath(), diff.changeType());
            p.fileOld = FilePathAdapter.getOldPath(diff.oldPath(), diff.changeType());
            p.type = diff.changeType();
            p.deletions -= diff.deletions();
            p.insertions = diff.insertions();
            patchSetAttribute.files.add(p);
        }
    } catch (DiffNotAvailableException e) {
        logger.atSevere().withCause(e).log("Cannot get patch list");
    }
}
Also used : PatchAttribute(com.google.gerrit.server.data.PatchAttribute) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput)

Example 8 with DiffNotAvailableException

use of com.google.gerrit.server.patch.DiffNotAvailableException in project gerrit by GerritCodeReview.

the class ListOfFilesUnchangedPredicate method match.

@Override
public boolean match(ApprovalContext ctx) {
    PatchSet targetPatchSet = ctx.target();
    PatchSet sourcePatchSet = ctx.changeNotes().getPatchSets().get(ctx.patchSetApproval().patchSetId());
    Integer parentNum = isInitialCommit(ctx.changeNotes().getProjectName(), targetPatchSet.commitId()) ? 0 : 1;
    try {
        Map<String, ModifiedFile> baseVsCurrent = diffOperations.loadModifiedFilesAgainstParent(ctx.changeNotes().getProjectName(), targetPatchSet.commitId(), parentNum, DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
        Map<String, ModifiedFile> baseVsPrior = diffOperations.loadModifiedFilesAgainstParent(ctx.changeNotes().getProjectName(), sourcePatchSet.commitId(), parentNum, DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
        Map<String, ModifiedFile> priorVsCurrent = diffOperations.loadModifiedFiles(ctx.changeNotes().getProjectName(), sourcePatchSet.commitId(), targetPatchSet.commitId(), DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
        return match(baseVsCurrent, baseVsPrior, priorVsCurrent);
    } catch (DiffNotAvailableException ex) {
        throw new StorageException("failed to compute difference in files, so won't copy" + " votes on labels even if list of files is the same and " + "copyAllIfListOfFilesDidNotChange", ex);
    }
}
Also used : DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) ModifiedFile(com.google.gerrit.server.patch.gitdiff.ModifiedFile) PatchSet(com.google.gerrit.entities.PatchSet) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

DiffNotAvailableException (com.google.gerrit.server.patch.DiffNotAvailableException)8 IOException (java.io.IOException)6 FileDiffOutput (com.google.gerrit.server.patch.filediff.FileDiffOutput)5 StorageException (com.google.gerrit.exceptions.StorageException)3 FluentLogger (com.google.common.flogger.FluentLogger)2 PatchSet (com.google.gerrit.entities.PatchSet)2 Inject (com.google.inject.Inject)2 Assisted (com.google.inject.assistedinject.Assisted)2 HashMap (java.util.HashMap)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FilenameComparator (com.google.gerrit.common.data.FilenameComparator)1 Account (com.google.gerrit.entities.Account)1 Change (com.google.gerrit.entities.Change)1 Comment (com.google.gerrit.entities.Comment)1 HumanComment (com.google.gerrit.entities.HumanComment)1 NotifyType (com.google.gerrit.entities.NotifyConfig.NotifyType)1