From 0f9ec9e406b903ab9be6a95e15a282da9a6c5512 Mon Sep 17 00:00:00 2001 From: Markus Duft Date: Mon, 5 Mar 2018 10:34:29 +0100 Subject: [PATCH] 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 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/lfs/BuiltinLFS.java | 8 ++++- ...and.java => InstallBuiltinLfsCommand.java} | 7 ++-- .../src/org/eclipse/jgit/util/LfsFactory.java | 34 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) rename org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/{InstallLfsCommand.java => InstallBuiltinLfsCommand.java} (95%) diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java index d65e4e999..415caa985 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java @@ -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(); + } + } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/InstallLfsCommand.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/InstallBuiltinLfsCommand.java similarity index 95% rename from org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/InstallLfsCommand.java rename to org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/InstallBuiltinLfsCommand.java index b204d0c15..028b19b2a 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/InstallLfsCommand.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/InstallBuiltinLfsCommand.java @@ -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{ +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; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/LfsFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/LfsFactory.java index 920091649..6d60ef3f4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/LfsFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/LfsFactory.java @@ -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 { + /** + * @param repo + * the repository to enable support for. + * @return The {@link LfsInstallCommand} for chaining. + */ + public LfsInstallCommand setRepository(Repository repo); + } + }