Reduce log levels

This commit is contained in:
Rene Pfeuffer
2019-10-09 11:27:54 +02:00
parent a81049eea3
commit 369ad9e788
3 changed files with 16 additions and 18 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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);
}
}