Search in sources :

Example 1 with ChangeType

use of com.google.gerrit.entities.Patch.ChangeType in project gerrit by GerritCodeReview.

the class DiffOperationsImpl method loadModifiedFilesWithoutCache.

/**
 * Loads the modified file paths between two commits without inspecting the diff cache.
 */
private static Map<String, ModifiedFile> loadModifiedFilesWithoutCache(Project.NameKey project, DiffParameters diffParams, RevWalk revWalk, Config repoConfig) throws DiffNotAvailableException {
    ObjectId newCommit = diffParams.newCommit();
    ObjectId oldCommit = diffParams.baseCommit();
    try {
        ObjectReader reader = revWalk.getObjectReader();
        List<DiffEntry> diffEntries;
        try (DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
            df.setReader(reader, repoConfig);
            df.setDetectRenames(false);
            diffEntries = df.scan(oldCommit.equals(ObjectId.zeroId()) ? null : oldCommit, newCommit);
        }
        List<ModifiedFile> modifiedFiles = diffEntries.stream().map(entry -> ModifiedFile.builder().changeType(toChangeType(entry.getChangeType())).oldPath(getGitPath(entry.getOldPath())).newPath(getGitPath(entry.getNewPath())).build()).collect(Collectors.toList());
        return DiffUtil.mergeRewrittenModifiedFiles(modifiedFiles).stream().collect(ImmutableMap.toImmutableMap(ModifiedFile::getDefaultPath, Function.identity()));
    } catch (IOException e) {
        throw new DiffNotAvailableException(String.format("Failed to compute the modified files for project '%s'," + " old commit '%s', new commit '%s'.", project, oldCommit.name(), newCommit.name()), e);
    }
}
Also used : Patch(com.google.gerrit.entities.Patch) Module(com.google.inject.Module) ModifiedFilesCache(com.google.gerrit.server.patch.diff.ModifiedFilesCache) Whitespace(com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace) DiffAlgorithm(com.google.gerrit.server.patch.gitfilediff.GitFileDiffCacheImpl.DiffAlgorithm) Inject(com.google.inject.Inject) FileDiffCache(com.google.gerrit.server.patch.filediff.FileDiffCache) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) ImmutableCollection(com.google.common.collect.ImmutableCollection) Function(java.util.function.Function) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) ChangeType(com.google.gerrit.entities.Patch.ChangeType) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) Map(java.util.Map) ModifiedFilesCacheKey(com.google.gerrit.server.patch.diff.ModifiedFilesCacheKey) GitModifiedFilesCacheImpl(com.google.gerrit.server.patch.gitdiff.GitModifiedFilesCacheImpl) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) ImmutableMap(com.google.common.collect.ImmutableMap) ModifiedFile(com.google.gerrit.server.patch.gitdiff.ModifiedFile) DisabledOutputStream(org.eclipse.jgit.util.io.DisabledOutputStream) FileDiffCacheKey(com.google.gerrit.server.patch.filediff.FileDiffCacheKey) FileDiffCacheImpl(com.google.gerrit.server.patch.filediff.FileDiffCacheImpl) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) CacheModule(com.google.gerrit.server.cache.CacheModule) GitFileDiffCacheImpl(com.google.gerrit.server.patch.gitfilediff.GitFileDiffCacheImpl) ObjectId(org.eclipse.jgit.lib.ObjectId) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) AutoValue(com.google.auto.value.AutoValue) Project(com.google.gerrit.entities.Project) Optional(java.util.Optional) DiffEntry(org.eclipse.jgit.diff.DiffEntry) ModifiedFilesCacheImpl(com.google.gerrit.server.patch.diff.ModifiedFilesCacheImpl) ObjectReader(org.eclipse.jgit.lib.ObjectReader) FluentLogger(com.google.common.flogger.FluentLogger) Singleton(com.google.inject.Singleton) ObjectId(org.eclipse.jgit.lib.ObjectId) ModifiedFile(com.google.gerrit.server.patch.gitdiff.ModifiedFile) ObjectReader(org.eclipse.jgit.lib.ObjectReader) IOException(java.io.IOException) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 2 with ChangeType

use of com.google.gerrit.entities.Patch.ChangeType in project gerrit by GerritCodeReview.

the class PatchListEntry method readFrom.

static PatchListEntry readFrom(InputStream in) throws IOException {
    ChangeType changeType = readEnum(in, ChangeType.values());
    PatchType patchType = readEnum(in, PatchType.values());
    String oldName = readString(in);
    String newName = readString(in);
    byte[] hdr = readBytes(in);
    int ins = readVarInt32(in);
    int del = readVarInt32(in);
    long size = readFixInt64(in);
    long sizeDelta = readFixInt64(in);
    Edit[] editArray = readEditArray(in);
    Edit[] editsDueToRebase = readEditArray(in);
    return new PatchListEntry(changeType, patchType, oldName, newName, hdr, ImmutableList.copyOf(editArray), ImmutableSet.copyOf(editsDueToRebase), ins, del, size, sizeDelta);
}
Also used : ChangeType(com.google.gerrit.entities.Patch.ChangeType) PatchType(com.google.gerrit.entities.Patch.PatchType) Edit(org.eclipse.jgit.diff.Edit) BasicSerialization.writeString(com.google.gerrit.server.ioutil.BasicSerialization.writeString) BasicSerialization.readString(com.google.gerrit.server.ioutil.BasicSerialization.readString)

Aggregations

ChangeType (com.google.gerrit.entities.Patch.ChangeType)2 AutoValue (com.google.auto.value.AutoValue)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FluentLogger (com.google.common.flogger.FluentLogger)1 Nullable (com.google.gerrit.common.Nullable)1 Patch (com.google.gerrit.entities.Patch)1 COMMIT_MSG (com.google.gerrit.entities.Patch.COMMIT_MSG)1 MERGE_LIST (com.google.gerrit.entities.Patch.MERGE_LIST)1 PatchType (com.google.gerrit.entities.Patch.PatchType)1 Project (com.google.gerrit.entities.Project)1 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)1 Whitespace (com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace)1 CacheModule (com.google.gerrit.server.cache.CacheModule)1 BasicSerialization.readString (com.google.gerrit.server.ioutil.BasicSerialization.readString)1 BasicSerialization.writeString (com.google.gerrit.server.ioutil.BasicSerialization.writeString)1 ModifiedFilesCache (com.google.gerrit.server.patch.diff.ModifiedFilesCache)1 ModifiedFilesCacheImpl (com.google.gerrit.server.patch.diff.ModifiedFilesCacheImpl)1 ModifiedFilesCacheKey (com.google.gerrit.server.patch.diff.ModifiedFilesCacheKey)1