mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Insert some logging
This commit is contained in:
@@ -6,6 +6,8 @@ import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.attributes.FilterCommandRegistry;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.BadRequestException;
|
||||
import sonia.scm.ConcurrentModificationException;
|
||||
import sonia.scm.ContextEntry;
|
||||
@@ -30,6 +32,7 @@ import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
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 final GitWorkdirFactory workdirFactory;
|
||||
@@ -109,12 +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);
|
||||
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);
|
||||
FilterCommandRegistry.unregister(registerKey);
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -7,6 +7,8 @@ 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;
|
||||
import sonia.scm.store.BlobStore;
|
||||
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 {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LfsBlobStoreCleanFilter.class);
|
||||
|
||||
private Lfs lfsUtil;
|
||||
private final BlobStore lfsBlobStore;
|
||||
@@ -44,20 +47,24 @@ public class LfsBlobStoreCleanFilter extends FilterCommand {
|
||||
|
||||
@Override
|
||||
public int run() throws IOException {
|
||||
LOG.info("running scm lfs filter for file {}", targetFile);
|
||||
DigestOutputStream digestOutputStream = createDigestStream();
|
||||
try {
|
||||
long size = ByteStreams.copy(in, digestOutputStream);
|
||||
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) {
|
||||
LOG.info("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 " + loid.getName() + " but has wrong size");
|
||||
throw new RuntimeException("lfs entry already exists for loid " + hash + " but has wrong size");
|
||||
}
|
||||
} 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();
|
||||
Files.copy(targetFile, outputStream);
|
||||
newBlob.commit();
|
||||
|
||||
@@ -65,7 +65,6 @@ public class GitModifyCommand_LFSTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void shouldCreateSecondCommits() throws IOException, GitAPIException {
|
||||
new GitLfsFilterModule().configure(null);
|
||||
createCommit("new_lfs.png", "new content", "fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601", new ByteArrayOutputStream());
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
Reference in New Issue
Block a user