mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 12:20:56 +01:00
Merge with 2.0.0-m3
This commit is contained in:
@@ -213,8 +213,14 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
|
||||
if (lfsPointer.isPresent()) {
|
||||
BlobStore lfsBlobStore = lfsBlobStoreFactory.getLfsBlobStore(repository);
|
||||
Blob blob = lfsBlobStore.get(lfsPointer.get().getOid().getName());
|
||||
file.setLength(blob.getSize());
|
||||
String oid = lfsPointer.get().getOid().getName();
|
||||
Blob blob = lfsBlobStore.get(oid);
|
||||
if (blob == null) {
|
||||
logger.error("lfs blob for lob id {} not found in lfs store of repository {}", oid, repository.getNamespaceAndName());
|
||||
file.setLength(-1);
|
||||
} else {
|
||||
file.setLength(blob.getSize());
|
||||
}
|
||||
} else {
|
||||
file.setLength(loader.getSize());
|
||||
}
|
||||
|
||||
@@ -145,7 +145,12 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
|
||||
|
||||
private Loader loadFromLfsStore(TreeWalk treeWalk, RevWalk revWalk, LfsPointer lfsPointer) throws IOException {
|
||||
BlobStore lfsBlobStore = lfsBlobStoreFactory.getLfsBlobStore(repository);
|
||||
Blob blob = lfsBlobStore.get(lfsPointer.getOid().getName());
|
||||
String oid = lfsPointer.getOid().getName();
|
||||
Blob blob = lfsBlobStore.get(oid);
|
||||
if (blob == null) {
|
||||
logger.error("lfs blob for lob id {} not found in lfs store of repository {}", oid, repository.getNamespaceAndName());
|
||||
throw notFound(entity("LFS", oid).in(repository));
|
||||
}
|
||||
GitUtil.release(revWalk);
|
||||
GitUtil.release(treeWalk);
|
||||
return new BlobLoader(blob);
|
||||
|
||||
@@ -33,13 +33,18 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.diff.DiffEntry;
|
||||
import org.eclipse.jgit.diff.DiffFormatter;
|
||||
import org.eclipse.jgit.util.QuotedString;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.DiffCommandBuilder;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
|
||||
@@ -51,12 +56,12 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
|
||||
@Override
|
||||
public DiffCommandBuilder.OutputStreamConsumer getDiffResult(DiffCommandRequest request) throws IOException {
|
||||
@SuppressWarnings("squid:S2095") // repository will be closed with the RepositoryService
|
||||
org.eclipse.jgit.lib.Repository repository = open();
|
||||
org.eclipse.jgit.lib.Repository repository = open();
|
||||
|
||||
Differ.Diff diff = Differ.diff(repository, request);
|
||||
|
||||
return output -> {
|
||||
try (DiffFormatter formatter = new DiffFormatter(output)) {
|
||||
try (DiffFormatter formatter = new DiffFormatter(new DequoteOutputStream(output))) {
|
||||
formatter.setRepository(repository);
|
||||
|
||||
for (DiffEntry e : diff.getEntries()) {
|
||||
@@ -70,4 +75,116 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
|
||||
};
|
||||
}
|
||||
|
||||
static class DequoteOutputStream extends OutputStream {
|
||||
|
||||
private static final String[] DEQUOTE_STARTS = {
|
||||
"--- ",
|
||||
"+++ ",
|
||||
"diff --git "
|
||||
};
|
||||
|
||||
private final OutputStream target;
|
||||
|
||||
private boolean afterNL = true;
|
||||
private boolean writeToBuffer = false;
|
||||
private int numberOfPotentialBeginning = -1;
|
||||
private int potentialBeginningCharCount = 0;
|
||||
private boolean inPotentialQuotedLine = false;
|
||||
|
||||
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
|
||||
DequoteOutputStream(OutputStream target) {
|
||||
this.target = new BufferedOutputStream(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int i) throws IOException {
|
||||
if (i == (int) '\n') {
|
||||
handleNewLine(i);
|
||||
return;
|
||||
}
|
||||
|
||||
if (afterNL) {
|
||||
afterNL = false;
|
||||
if (foundPotentialBeginning(i)) {
|
||||
return;
|
||||
}
|
||||
numberOfPotentialBeginning = -1;
|
||||
inPotentialQuotedLine = false;
|
||||
}
|
||||
|
||||
if (inPotentialQuotedLine && i == '"') {
|
||||
handleQuote();
|
||||
return;
|
||||
}
|
||||
|
||||
if (numberOfPotentialBeginning > -1 && checkForFurtherBeginning(i)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (writeToBuffer) {
|
||||
buffer.write(i);
|
||||
} else {
|
||||
target.write(i);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkForFurtherBeginning(int i) throws IOException {
|
||||
if (i == DEQUOTE_STARTS[numberOfPotentialBeginning].charAt(potentialBeginningCharCount)) {
|
||||
if (potentialBeginningCharCount + 1 < DEQUOTE_STARTS[numberOfPotentialBeginning].length()) {
|
||||
++potentialBeginningCharCount;
|
||||
} else {
|
||||
inPotentialQuotedLine = true;
|
||||
}
|
||||
target.write(i);
|
||||
return true;
|
||||
} else {
|
||||
numberOfPotentialBeginning = -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean foundPotentialBeginning(int i) throws IOException {
|
||||
for (int n = 0; n < DEQUOTE_STARTS.length; ++n) {
|
||||
if (i == DEQUOTE_STARTS[n].charAt(0)) {
|
||||
numberOfPotentialBeginning = n;
|
||||
potentialBeginningCharCount = 1;
|
||||
target.write(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleQuote() throws IOException {
|
||||
if (writeToBuffer) {
|
||||
buffer.write('"');
|
||||
dequoteBuffer();
|
||||
} else {
|
||||
writeToBuffer = true;
|
||||
buffer.reset();
|
||||
buffer.write('"');
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNewLine(int i) throws IOException {
|
||||
afterNL = true;
|
||||
if (writeToBuffer) {
|
||||
dequoteBuffer();
|
||||
}
|
||||
target.write(i);
|
||||
}
|
||||
|
||||
private void dequoteBuffer() throws IOException {
|
||||
byte[] bytes = buffer.toByteArray();
|
||||
String dequote = QuotedString.GIT_PATH.dequote(bytes, 0, bytes.length);
|
||||
target.write(dequote.getBytes(UTF_8));
|
||||
writeToBuffer = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
target.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user