From 8b8999dca8d71b976da94715e06162510bb51460 Mon Sep 17 00:00:00 2001 From: Matthias Fromme Date: Mon, 4 Apr 2022 06:45:22 +0200 Subject: Lazy loading of .lfsconfig. Load the '.lfsconfig ' on access instead of trying to load it unconditionally each time an LFS filter is applied. Bug 578020 Change-Id: I986d4e61a736fc83cf00e62a08d8413c6bb53f78 --- .../org/eclipse/jgit/lfs/internal/LfsConfig.java | 62 ++++++++++++++-------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'org.eclipse.jgit.lfs') diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java index 71d395ca84..857ccbe056 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java @@ -30,21 +30,26 @@ import org.eclipse.jgit.treewalk.TreeWalk; import static org.eclipse.jgit.lib.Constants.HEAD; /** - * Encapsulate access to the .lfsconfig. + * Encapsulate access to the {@code .lfsconfig}. + *

+ * According to the git lfs documentation the order to find the + * {@code .lfsconfig} file is: + *

+ *
    + *
  1. in the root of the working tree
  2. + *
  3. in the index
  4. + *
  5. in the HEAD; for bare repositories this is the only place that is + * searched
  6. + *
+ *

+ * Values from the {@code .lfsconfig} are used only if not specified in another + * git config file to allow local override without modifiction of a committed + * file. + *

* - * According to the document - * https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-config.5.ronn - * the order to find the .lfsconfig file is: - * - *
- *   1. in the root of the working tree
- *   2. in the index
- *   3. in the HEAD, for bare repositories this is the only place
- *      that is searched
- * 
- * - * Values from the .lfsconfig are used only if not specified in another git - * config file to allow local override without modifiction of a committed file. + * @see Configuration + * options for git-lfs */ public class LfsConfig { private Repository db; @@ -55,17 +60,30 @@ public class LfsConfig { * * @param db * the associated repo - * @throws IOException */ - public LfsConfig(Repository db) throws IOException { + public LfsConfig(Repository db) { this.db = db; - delegate = this.load(); + } + + /** + * Getter for the delegate to allow lazy initialization. + * + * @return the delegate {@link Config} + * @throws IOException + */ + private Config getDelegate() throws IOException { + if (delegate == null) { + delegate = this.load(); + } + return delegate; } /** * Read the .lfsconfig file from the repository * - * @return The loaded lfs config or null if it does not exist + * An empty config is returned be empty if no lfs config exists. + * + * @return The loaded lfs config * * @throws IOException */ @@ -102,7 +120,7 @@ public class LfsConfig { throws IOException { File lfsConfig = db.getFS().resolve(db.getWorkTree(), Constants.DOT_LFS_CONFIG); - if (lfsConfig.exists() && lfsConfig.isFile()) { + if (lfsConfig.isFile()) { FileBasedConfig config = new FileBasedConfig(lfsConfig, db.getFS()); try { config.load(); @@ -188,12 +206,14 @@ public class LfsConfig { * @param name * the key name * @return a String value from the config, null if not found + * @throws IOException */ + @Nullable public String getString(final String section, final String subsection, - final String name) { + final String name) throws IOException { String result = db.getConfig().getString(section, subsection, name); if (result == null) { - result = delegate.getString(section, subsection, name); + result = getDelegate().getString(section, subsection, name); } return result; } -- cgit v1.2.3