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 classApplyCommand.SHA1InputStreamAnInputStreamthat updates aSHA1on every byte read.private static classApplyCommand.StreamLoaderWe write the patch result to aTemporaryBufferand then useDirCacheCheckout.getContent() to run the result through the CR-LF and smudge filters.private static interfaceApplyCommand.StreamSupplierSomething that can supply anInputStream.
-
Field Summary
Fields Modifier and Type Field Description private java.io.InputStreamin-
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 voidapply(Repository repository, java.lang.String path, DirCache cache, java.io.File f, FileHeader fh)private voidapplyBinary(Repository repository, java.lang.String path, java.io.File f, FileHeader fh, ApplyCommand.StreamSupplier loader, ObjectId id, DirCacheCheckout.CheckoutMetadata checkOut)private voidapplyText(Repository repository, java.lang.String path, RawText rt, java.io.File f, FileHeader fh, DirCacheCheckout.CheckoutMetadata checkOut)ApplyResultcall()private booleancanApplyAt(java.util.List<java.nio.ByteBuffer> hunkLines, java.util.List<java.nio.ByteBuffer> newLines, int line)private voidcheckOid(ObjectId baseId, ObjectId id, DiffEntry.ChangeType type, java.io.File f, java.lang.String path)private java.io.InputStreamfilterClean(Repository repository, java.lang.String path, java.io.InputStream fromFile, boolean convertCrLf, java.lang.String filterCommand)private java.io.FilegetFile(java.lang.String path, boolean create)private static booleanhasCrLf(FileHeader fileHeader)private ObjectIdhash(java.io.File f)private voidinitHash(SHA1 hash, long size)private booleanisNoNewlineAtEndOfFile(FileHeader fh)private booleanneedsCrLfConversion(java.io.File f, FileHeader fileHeader)ApplyCommandsetPatch(java.io.InputStream in)Set patchprivate java.nio.ByteBufferslice(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
ApplyCommandcommand 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:
callin interfacejava.util.concurrent.Callable<ApplyResult>- Specified by:
callin classGitCommand<ApplyResult>- Throws:
GitAPIExceptionPatchFormatExceptionPatchApplyException
-
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.IOExceptionPatchApplyException
-
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:
PatchApplyExceptionjava.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:
PatchApplyExceptionjava.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.IOExceptionPatchApplyException
-
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)
-
-