Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util

public Class LfsFactory

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .PrintStream, java.text.MessageFormat, java.util.concurrent.Callable, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.attributes.Attribute, .Attributes, org.eclipse.jgit.hooks.PrePushHook, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.ObjectLoader, .Repository, org.eclipse.jgit.revwalk.RevCommit, org.eclipse.jgit.treewalk.FileTreeIterator, .TreeWalk, org.eclipse.jgit.treewalk.filter.PathFilter

Represents an optionally present LFS support implementation
Since
4.11

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
LfsFactory.LfsInputStream

Encapsulate a potentially exchanged InputStream along with the expected stream content length.

public static interface
LfsFactory.LfsInstallCommand

A command to enable LFS.

Field Summary

Modifier and TypeField and Description
private static LfsFactory

Constructor Summary

AccessConstructor and Description
protected
LfsFactory()

Constructor

Method Summary

Modifier and TypeMethod and Description
public LfsFactory.LfsInputStream

Returns:

a stream to the content that should be written to the object store along with the expected length of the stream. the original stream is not applicable.
applyCleanFilter
(Repository
the repository
db
,
InputStream
the original input
input
,
long
the expected input stream length
length
,
Attribute
the attribute used to check for LFS enablement (i.e. "merge", "diff", "filter" from .gitattributes).
attribute
)

Apply clean filtering to the given stream, writing the file content to the LFS storage if required and returning a stream to the LFS pointer instead.

public ObjectLoader

Returns:

a loader for the actual data of a blob, or the original loader in case LFS is not applicable.
applySmudgeFilter
(Repository
the repository
db
,
ObjectLoader
the loader for the blob
loader
,
Attribute
the attribute used to check for LFS enablement (i.e. "merge", "diff", "filter" from .gitattributes).
attribute
)

Apply smudge filtering to a given loader, potentially redirecting it to a LFS blob which is downloaded on demand.

public static Attributes

Returns:

the Attributes for the given path.
getAttributesForPath
(Repository
the repository
db
,
String
the path to find attributes for
path
)

Get git attributes for given path

public static Attributes

Returns:

the Attributes for the given path.
getAttributesForPath
(Repository
the repository
db
,
String
the path to find attributes for
path
,
RevCommit
the commit to inspect.
commit
)

Get attributes for given path and commit

public LfsFactory.LfsInstallCommand

Returns:

a command to install LFS support.
getInstallCommand
()

Retrieve an LfsInstallCommand which can be used to enable LFS support (if available) either per repository or for the user.

public static LfsFactory

Returns:

the current LFS implementation
getInstance
()

Get the LFS factory instance

public PrePushHook

Returns:

a PrePushHook implementation or null
getPrePushHook
(Repository
the Repository the hook is applied to.
repo
,
PrintStream
output stream
outputStream
)

Retrieve a pre-push hook to be applied using the default error stream.

public PrePushHook

Returns:

a PrePushHook implementation or null
getPrePushHook
(Repository
the Repository the hook is applied to.
repo
,
PrintStream
output stream
outputStream
,
PrintStream
error stream
errorStream
)

Retrieve a pre-push hook to be applied.

public boolean

Returns:

whether LFS support is available
isAvailable
()

Whether LFS support is available

public boolean

Returns:

whether LFS is enabled for the given repository locally or globally.
isEnabled
(Repository
the repository to check
db
)

Whether LFS is enabled

public static void
setInstance(LfsFactory
register a LfsFactory instance as the LfsFactory implementation to use.
instance
)

Set the LFS factory instance

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instanceback to summary
private static LfsFactory instance

Constructor Detail

LfsFactoryback to summary
protected LfsFactory()

Constructor

Method Detail

applyCleanFilterback to summary
public LfsFactory.LfsInputStream applyCleanFilter(Repository db, InputStream input, long length, Attribute attribute) throws IOException

Apply clean filtering to the given stream, writing the file content to the LFS storage if required and returning a stream to the LFS pointer instead.

Parameters
db:Repository

the repository

input:InputStream

the original input

length:long

the expected input stream length

attribute:Attribute

the attribute used to check for LFS enablement (i.e. "merge", "diff", "filter" from .gitattributes).

Returns:LfsFactory.LfsInputStream

a stream to the content that should be written to the object store along with the expected length of the stream. the original stream is not applicable.

Exceptions
IOException:
in case of an error
applySmudgeFilterback to summary
public ObjectLoader applySmudgeFilter(Repository db, ObjectLoader loader, Attribute attribute) throws IOException

Apply smudge filtering to a given loader, potentially redirecting it to a LFS blob which is downloaded on demand.

Parameters
db:Repository

the repository

loader:ObjectLoader

the loader for the blob

attribute:Attribute

the attribute used to check for LFS enablement (i.e. "merge", "diff", "filter" from .gitattributes).

Returns:ObjectLoader

a loader for the actual data of a blob, or the original loader in case LFS is not applicable.

