LFS: Adjust some API to make integration into tools (EGit,...) easier

Make the install command accessible without requiring reflection.

Expose the isEnabled(Repository) API to be able to check if calling the
install command is required for a repository.

Change-Id: I17e6eaefb6afda17fea8162cbf0cb86a20506753
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Markus Duft 2018-03-05 10:34:29 +01:00 committed by Matthias Sohn
parent 9f689e90d4
commit 0f9ec9e406
3 changed files with 45 additions and 4 deletions

View File

@ -112,7 +112,8 @@ public LfsInputStream applyCleanFilter(Repository db, InputStream input,
* the repository
* @return whether LFS is requested for the given repo.
*/
private boolean isEnabled(Repository db) {
@Override
public boolean isEnabled(Repository db) {
if (db == null) {
return false;
}
@ -138,4 +139,9 @@ private boolean isEnabled(Repository db, Attribute attribute) {
.equals(attribute.getValue());
}
@Override
public LfsInstallCommand getInstallCommand() {
return new InstallBuiltinLfsCommand();
}
}

View File

@ -44,7 +44,6 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.util.concurrent.Callable;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lfs.internal.LfsText;
@ -53,6 +52,7 @@
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.LfsFactory.LfsInstallCommand;
import org.eclipse.jgit.util.SystemReader;
/**
@ -61,7 +61,7 @@
*
* @since 4.11
*/
public class InstallLfsCommand implements Callable<Void>{
public class InstallBuiltinLfsCommand implements LfsInstallCommand {
private static final String[] ARGS_USER = new String[] { "lfs", "install" }; //$NON-NLS-1$//$NON-NLS-2$
@ -110,7 +110,8 @@ public Void call() throws Exception {
* configuration
* @return this command
*/
public InstallLfsCommand setRepository(Repository repo) {
@Override
public LfsInstallCommand setRepository(Repository repo) {
this.repository = repo;
return this;
}

View File

@ -46,6 +46,7 @@
import java.io.InputStream;
import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.concurrent.Callable;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.attributes.Attribute;
@ -156,6 +157,26 @@ public ObjectLoader applySmudgeFilter(Repository db,
return null;
}
/**
* Retrieve an {@link LfsInstallCommand} which can be used to enable LFS
* support (if available) either per repository or for the user.
*
* @return a command to install LFS support.
*/
public @Nullable LfsInstallCommand getInstallCommand() {
return null;
}
/**
* @param db
* the repository to check
* @return whether LFS is enabled for the given repository locally or
* globally.
*/
public boolean isEnabled(Repository db) {
return false;
}
/**
* @param db
* the repository
@ -281,4 +302,17 @@ public long getLength() {
}
}
/**
* A command to enable LFS. Optionally set a {@link Repository} to enable
* locally on the repository only.
*/
public interface LfsInstallCommand extends Callable<Void> {
/**
* @param repo
* the repository to enable support for.
* @return The {@link LfsInstallCommand} for chaining.
*/
public LfsInstallCommand setRepository(Repository repo);
}
}