From 369ad9e788483a426b7c480fb43f674643d3c7cc Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Wed, 9 Oct 2019 11:27:54 +0200 Subject: [PATCH] Reduce log levels --- .../scm/repository/spi/GitModifyCommand.java | 4 ++-- .../spi/LfsBlobStoreCleanFilter.java | 21 ++++++++----------- .../spi/LfsBlobStoreCleanFilterFactory.java | 9 ++++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java index 72238e117e..f87dc038c0 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java @@ -112,14 +112,14 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman LfsBlobStoreCleanFilterFactory cleanFilterFactory = new LfsBlobStoreCleanFilterFactory(lfsBlobStoreFactory, repository, targetFile); String registerKey = "git-lfs clean -- '" + path + "'"; - LOG.info("register lfs filter command factory for command '{}'", registerKey); + LOG.debug("register lfs filter command factory for command '{}'", registerKey); FilterCommandRegistry.register(registerKey, cleanFilterFactory::createFilter); try { addFileToGit(path); } catch (GitAPIException e) { throwInternalRepositoryException("could not add file to index", e); } finally { - LOG.info("unregister lfs filter command factory for command \"{}\"", registerKey); + LOG.debug("unregister lfs filter command factory for command \"{}\"", registerKey); FilterCommandRegistry.unregister(registerKey); } } finally { diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilter.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilter.java index 3ab8a3e8cf..7c9c3d3225 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilter.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilter.java @@ -2,11 +2,9 @@ package sonia.scm.repository.spi; import com.google.common.io.ByteStreams; import org.eclipse.jgit.attributes.FilterCommand; -import org.eclipse.jgit.lfs.Lfs; import org.eclipse.jgit.lfs.LfsPointer; import org.eclipse.jgit.lfs.lib.AnyLongObjectId; import org.eclipse.jgit.lfs.lib.LongObjectId; -import org.eclipse.jgit.lib.Repository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sonia.scm.store.Blob; @@ -28,26 +26,24 @@ import static org.eclipse.jgit.lfs.lib.Constants.LONG_HASH_FUNCTION; * Adapted version of JGit's {@link org.eclipse.jgit.lfs.CleanFilter} to write the * lfs file directly to the lfs blob store. */ -public class LfsBlobStoreCleanFilter extends FilterCommand { +class LfsBlobStoreCleanFilter extends FilterCommand { private static final Logger LOG = LoggerFactory.getLogger(LfsBlobStoreCleanFilter.class); - private Lfs lfsUtil; private final BlobStore lfsBlobStore; private final Path targetFile; - public LfsBlobStoreCleanFilter(Repository db, InputStream in, OutputStream out, BlobStore lfsBlobStore, Path targetFile) - throws IOException { + LfsBlobStoreCleanFilter(InputStream in, OutputStream out, BlobStore lfsBlobStore, Path targetFile) { super(in, out); - lfsUtil = new Lfs(db); this.lfsBlobStore = lfsBlobStore; this.targetFile = targetFile; - Files.createDirectories(lfsUtil.getLfsTmpDir()); } @Override + // Suppress warning for RuntimeException after check for wrong size, because mathematicians say this will never happen + @SuppressWarnings("squid:S00112") public int run() throws IOException { - LOG.info("running scm lfs filter for file {}", targetFile); + LOG.debug("running scm lfs filter for file {}", targetFile); DigestOutputStream digestOutputStream = createDigestStream(); try { long size = ByteStreams.copy(in, digestOutputStream); @@ -56,14 +52,13 @@ public class LfsBlobStoreCleanFilter extends FilterCommand { Blob existingBlob = lfsBlobStore.get(hash); if (existingBlob != null) { - LOG.info("found existing lfs blob for oid {}", hash); + LOG.debug("found existing lfs blob for oid {}", hash); long blobSize = existingBlob.getSize(); if (blobSize != size) { - // Mathematicians say this will never happen throw new RuntimeException("lfs entry already exists for loid " + hash + " but has wrong size"); } } else { - LOG.info("uploading new lfs blob for oid {}", hash); + LOG.debug("uploading new lfs blob for oid {}", hash); Blob newBlob = lfsBlobStore.create(hash); OutputStream outputStream = newBlob.getOutputStream(); Files.copy(targetFile, outputStream); @@ -80,6 +75,8 @@ public class LfsBlobStoreCleanFilter extends FilterCommand { } } + // Suppress warning for RuntimeException after check for wrong size, because hash alg for sha256 is built in + @SuppressWarnings("squid:S00112") private DigestOutputStream createDigestStream() { MessageDigest md ; try { diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilterFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilterFactory.java index 6951ec1b14..d6de8e83df 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilterFactory.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/LfsBlobStoreCleanFilterFactory.java @@ -8,19 +8,20 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Path; -public class LfsBlobStoreCleanFilterFactory { +class LfsBlobStoreCleanFilterFactory { private final LfsBlobStoreFactory blobStoreFactory; private final sonia.scm.repository.Repository repository; private final Path targetFile; - public LfsBlobStoreCleanFilterFactory(LfsBlobStoreFactory blobStoreFactory, sonia.scm.repository.Repository repository, Path targetFile) { + LfsBlobStoreCleanFilterFactory(LfsBlobStoreFactory blobStoreFactory, sonia.scm.repository.Repository repository, Path targetFile) { this.blobStoreFactory = blobStoreFactory; this.repository = repository; this.targetFile = targetFile; } - LfsBlobStoreCleanFilter createFilter(Repository db, InputStream in, OutputStream out) throws IOException { - return new LfsBlobStoreCleanFilter(db, in, out, blobStoreFactory.getLfsBlobStore(repository), targetFile); + @SuppressWarnings("squid:S1172") // suppress unused parameter to keep the api compatible to jgit's FilterCommandFactory + LfsBlobStoreCleanFilter createFilter(Repository db, InputStream in, OutputStream out) { + return new LfsBlobStoreCleanFilter(in, out, blobStoreFactory.getLfsBlobStore(repository), targetFile); } }