Exceptions
IOException:
if an IO error occurred
getAttributesForPathback to summary
public static Attributes getAttributesForPath(Repository db, String path) throws IOException

Get git attributes for given path

Parameters
db:Repository

the repository

path:String

the path to find attributes for

Returns:Attributes

the Attributes for the given path.

Exceptions
IOException:
in case of an error
getAttributesForPathback to summary
public static Attributes getAttributesForPath(Repository db, String path, RevCommit commit) throws IOException

Get attributes for given path and commit

Parameters
db:Repository

the repository

path:String

the path to find attributes for

commit:RevCommit

the commit to inspect.

Returns:Attributes

the Attributes for the given path.

Exceptions
IOException:
in case of an error
getInstallCommandback to summary
public LfsFactory.LfsInstallCommand getInstallCommand()

Retrieve an LfsInstallCommand which can be used to enable LFS support (if available) either per repository or for the user.

Returns:LfsFactory.LfsInstallCommand

a command to install LFS support.

Annotations
@Nullable
getInstanceback to summary
public static LfsFactory getInstance()

Get the LFS factory instance

Returns:LfsFactory

the current LFS implementation

getPrePushHookback to summary
public PrePushHook getPrePushHook(Repository repo, PrintStream outputStream)

Retrieve a pre-push hook to be applied using the default error stream.

Parameters
repo:Repository

the Repository the hook is applied to.

outputStream:PrintStream

output stream

Returns:PrePushHook

a PrePushHook implementation or null

Annotations
@Nullable
getPrePushHookback to summary
public PrePushHook getPrePushHook(Repository repo, PrintStream outputStream, PrintStream errorStream)

Retrieve a pre-push hook to be applied.

Parameters
repo:Repository

the Repository the hook is applied to.

outputStream:PrintStream

output stream

errorStream:PrintStream

error stream

Returns:PrePushHook

a PrePushHook implementation or null

Annotations
@Nullable
Since
5.6
isAvailableback to summary
public boolean isAvailable()

Whether LFS support is available

Returns:boolean

whether LFS support is available

isEnabledback to summary
public boolean isEnabled(Repository db)

Whether LFS is enabled

Parameters
db:Repository

the repository to check

Returns:boolean

whether LFS is enabled for the given repository locally or globally.

setInstanceback to summary
public static void setInstance(LfsFactory instance)

Set the LFS factory instance

Parameters
instance:LfsFactory

register a LfsFactory instance as the LfsFactory implementation to use.

org.eclipse.jgit.util back to summary

public final Class LfsFactory.LfsInputStream

extends InputStream
Class Inheritance

Encapsulate a potentially exchanged InputStream along with the expected stream content length.

Field Summary

Modifier and TypeField and Description
private long
length

The expected stream content length.

private InputStream
stream

The actual stream.

Constructor Summary

AccessConstructor and Description
public
LfsInputStream(InputStream
the stream to wrap. the stream will be closed on close().
stream
,
long
the expected length of the stream
length
)

Create a new wrapper around a certain stream

public
LfsInputStream(TemporaryBuffer
the buffer to initialize stream and length from. The buffer will be destroyed on close()
buffer
)

Create a new wrapper around a temporary buffer.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

public long

Returns:

the length of the stream
getLength
()

Get stream length

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

lengthback to summary
private long length

The expected stream content length.

streamback to summary
private InputStream stream

The actual stream.

Constructor Detail

LfsInputStreamback to summary
public LfsInputStream(InputStream stream, long length)

Create a new wrapper around a certain stream

Parameters
stream:InputStream

the stream to wrap. the stream will be closed on close().

length:long

the expected length of the stream

LfsInputStreamback to summary
public LfsInputStream(TemporaryBuffer buffer) throws IOException

Create a new wrapper around a temporary buffer.

Parameters
buffer:TemporaryBuffer

the buffer to initialize stream and length from. The buffer will be destroyed on close()

Exceptions
IOException:
in case of an error opening the stream to the buffer.

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getLengthback to summary
public long getLength()

Get stream length

Returns:long

the length of the stream

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
org.eclipse.jgit.util back to summary

public Interface LfsFactory.LfsInstallCommand

extends Callable<Void>

A command to enable LFS. Optionally set a Repository to enable locally on the repository only.

Method Summary

Modifier and TypeMethod and Description
public LfsFactory.LfsInstallCommand

Returns:

The LfsInstallCommand for chaining.
setRepository
(Repository
the repository to enable support for.
repo
)

Set the repository to enable LFS for

Inherited from java.util.concurrent.Callable:
call

Method Detail

setRepositoryback to summary
public LfsFactory.LfsInstallCommand setRepository(Repository repo)

Set the repository to enable LFS for

Parameters
repo:Repository

the repository to enable support for.

Returns:LfsFactory.LfsInstallCommand

The LfsInstallCommand for chaining.