Insert some logging

This commit is contained in:
Rene Pfeuffer
2019-10-08 16:19:30 +02:00
parent ffcb96820e
commit 7af882fe8e
3 changed files with 15 additions and 4 deletions

View File

@@ -6,6 +6,8 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.attributes.FilterCommandRegistry; import org.eclipse.jgit.attributes.FilterCommandRegistry;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.BadRequestException; import sonia.scm.BadRequestException;
import sonia.scm.ConcurrentModificationException; import sonia.scm.ConcurrentModificationException;
import sonia.scm.ContextEntry; import sonia.scm.ContextEntry;
@@ -30,6 +32,7 @@ import static sonia.scm.NotFoundException.notFound;
public class GitModifyCommand extends AbstractGitCommand implements ModifyCommand { public class GitModifyCommand extends AbstractGitCommand implements ModifyCommand {
private static final Logger LOG = LoggerFactory.getLogger(GitModifyCommand.class);
private static final Striped<Lock> REGISTER_LOCKS = Striped.lock(5); private static final Striped<Lock> REGISTER_LOCKS = Striped.lock(5);
private final GitWorkdirFactory workdirFactory; private final GitWorkdirFactory workdirFactory;
@@ -109,12 +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);
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);
FilterCommandRegistry.unregister(registerKey); FilterCommandRegistry.unregister(registerKey);
} }
} finally { } finally {

View File

@@ -7,6 +7,8 @@ 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.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.store.Blob; import sonia.scm.store.Blob;
import sonia.scm.store.BlobStore; import sonia.scm.store.BlobStore;
import sonia.scm.util.IOUtil; import sonia.scm.util.IOUtil;
@@ -28,6 +30,7 @@ import static org.eclipse.jgit.lfs.lib.Constants.LONG_HASH_FUNCTION;
*/ */
public class LfsBlobStoreCleanFilter extends FilterCommand { public class LfsBlobStoreCleanFilter extends FilterCommand {
private static final Logger LOG = LoggerFactory.getLogger(LfsBlobStoreCleanFilter.class);
private Lfs lfsUtil; private Lfs lfsUtil;
private final BlobStore lfsBlobStore; private final BlobStore lfsBlobStore;
@@ -44,20 +47,24 @@ public class LfsBlobStoreCleanFilter extends FilterCommand {
@Override @Override
public int run() throws IOException { public int run() throws IOException {
LOG.info("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);
AnyLongObjectId loid = LongObjectId.fromRaw(digestOutputStream.getMessageDigest().digest()); AnyLongObjectId loid = LongObjectId.fromRaw(digestOutputStream.getMessageDigest().digest());
String hash = loid.getName();
Blob existingBlob = lfsBlobStore.get(loid.getName()); Blob existingBlob = lfsBlobStore.get(hash);
if (existingBlob != null) { if (existingBlob != null) {
LOG.info("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 // Mathematicians say this will never happen
throw new RuntimeException("lfs entry already exists for loid " + loid.getName() + " but has wrong size"); throw new RuntimeException("lfs entry already exists for loid " + hash + " but has wrong size");
} }
} else { } else {
Blob newBlob = lfsBlobStore.create(loid.getName()); LOG.info("uploading new lfs blob for oid {}", hash);
Blob newBlob = lfsBlobStore.create(hash);
OutputStream outputStream = newBlob.getOutputStream(); OutputStream outputStream = newBlob.getOutputStream();
Files.copy(targetFile, outputStream); Files.copy(targetFile, outputStream);
newBlob.commit(); newBlob.commit();

View File

@@ -65,7 +65,6 @@ public class GitModifyCommand_LFSTest extends AbstractGitCommandTestBase {
@Test @Test
public void shouldCreateSecondCommits() throws IOException, GitAPIException { public void shouldCreateSecondCommits() throws IOException, GitAPIException {
new GitLfsFilterModule().configure(null);
createCommit("new_lfs.png", "new content", "fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601", new ByteArrayOutputStream()); createCommit("new_lfs.png", "new content", "fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601", new ByteArrayOutputStream());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();