Package org.eclipse.jgit.api
Class ApplyCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<ApplyResult>
-
- org.eclipse.jgit.api.ApplyCommand
-
- All Implemented Interfaces:
java.util.concurrent.Callable<ApplyResult>
public class ApplyCommand extends GitCommand<ApplyResult>
Apply a patch to files and/or to the index.- Since:
- 2.0
- See Also:
- Git documentation about apply
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ApplyCommand.SHA1InputStream
AnInputStream
that updates aSHA1
on every byte read.private static class
ApplyCommand.StreamLoader
We write the patch result to aTemporaryBuffer
and then useDirCacheCheckout
.getContent() to run the result through the CR-LF and smudge filters.private static interface
ApplyCommand.StreamSupplier
Something that can supply anInputStream
.
-
Field Summary
Fields Modifier and Type Field Description private java.io.InputStream
in
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Constructor Description ApplyCommand(Repository repo)
Constructs the command.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
apply(Repository repository, java.lang.String path, DirCache cache, java.io.File f, FileHeader fh)
private void
applyBinary(Repository repository, java.lang.String path, java.io.File f, FileHeader fh, ApplyCommand.StreamSupplier loader, ObjectId id, DirCacheCheckout.CheckoutMetadata checkOut)
private void
applyText(Repository repository, java.lang.String path, RawText rt, java.io.File f, FileHeader fh, DirCacheCheckout.CheckoutMetadata checkOut)
ApplyResult
call()
private boolean
canApplyAt(java.util.List<java.nio.ByteBuffer> hunkLines, java.util.List<java.nio.ByteBuffer> newLines, int line)
private void
checkOid(ObjectId baseId, ObjectId id, DiffEntry.ChangeType type, java.io.File f, java.lang.String path)
private java.io.InputStream
filterClean(Repository repository, java.lang.String path, java.io.InputStream fromFile, boolean convertCrLf, java.lang.String filterCommand)
private java.io.File
getFile(java.lang.String path, boolean create)
private static boolean
hasCrLf(FileHeader fileHeader)
private ObjectId
hash(java.io.File f)
private void
initHash(SHA1 hash, long size)
private boolean
isNoNewlineAtEndOfFile(FileHeader fh)
private boolean
needsCrLfConversion(java.io.File f, FileHeader fileHeader)
ApplyCommand
setPatch(java.io.InputStream in)
Set patchprivate java.nio.ByteBuffer
slice(java.nio.ByteBuffer b, int off)
-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Constructor Detail
-
ApplyCommand
ApplyCommand(Repository repo)
Constructs the command.- Parameters:
repo
-
-
-
Method Detail
-
setPatch
public ApplyCommand setPatch(java.io.InputStream in)
Set patch- Parameters:
in
- the patch to apply- Returns:
- this instance
-
call
public ApplyResult call() throws GitAPIException, PatchFormatException, PatchApplyException
Execute the command
Executes the
ApplyCommand
command with all the options and parameters collected by the setter methods (e.g.setPatch(InputStream)
of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.- Specified by:
call
in interfacejava.util.concurrent.Callable<ApplyResult>
- Specified by:
call
in classGitCommand<ApplyResult>
- Throws:
GitAPIException
PatchFormatException
PatchApplyException
-
getFile
private java.io.File getFile(java.lang.String path, boolean create) throws PatchApplyException
- Throws:
PatchApplyException
-
apply
private void apply(Repository repository, java.lang.String path, DirCache cache, java.io.File f, FileHeader fh) throws java.io.IOException, PatchApplyException
- Throws:
java.io.IOException
PatchApplyException
-
needsCrLfConversion
private boolean needsCrLfConversion(java.io.File f, FileHeader fileHeader) throws java.io.IOException
- Throws:
java.io.IOException
-
hasCrLf
private static boolean hasCrLf(FileHeader fileHeader)
-
filterClean
private java.io.InputStream filterClean(Repository repository, java.lang.String path, java.io.InputStream fromFile, boolean convertCrLf, java.lang.String filterCommand) throws java.io.IOException
- Throws:
java.io.IOException
-
initHash
private void initHash(SHA1 hash, long size)
-
hash
private ObjectId hash(java.io.File f) throws java.io.IOException
- Throws:
java.io.IOException
-
checkOid
private void checkOid(ObjectId baseId, ObjectId id, DiffEntry.ChangeType type, java.io.File f, java.lang.String path) throws PatchApplyException, java.io.IOException
- Throws:
PatchApplyException
java.io.IOException
-
applyBinary
private void applyBinary(Repository repository, java.lang.String path, java.io.File f, FileHeader fh, ApplyCommand.StreamSupplier loader, ObjectId id, DirCacheCheckout.CheckoutMetadata checkOut) throws PatchApplyException, java.io.IOException
- Throws:
PatchApplyException
java.io.IOException
-
applyText
private void applyText(Repository repository, java.lang.String path, RawText rt, java.io.File f, FileHeader fh, DirCacheCheckout.CheckoutMetadata checkOut) throws java.io.IOException, PatchApplyException
- Throws:
java.io.IOException
PatchApplyException
-
canApplyAt
private boolean canApplyAt(java.util.List<java.nio.ByteBuffer> hunkLines, java.util.List<java.nio.ByteBuffer> newLines, int line)
-
slice
private java.nio.ByteBuffer slice(java.nio.ByteBuffer b, int off)
-
isNoNewlineAtEndOfFile
private boolean isNoNewlineAtEndOfFile(FileHeader fh)
-
-