Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionSha256Sum=df67a32e86e3276d011735facb1535f64d0d88df84fa87521e90becc2d735444
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
15 changes: 7 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -170,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )

JAVACMD=$( cygpath --unix "$JAVACMD" )

Expand Down Expand Up @@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
25 changes: 13 additions & 12 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,22 +59,21 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
88 changes: 76 additions & 12 deletions jgit/src/main/java/org/openrewrite/jgit/diff/DiffFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;

import org.openrewrite.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.openrewrite.jgit.diff.DiffEntry.ChangeType;
Expand Down Expand Up @@ -68,6 +71,7 @@
import org.openrewrite.jgit.treewalk.filter.TreeFilter;
import org.openrewrite.jgit.util.LfsFactory;
import org.openrewrite.jgit.util.QuotedString;
import org.openrewrite.jgit.util.io.BinaryHunkOutputStream;

/**
* Format a Git style patch script.
Expand Down Expand Up @@ -96,6 +100,8 @@ public class DiffFormatter implements AutoCloseable {

private RawTextComparator comparator = RawTextComparator.DEFAULT;

private boolean binaryPatch = false;

private int binaryFileThreshold = DEFAULT_BINARY_FILE_THRESHOLD;

private String oldPrefix = "a/"; //$NON-NLS-1$
Expand Down Expand Up @@ -259,6 +265,10 @@ public void setBinaryFileThreshold(int threshold) {
this.binaryFileThreshold = threshold;
}

public void setBinary(boolean binaryPatch) {
this.binaryPatch = binaryPatch;
}

/**
* Set the prefix applied in front of old file paths.
*
Expand Down Expand Up @@ -714,7 +724,7 @@ private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
}

private String format(AbbreviatedObjectId id) {
if (id.isComplete() && reader != null) {
if (id.isComplete() && reader != null && !binaryPatch) {
try {
id = reader.abbreviate(id.toObjectId(), abbreviationLength);
} catch (IOException cannotAbbreviate) {
Expand Down Expand Up @@ -764,6 +774,8 @@ public void format(FileHeader head, RawText a, RawText b)
out.write(head.getBuffer(), start, end - start);
if (head.getPatchType() == PatchType.UNIFIED)
format(head.toEditList(), a, b);
else if (head.getPatchType() == PatchType.GIT_BINARY && a != null && b != null)
formatBinary(a, b);
}

/**
Expand Down Expand Up @@ -816,6 +828,26 @@ public void format(EditList edits, RawText a, RawText b)
}
}

private void formatBinary(RawText a, RawText b) throws IOException {
byte[] oldImage = a.getRawContent();
byte[] newImage = b.getRawContent();
out.write(encodeASCII("literal " + newImage.length + "\n"));
Deflater deflater = new Deflater();
deflater.setLevel(Deflater.BEST_SPEED);
try (OutputStream os = new DeflaterOutputStream(new BinaryHunkOutputStream(out), deflater, 1024)) {
os.write(newImage);
}
out.write('\n');
out.write(encodeASCII("literal " + oldImage.length + "\n"));
deflater = new Deflater(); // deflater is stateful, reset it
deflater.setLevel(Deflater.BEST_SPEED);
try (OutputStream os = new DeflaterOutputStream(new BinaryHunkOutputStream(out), deflater, 1024)) {
os.write(oldImage);
}
out.write('\n');
out.write('\n');
}

/**
* Output a line of context (unmodified line).
*
Expand Down Expand Up @@ -997,17 +1029,45 @@ private FormatResult createFormatResult(DiffEntry ent) throws IOException,
aRaw = new RawText(writeGitLinkText(ent.getOldId()));
bRaw = new RawText(writeGitLinkText(ent.getNewId()));
} else {
try {
aRaw = open(OLD, ent);
bRaw = open(NEW, ent);
} catch (BinaryBlobException e) {
// Do nothing; we check for null below.
formatOldNewPaths(buf, ent);
buf.write(encodeASCII("Binary files differ\n")); //$NON-NLS-1$
editList = new EditList();
type = PatchType.BINARY;
res.header = new FileHeader(buf.toByteArray(), editList, type);
if (binaryPatch) {
try {
aRaw = open(OLD, ent);
bRaw = open(NEW, ent);
} catch (BinaryBlobException e) {
// Do nothing; we check for null below.
formatOldNewPaths(buf, ent);
buf.write(encodeASCII("Binary files differ\n")); //$NON-NLS-1$
editList = new EditList();
type = PatchType.BINARY;
res.header = new FileHeader(buf.toByteArray(), editList, type);
return res;
}

if (Arrays.equals(aRaw.getRawContent(), bRaw.getRawContent())) {
type = PatchType.GIT_BINARY;
res.header = new FileHeader(buf.toByteArray(), type);
return res;
}

buf.write(encodeASCII("GIT binary patch\n"));
type = PatchType.GIT_BINARY;
res.header = new FileHeader(buf.toByteArray(), type);
res.a = aRaw;
res.b = bRaw;
return res;
} else {
try {
aRaw = open(OLD, ent);
bRaw = open(NEW, ent);
} catch (BinaryBlobException e) {
// Do nothing; we check for null below.
formatOldNewPaths(buf, ent);
buf.write(encodeASCII("Binary files differ\n")); //$NON-NLS-1$
editList = new EditList();
type = PatchType.BINARY;
res.header = new FileHeader(buf.toByteArray(), editList, type);
return res;
}
}
}

Expand Down Expand Up @@ -1072,7 +1132,11 @@ private RawText open(DiffEntry.Side side, DiffEntry entry)

ObjectLoader ldr = LfsFactory.getInstance().applySmudgeFilter(repository,
source.open(side, entry), entry.getDiffAttribute());
return RawText.load(ldr, binaryFileThreshold);
if (binaryPatch) {
return RawText.loadBinary(ldr, binaryFileThreshold);
} else {
return RawText.load(ldr, binaryFileThreshold);
}
}

/**
Expand Down
37 changes: 37 additions & 0 deletions jgit/src/main/java/org/openrewrite/jgit/diff/RawText.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,41 @@ public static RawText load(ObjectLoader ldr, int threshold)
return new RawText(data, RawParseUtils.lineMapOrBinary(data, 0, (int) sz));
}
}

/**
* Read a blob object into RawText, or throw BinaryBlobException if the blob
* is binary.
*
* @param ldr
* the ObjectLoader for the blob
* @param threshold
* if the blob is larger than this size, it is always assumed to
* be binary.
* @since 4.10
* @return the RawText representing the blob.
* @throws org.openrewrite.jgit.errors.BinaryBlobException
* if the blob contains binary data.
* @throws java.io.IOException
* if the input could not be read.
*/
public static RawText loadBinary(ObjectLoader ldr, int threshold)
throws IOException, BinaryBlobException {
long sz = ldr.getSize();

if (sz > threshold) {
throw new BinaryBlobException();
}

try (InputStream stream = ldr.openStream()) {
byte[] data;
try {
data = new byte[(int) sz];
} catch (OutOfMemoryError e) {
throw new LargeObjectException.OutOfMemory(e);
}

IO.readFully(stream, data, 0, (int) sz);
return new RawText(data);
}
}
}
18 changes: 15 additions & 3 deletions jgit/src/main/java/org/openrewrite/jgit/patch/FileHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,29 @@ public enum PatchType {
*
* @param headerLines
* buffer holding the diff header for this file
* @param edits
* the edits for this file
* @param type
* the type of patch used to modify this file
*/
public FileHeader(byte[] headerLines, EditList edits, PatchType type) {
public FileHeader(byte[] headerLines, PatchType type) {
this(headerLines, 0);
endOffset = headerLines.length;
int ptr = parseGitFileName(Patch.DIFF_GIT.length, headerLines.length);
parseGitHeaders(ptr, headerLines.length);
this.patchType = type;
}

/**
* Constructs a new FileHeader
*
* @param headerLines
* buffer holding the diff header for this file
* @param edits
* the edits for this file
* @param type
* the type of patch used to modify this file
*/
public FileHeader(byte[] headerLines, EditList edits, PatchType type) {
this(headerLines, type);
addHunk(new HunkHeader(this, edits));
}

Expand Down