mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-21 15:59:48 +01:00
Reduce log levels
This commit is contained in:
@@ -112,14 +112,14 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
|||||||
LfsBlobStoreCleanFilterFactory cleanFilterFactory = new LfsBlobStoreCleanFilterFactory(lfsBlobStoreFactory, repository, targetFile);
|
LfsBlobStoreCleanFilterFactory cleanFilterFactory = new LfsBlobStoreCleanFilterFactory(lfsBlobStoreFactory, repository, targetFile);
|
||||||
|
|
||||||
String registerKey = "git-lfs clean -- '" + path + "'";
|
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);
|
FilterCommandRegistry.register(registerKey, cleanFilterFactory::createFilter);
|
||||||
try {
|
try {
|
||||||
addFileToGit(path);
|
addFileToGit(path);
|
||||||
} catch (GitAPIException e) {
|
} catch (GitAPIException e) {
|
||||||
throwInternalRepositoryException("could not add file to index", e);
|
throwInternalRepositoryException("could not add file to index", e);
|
||||||
} finally {
|
} finally {
|
||||||
LOG.info("unregister lfs filter command factory for command \"{}\"", registerKey);
|
LOG.debug("unregister lfs filter command factory for command \"{}\"", registerKey);
|
||||||
FilterCommandRegistry.unregister(registerKey);
|
FilterCommandRegistry.unregister(registerKey);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import org.eclipse.jgit.attributes.FilterCommand;
|
import org.eclipse.jgit.attributes.FilterCommand;
|
||||||
import org.eclipse.jgit.lfs.Lfs;
|
|
||||||
import org.eclipse.jgit.lfs.LfsPointer;
|
import org.eclipse.jgit.lfs.LfsPointer;
|
||||||
import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
|
import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
|
||||||
import org.eclipse.jgit.lfs.lib.LongObjectId;
|
import org.eclipse.jgit.lfs.lib.LongObjectId;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.store.Blob;
|
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
|
* Adapted version of JGit's {@link org.eclipse.jgit.lfs.CleanFilter} to write the
|
||||||
* lfs file directly to the lfs blob store.
|
* 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 static final Logger LOG = LoggerFactory.getLogger(LfsBlobStoreCleanFilter.class);
|
||||||
|
|
||||||
private Lfs lfsUtil;
|
|
||||||
private final BlobStore lfsBlobStore;
|
private final BlobStore lfsBlobStore;
|
||||||
private final Path targetFile;
|
private final Path targetFile;
|
||||||
|
|
||||||
public LfsBlobStoreCleanFilter(Repository db, InputStream in, OutputStream out, BlobStore lfsBlobStore, Path targetFile)
|
LfsBlobStoreCleanFilter(InputStream in, OutputStream out, BlobStore lfsBlobStore, Path targetFile) {
|
||||||
throws IOException {
|
|
||||||
super(in, out);
|
super(in, out);
|
||||||
lfsUtil = new Lfs(db);
|
|
||||||
this.lfsBlobStore = lfsBlobStore;
|
this.lfsBlobStore = lfsBlobStore;
|
||||||
this.targetFile = targetFile;
|
this.targetFile = targetFile;
|
||||||
Files.createDirectories(lfsUtil.getLfsTmpDir());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
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();
|
DigestOutputStream digestOutputStream = createDigestStream();
|
||||||
try {
|
try {
|
||||||
long size = ByteStreams.copy(in, digestOutputStream);
|
long size = ByteStreams.copy(in, digestOutputStream);
|
||||||
@@ -56,14 +52,13 @@ public class LfsBlobStoreCleanFilter extends FilterCommand {
|
|||||||
|
|
||||||
Blob existingBlob = lfsBlobStore.get(hash);
|
Blob existingBlob = lfsBlobStore.get(hash);
|
||||||
if (existingBlob != null) {
|
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();
|
long blobSize = existingBlob.getSize();
|
||||||
if (blobSize != size) {
|
if (blobSize != size) {
|
||||||
// Mathematicians say this will never happen
|
|
||||||
throw new RuntimeException("lfs entry already exists for loid " + hash + " but has wrong size");
|
throw new RuntimeException("lfs entry already exists for loid " + hash + " but has wrong size");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.info("uploading new lfs blob for oid {}", hash);
|
LOG.debug("uploading new lfs blob for oid {}", hash);
|
||||||
Blob newBlob = lfsBlobStore.create(hash);
|
Blob newBlob = lfsBlobStore.create(hash);
|
||||||
OutputStream outputStream = newBlob.getOutputStream();
|
OutputStream outputStream = newBlob.getOutputStream();
|
||||||
Files.copy(targetFile, outputStream);
|
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() {
|
private DigestOutputStream createDigestStream() {
|
||||||
MessageDigest md ;
|
MessageDigest md ;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -8,19 +8,20 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class LfsBlobStoreCleanFilterFactory {
|
class LfsBlobStoreCleanFilterFactory {
|
||||||
|
|
||||||
private final LfsBlobStoreFactory blobStoreFactory;
|
private final LfsBlobStoreFactory blobStoreFactory;
|
||||||
private final sonia.scm.repository.Repository repository;
|
private final sonia.scm.repository.Repository repository;
|
||||||
private final Path targetFile;
|
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.blobStoreFactory = blobStoreFactory;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.targetFile = targetFile;
|
this.targetFile = targetFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
LfsBlobStoreCleanFilter createFilter(Repository db, InputStream in, OutputStream out) throws IOException {
|
@SuppressWarnings("squid:S1172") // suppress unused parameter to keep the api compatible to jgit's FilterCommandFactory
|
||||||
return new LfsBlobStoreCleanFilter(db, in, out, blobStoreFactory.getLfsBlobStore(repository), targetFile);
|
LfsBlobStoreCleanFilter createFilter(Repository db, InputStream in, OutputStream out) {
|
||||||
|
return new LfsBlobStoreCleanFilter(in, out, blobStoreFactory.getLfsBlobStore(repository), targetFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user