aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/.gitattributes2
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta.patch8
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PostImagebin0 -> 8197 bytes
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PreImagebin0 -> 8192 bytes
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal.patch126
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PostImagebin0 -> 5389 bytes
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PreImagebin0 -> 1629 bytes
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add.patch40
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add_PostImagebin0 -> 1629 bytes
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java41
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java274
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java3
13 files changed, 467 insertions, 30 deletions
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/.gitattributes b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/.gitattributes
index c5831d9a8b..28caa2f82a 100644
--- a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/.gitattributes
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/.gitattributes
@@ -1,3 +1,5 @@
*.patch -crlf
*Image -crlf
*.out -crlf
+delta* -text
+literal* -text
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta.patch b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta.patch
new file mode 100644
index 0000000000..84855308a5
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta.patch
@@ -0,0 +1,8 @@
+diff --git a/delta b/delta
+index b4527005bf9e4da2dd1d7185b51bdac623a4218f..8b370bb5f2bc3261b6b62e80d6edd784a61ec225 100644
+GIT binary patch
+delta 14
+ScmZp0Xmwa1z*+$U3j_csN(Dmz
+
+delta 12
+TcmZp5XmD5{u!xa=5hEi28?FP4
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PostImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PostImage
new file mode 100644
index 0000000000..8b370bb5f2
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PostImage
Binary files differ
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PreImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PreImage
new file mode 100644
index 0000000000..b4527005bf
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/delta_PreImage
Binary files differ
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal.patch b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal.patch
new file mode 100644
index 0000000000..c8811d5bb0
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal.patch
@@ -0,0 +1,126 @@
+diff --git a/literal b/literal
+index 799df8578e3cae8a5e979182391b8e9a6a3deded..74e4201af6378ac87bf9e118fbab6553c7fd355c 100644
+GIT binary patch
+literal 5389
+zcmc&&X;f25x2=0gFa(g;$fO8C5fl|r2$Mhpf-;XXh+qO@qwRo*3aF3^Pe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sf%~un+ua7rY{J06+}0
+zBy8Rps2H|^J|j+2+~rC4Fn?hY0JCP_Lh7i|L+U9?*al+&tkFFXsf0HCR$sKt{%-N*
+z3RR6+FmIp}5m(&$ue@g=bLJKRFlTN7-&`_x$UWlocgCh)3Al~C9R)~fZF~*18f4VZ
+z7oA&Ukw3@K+7SLg7mjhqTqW}hV+`Lhzc5b6=kLU7I5v9W<&&Sk(HI4gO@x470;o9m
+zY+rTyJynfaG+&^Lp59A<M5C)XcqYbh#lf@DF@T<{7x4#s21TzuZbDB++R+zw^S<u0
+z;g3DVz_f{JftkB1C;cKAHg^r29JT@cfi7H53U1dZYR<KAsi_ldm7Uv;a`aFYDEI>1
+zbX{p6Z2g0st1+xPRr~fQk-nI>L$^#A<JHs;1&T!MQ?sAF12H_pkRrHUeIPC;nNZkA
+zAlOSN><5PaL=!6;PSwBuOsthb;@vtaN3H8!fg-Rw7QQgI>Pk?49a|gzM^OzTtUX=(
+z<{t+S#TiXq)6|eE-gzSI0rP_+YmYB4y}5I>Ds?yLyvmA{4domX6nRy|Tb{c@gw3Go
+zSAy>Q%C;02*syDzNaO$;UaV@p5uVP-xx6jWU($8IpY(BDzOQ7j6qV%)(*@c8YURW;
+zzpcp2S4#n^S%{1S+QBwkHC1k7_I_Hk`;+V09uYtc%=Ww#?-e@}G}|!}PU;OD{-Qsp
+bU%LDkMDBWX&Ru`<00000NkvXXu0mjfJA@b~
+
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PostImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PostImage
new file mode 100644
index 0000000000..74e4201af6
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PostImage
Binary files differ
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PreImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PreImage
new file mode 100644
index 0000000000..799df8578e
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_PreImage
Binary files differ
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add.patch b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add.patch
new file mode 100644
index 0000000000..bb6a9e42a3
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add.patch
@@ -0,0 +1,40 @@
+diff --git a/literal_add b/literal_add
+new file mode 100644
+index 0000000000000000000000000000000000000000..799df8578e3cae8a5e979182391b8e9a6a3deded
+GIT binary patch
+literal 1629
+zcmV-j2BP_iP)<h;3K|Lk000e1NJLTq001BW001Be1^@s6b9#F800004b3#c}2nYxW
+zd<bNS000IQNkl<ZScS!xeQcH08Nh$fdGGB9P;Q}RCD0F7u}~l_3X>XOp-ouEG7tw0
+zrz1-=F%F0OAZ*Bt%4AWe%cd6G%m`sY6u$yfhB9DOrfkevkPjQ|7bz{Y^t;geeV+Z%
+z-b-(9d+9KXPx9t{&pFR|p5ODF^FHT&;Y${|kx3oD%S#{awv*l7K)tMQzWRR$@NLb_
+zw;H}v)GQIf6%3j8H~%fa;jd>h$695QRWckW+^S($6E4nXW;Y+LsHg~iVF2&*`MKhR
+zHmmCQ1byyU`lD^F&Xm<pKK62+wdxsmqG|_L|6&~1bD!4kKAp&iGu%LLdCpHn>|TNV
+z%8R3a_|Tzmm#*3P@Q-HSUYM1eH!<b#!H-eZVZxGBjLfoXADrNsadU=e>c3jMs;&&F
+z8VCRQ^d#Seu9v{M5A2zz4}Ep>n<uhf6p_p+1vzZn`55CfJnY+hl#T1RV8b?1fPFTV
+zMq{}1RLvXzNtgju#D6Av7dYQX?EYncy0!eD=hJtHNE$$UTQ~nWa)NIxE}{6=0&;V+
+zNSKLeLKv&c>a1}yj<<B4tsNF%LuSqsh<Qk$W5YWI51(ur^O}gH4%BIH@8;;=D_OL-
+zgyP!@m^v+w?3^q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@cfi7H53U1dZYR<KAsi_ldm7Uv;a`aFYDEI>1
+zbX{p6Z2g0st1+xPRr~fQk-nI>L$^#A<JHs;1&T!MQ?sAF12H_pkRrHUeIPC;nNZkA
+zAlOSN><5PaL=!6;PSwBuOsthb;@vtaN3H8!fg-Rw7QQgI>Pk?49a|gzM^OzTtUX=(
+z<{t+S#TiXq)6|eE-gzSI0rP_+YmYB4y}5I>Ds?yLyvmA{4domX6nRy|Tb{c@gw3Go
+zSAy>Q%C;02*syDzNaO$;UaV@p5uVP-xx6jWU($8IpY(BDzOQ7j6qV%)(*@c8YURW;
+zzpcp2S4#n^S%{1S+QBwkHC1k7_I_Hk`;+V09uYtc%=Ww#?-e@}G}|!}PU;OD{-Qsp
+bU%LDkMDBWX&Ru`<00000NkvXXu0mjfJA@b~
+
+literal 0
+HcmV?d00001
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add_PostImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add_PostImage
new file mode 100644
index 0000000000..799df8578e
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/literal_add_PostImage
Binary files differ
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
index 335a64d70b..e9b8924e6f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
@@ -9,6 +9,7 @@
*/
package org.eclipse.jgit.api;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -19,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import org.eclipse.jgit.api.errors.PatchApplyException;
import org.eclipse.jgit.api.errors.PatchFormatException;
@@ -29,6 +31,7 @@ import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.util.IO;
import org.junit.Test;
public class ApplyCommandTest extends RepositoryTestCase {
@@ -246,6 +249,44 @@ public class ApplyCommandTest extends RepositoryTestCase {
}
}
+ private void checkBinary(String name, boolean hasPreImage)
+ throws Exception {
+ try (Git git = new Git(db)) {
+ byte[] post = IO
+ .readWholeStream(getTestResource(name + "_PostImage"), 0)
+ .array();
+ File f = new File(db.getWorkTree(), name);
+ if (hasPreImage) {
+ byte[] pre = IO
+ .readWholeStream(getTestResource(name + "_PreImage"), 0)
+ .array();
+ Files.write(f.toPath(), pre);
+ git.add().addFilepattern(name).call();
+ git.commit().setMessage("PreImage").call();
+ }
+ ApplyResult result = git.apply()
+ .setPatch(getTestResource(name + ".patch")).call();
+ assertEquals(1, result.getUpdatedFiles().size());
+ assertEquals(f, result.getUpdatedFiles().get(0));
+ assertArrayEquals(post, Files.readAllBytes(f.toPath()));
+ }
+ }
+
+ @Test
+ public void testBinaryDelta() throws Exception {
+ checkBinary("delta", true);
+ }
+
+ @Test
+ public void testBinaryLiteral() throws Exception {
+ checkBinary("literal", true);
+ }
+
+ @Test
+ public void testBinaryLiteralAdd() throws Exception {
+ checkBinary("literal_add", false);
+ }
+
@Test
public void testAddA1() throws Exception {
ApplyResult result = init("A1", false, true);
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
index 8b6872d337..962324e0f7 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -13,6 +13,9 @@ ambiguousObjectAbbreviation=Object abbreviation {0} is ambiguous
aNewObjectIdIsRequired=A NewObjectId is required.
anExceptionOccurredWhileTryingToAddTheIdOfHEAD=An exception occurred while trying to add the Id of HEAD
anSSHSessionHasBeenAlreadyCreated=An SSH session has been already created
+applyBinaryBaseOidWrong=Cannot apply binary patch; OID for file {0} does not match
+applyBinaryOidTooShort=Binary patch for file {0} does not have full IDs
+applyBinaryResultOidWrong=Result of binary patch for file {0} has wrong OID.
applyingCommit=Applying {0}
archiveFormatAlreadyAbsent=Archive format already absent: {0}
archiveFormatAlreadyRegistered=Archive format already registered with different implementation: {0}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
index 5d975ea389..f7eba88acd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
@@ -9,7 +9,9 @@
*/
package org.eclipse.jgit.api;
+import java.io.BufferedInputStream;
import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -25,6 +27,7 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.zip.InflaterInputStream;
import org.eclipse.jgit.api.errors.FilterFailedException;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -44,10 +47,13 @@ import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.CoreConfig.EolStreamType;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectStream;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.patch.BinaryHunk;
import org.eclipse.jgit.patch.FileHeader;
+import org.eclipse.jgit.patch.FileHeader.PatchType;
import org.eclipse.jgit.patch.HunkHeader;
import org.eclipse.jgit.patch.Patch;
import org.eclipse.jgit.treewalk.FileTreeIterator;
@@ -57,14 +63,17 @@ import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FS.ExecutionResult;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.StringUtils;
import org.eclipse.jgit.util.TemporaryBuffer;
-import org.eclipse.jgit.util.FS.ExecutionResult;
import org.eclipse.jgit.util.TemporaryBuffer.LocalFile;
+import org.eclipse.jgit.util.io.BinaryDeltaInputStream;
+import org.eclipse.jgit.util.io.BinaryHunkInputStream;
import org.eclipse.jgit.util.io.EolStreamTypeUtil;
+import org.eclipse.jgit.util.sha1.SHA1;
/**
* Apply a patch to files and/or to the index.
@@ -191,6 +200,9 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
private void apply(Repository repository, String path, DirCache cache,
File f, FileHeader fh) throws IOException, PatchApplyException {
+ if (PatchType.BINARY.equals(fh.getPatchType())) {
+ return;
+ }
boolean convertCrLf = needsCrLfConversion(f, fh);
// Use a TreeWalk with a DirCacheIterator to pick up the correct
// clean/smudge filters. CR-LF handling is completely determined by
@@ -217,16 +229,23 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
FileTreeIterator file = walk.getTree(fileIdx,
FileTreeIterator.class);
if (file != null) {
- command = walk
- .getFilterCommand(Constants.ATTR_FILTER_TYPE_CLEAN);
- RawText raw;
- // Can't use file.openEntryStream() as it would do CR-LF
- // conversion as usual, not as wanted by us.
- try (InputStream input = filterClean(repository, path,
- new FileInputStream(f), convertCrLf, command)) {
- raw = new RawText(IO.readWholeStream(input, 0).array());
+ if (PatchType.GIT_BINARY.equals(fh.getPatchType())) {
+ applyBinary(repository, path, f, fh,
+ file::openEntryStream, file.getEntryObjectId(),
+ checkOut);
+ } else {
+ command = walk.getFilterCommand(
+ Constants.ATTR_FILTER_TYPE_CLEAN);
+ RawText raw;
+ // Can't use file.openEntryStream() as it would do CR-LF
+ // conversion as usual, not as wanted by us.
+ try (InputStream input = filterClean(repository, path,
+ new FileInputStream(f), convertCrLf, command)) {
+ raw = new RawText(
+ IO.readWholeStream(input, 0).array());
+ }
+ applyText(repository, path, raw, f, fh, checkOut);
}
- apply(repository, path, raw, f, fh, checkOut);
return;
}
}
@@ -234,21 +253,30 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
// File ignored?
RawText raw;
CheckoutMetadata checkOut;
- if (convertCrLf) {
- try (InputStream input = EolStreamTypeUtil.wrapInputStream(
- new FileInputStream(f), EolStreamType.TEXT_LF)) {
- raw = new RawText(IO.readWholeStream(input, 0).array());
- }
- checkOut = new CheckoutMetadata(EolStreamType.TEXT_CRLF, null);
- } else {
- raw = new RawText(f);
+ if (PatchType.GIT_BINARY.equals(fh.getPatchType())) {
checkOut = new CheckoutMetadata(EolStreamType.DIRECT, null);
+ applyBinary(repository, path, f, fh, () -> new FileInputStream(f),
+ null, checkOut);
+ } else {
+ if (convertCrLf) {
+ try (InputStream input = EolStreamTypeUtil.wrapInputStream(
+ new FileInputStream(f), EolStreamType.TEXT_LF)) {
+ raw = new RawText(IO.readWholeStream(input, 0).array());
+ }
+ checkOut = new CheckoutMetadata(EolStreamType.TEXT_CRLF, null);
+ } else {
+ raw = new RawText(f);
+ checkOut = new CheckoutMetadata(EolStreamType.DIRECT, null);
+ }
+ applyText(repository, path, raw, f, fh, checkOut);
}
- apply(repository, path, raw, f, fh, checkOut);
}
private boolean needsCrLfConversion(File f, FileHeader fileHeader)
throws IOException {
+ if (PatchType.GIT_BINARY.equals(fileHeader.getPatchType())) {
+ return false;
+ }
if (!hasCrLf(fileHeader)) {
try (InputStream input = new FileInputStream(f)) {
return RawText.isCrLfText(input);
@@ -258,7 +286,7 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
}
private static boolean hasCrLf(FileHeader fileHeader) {
- if (fileHeader == null) {
+ if (PatchType.GIT_BINARY.equals(fileHeader.getPatchType())) {
return false;
}
for (HunkHeader header : fileHeader.getHunks()) {
@@ -331,18 +359,29 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
}
/**
+ * Something that can supply an {@link InputStream}.
+ */
+ private interface StreamSupplier {
+ InputStream load() throws IOException;
+ }
+
+ /**
* We write the patch result to a {@link TemporaryBuffer} and then use
* {@link DirCacheCheckout}.getContent() to run the result through the CR-LF
* and smudge filters. DirCacheCheckout needs an ObjectLoader, not a
- * TemporaryBuffer, so this class bridges between the two, making the
- * TemporaryBuffer look like an ordinary git blob to DirCacheCheckout.
+ * TemporaryBuffer, so this class bridges between the two, making any Stream
+ * provided by a {@link StreamSupplier} look like an ordinary git blob to
+ * DirCacheCheckout.
*/
- private static class BufferLoader extends ObjectLoader {
+ private static class StreamLoader extends ObjectLoader {
- private TemporaryBuffer data;
+ private StreamSupplier data;
- BufferLoader(TemporaryBuffer data) {
+ private long size;
+
+ StreamLoader(StreamSupplier data, long length) {
this.data = data;
+ this.size = length;
}
@Override
@@ -352,7 +391,7 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
@Override
public long getSize() {
- return data.length();
+ return size;
}
@Override
@@ -369,12 +408,146 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
public ObjectStream openStream()
throws MissingObjectException, IOException {
return new ObjectStream.Filter(getType(), getSize(),
- data.openInputStream());
+ new BufferedInputStream(data.load()));
}
}
- private void apply(Repository repository, String path, RawText rt, File f,
- FileHeader fh, CheckoutMetadata checkOut)
+ private void initHash(SHA1 hash, long size) {
+ hash.update(Constants.encodedTypeString(Constants.OBJ_BLOB));
+ hash.update((byte) ' ');
+ hash.update(Constants.encodeASCII(size));
+ hash.update((byte) 0);
+ }
+
+ private ObjectId hash(File f) throws IOException {
+ SHA1 hash = SHA1.newInstance();
+ initHash(hash, f.length());
+ try (InputStream input = new FileInputStream(f)) {
+ byte[] buf = new byte[8192];
+ int n;
+ while ((n = input.read(buf)) >= 0) {
+ hash.update(buf, 0, n);
+ }
+ }
+ return hash.toObjectId();
+ }
+
+ private void checkOid(ObjectId baseId, ObjectId id, ChangeType type, File f,
+ String path)
+ throws PatchApplyException, IOException {
+ boolean hashOk = false;
+ if (id != null) {
+ hashOk = baseId.equals(id);
+ if (!hashOk && ChangeType.ADD.equals(type)
+ && ObjectId.zeroId().equals(baseId)) {
+ // We create the file first. The OID of an empty file is not the
+ // zero id!
+ hashOk = Constants.EMPTY_BLOB_ID.equals(id);
+ }
+ } else {
+ if (ObjectId.zeroId().equals(baseId)) {
+ // File empty is OK.
+ hashOk = !f.exists() || f.length() == 0;
+ } else {
+ hashOk = baseId.equals(hash(f));
+ }
+ }
+ if (!hashOk) {
+ throw new PatchApplyException(MessageFormat
+ .format(JGitText.get().applyBinaryBaseOidWrong, path));
+ }
+ }
+
+ private void applyBinary(Repository repository, String path, File f,
+ FileHeader fh, StreamSupplier loader, ObjectId id,
+ CheckoutMetadata checkOut)
+ throws PatchApplyException, IOException {
+ if (!fh.getOldId().isComplete() || !fh.getNewId().isComplete()) {
+ throw new PatchApplyException(MessageFormat
+ .format(JGitText.get().applyBinaryOidTooShort, path));
+ }
+ BinaryHunk hunk = fh.getForwardBinaryHunk();
+ // A BinaryHunk has the start at the "literal" or "delta" token. Data
+ // starts on the next line.
+ int start = RawParseUtils.nextLF(hunk.getBuffer(),
+ hunk.getStartOffset());
+ int length = hunk.getEndOffset() - start;
+ SHA1 hash = SHA1.newInstance();
+ // Write to a buffer and copy to the file only if everything was fine
+ TemporaryBuffer buffer = new TemporaryBuffer.LocalFile(null);
+ try {
+ switch (hunk.getType()) {
+ case LITERAL_DEFLATED:
+ // This just overwrites the file. We need to check the hash of
+ // the base.
+ checkOid(fh.getOldId().toObjectId(), id, fh.getChangeType(), f,
+ path);
+ initHash(hash, hunk.getSize());
+ try (OutputStream out = buffer;
+ InputStream inflated = new SHA1InputStream(hash,
+ new InflaterInputStream(
+ new BinaryHunkInputStream(
+ new ByteArrayInputStream(
+ hunk.getBuffer(), start,
+ length))))) {
+ DirCacheCheckout.getContent(repository, path, checkOut,
+ new StreamLoader(() -> inflated, hunk.getSize()),
+ null, out);
+ if (!fh.getNewId().toObjectId().equals(hash.toObjectId())) {
+ throw new PatchApplyException(MessageFormat.format(
+ JGitText.get().applyBinaryResultOidWrong,
+ path));
+ }
+ }
+ try (InputStream bufIn = buffer.openInputStream()) {
+ Files.copy(bufIn, f.toPath(),
+ StandardCopyOption.REPLACE_EXISTING);
+ }
+ break;
+ case DELTA_DEFLATED:
+ // Unfortunately delta application needs random access to the
+ // base to construct the result.
+ byte[] base;
+ try (InputStream input = loader.load()) {
+ base = IO.readWholeStream(input, 0).array();
+ }
+ // At least stream the result!
+ try (BinaryDeltaInputStream input = new BinaryDeltaInputStream(
+ base,
+ new InflaterInputStream(new BinaryHunkInputStream(
+ new ByteArrayInputStream(hunk.getBuffer(),
+ start, length))))) {
+ long finalSize = input.getExpectedResultSize();
+ initHash(hash, finalSize);
+ try (OutputStream out = buffer;
+ SHA1InputStream hashed = new SHA1InputStream(hash,
+ input)) {
+ DirCacheCheckout.getContent(repository, path, checkOut,
+ new StreamLoader(() -> hashed, finalSize), null,
+ out);
+ if (!fh.getNewId().toObjectId()
+ .equals(hash.toObjectId())) {
+ throw new PatchApplyException(MessageFormat.format(
+ JGitText.get().applyBinaryResultOidWrong,
+ path));
+ }
+ }
+ }
+ try (InputStream bufIn = buffer.openInputStream()) {
+ Files.copy(bufIn, f.toPath(),
+ StandardCopyOption.REPLACE_EXISTING);
+ }
+ break;
+ default:
+ break;
+ }
+ } finally {
+ buffer.destroy();
+ }
+ }
+
+ private void applyText(Repository repository, String path, RawText rt,
+ File f, FileHeader fh, CheckoutMetadata checkOut)
throws IOException, PatchApplyException {
List<String> oldLines = new ArrayList<>(rt.size());
for (int i = 0; i < rt.size(); i++) {
@@ -514,7 +687,9 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
}
try (OutputStream output = new FileOutputStream(f)) {
DirCacheCheckout.getContent(repository, path, checkOut,
- new BufferLoader(buffer), null, output);
+ new StreamLoader(buffer::openInputStream,
+ buffer.length()),
+ null, output);
}
} finally {
buffer.destroy();
@@ -565,4 +740,43 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
return lhrt.getString(lhrt.size() - 1)
.equals("\\ No newline at end of file"); //$NON-NLS-1$
}
+
+ /**
+ * An {@link InputStream} that updates a {@link SHA1} on every byte read.
+ * The hash is supposed to have been initialized before reading starts.
+ */
+ private static class SHA1InputStream extends InputStream {
+
+ private final SHA1 hash;
+
+ private final InputStream in;
+
+ SHA1InputStream(SHA1 hash, InputStream in) {
+ this.hash = hash;
+ this.in = in;
+ }
+
+ @Override
+ public int read() throws IOException {
+ int b = in.read();
+ if (b >= 0) {
+ hash.update((byte) b);
+ }
+ return b;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int n = in.read(b, off, len);
+ if (n > 0) {
+ hash.update(b, off, n);
+ }
+ return n;
+ }
+
+ @Override
+ public void close() throws IOException {
+ in.close();
+ }
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
index 3b67b0f628..fd54986f94 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -41,6 +41,9 @@ public class JGitText extends TranslationBundle {
/***/ public String aNewObjectIdIsRequired;
/***/ public String anExceptionOccurredWhileTryingToAddTheIdOfHEAD;
/***/ public String anSSHSessionHasBeenAlreadyCreated;
+ /***/ public String applyBinaryBaseOidWrong;
+ /***/ public String applyBinaryOidTooShort;
+ /***/ public String applyBinaryResultOidWrong;
/***/ public String applyingCommit;
/***/ public String archiveFormatAlreadyAbsent;
/***/ public String archiveFormatAlreadyRegistered;