Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schuberth2015-05-22 15:21:27 +0000
committerMatthias Sohn2015-05-25 19:23:21 +0000
commit7ce6abe8584b228c408a733bfca77e9c2f176e00 (patch)
tree890888be453894ecffa50cf198704c889fa782e0
parent9599f3f1a6111a12b07a8a51755d3ca2452d53d3 (diff)
downloadjgit-7ce6abe8584b228c408a733bfca77e9c2f176e00.tar.gz
jgit-7ce6abe8584b228c408a733bfca77e9c2f176e00.tar.xz
jgit-7ce6abe8584b228c408a733bfca77e9c2f176e00.zip
FS: Allow to manually set the path to the Git system config file
Now that d7a4473 removed the gitprefix property, we did not have a way to specify the path to the Git system config file in case discoverGitSystemConfig() fails. Fix that by introducing a member variable that caches the result of discoverGitSystemConfig() as well as a setter method to overwrite the content of that variable. Change-Id: Icd965bffbe2f11b18c9505ee2ddd2afad5b64d70 Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java28
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java2
2 files changed, 29 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
index 557aa8e03e..a46dc33cdb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
@@ -157,6 +157,8 @@ public abstract class FS {
private volatile Holder<File> userHome;
+ private volatile Holder<File> gitSystemConfig;
+
/**
* Constructs a file system abstraction.
*/
@@ -172,6 +174,7 @@ public abstract class FS {
*/
protected FS(FS src) {
userHome = src.userHome;
+ gitSystemConfig = src.gitSystemConfig;
}
/** @return a new instance of the same type of FS. */
@@ -548,6 +551,31 @@ public abstract class FS {
}
/**
+ * @return the currently used path to the system-wide Git configuration
+ * file or {@code null} if none has been set.
+ * @since 4.0
+ */
+ public File getGitSystemConfig() {
+ if (gitSystemConfig == null) {
+ gitSystemConfig = new Holder<File>(discoverGitSystemConfig());
+ }
+ return gitSystemConfig.value;
+ }
+
+ /**
+ * Set the path to the system-wide Git configuration file to use.
+ *
+ * @param configFile
+ * the path to the config file.
+ * @return {@code this}
+ * @since 4.0
+ */
+ public FS setGitSystemConfig(File configFile) {
+ gitSystemConfig = new Holder<File>(configFile);
+ return this;
+ }
+
+ /**
* @param grandchild
* @return the parent directory of this file's parent directory or
* {@code null} in case there's no grandparent directory
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
index 04a7051a72..b4233b6ccd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
@@ -89,7 +89,7 @@ public abstract class SystemReader {
}
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
- File configFile = fs.discoverGitSystemConfig();
+ File configFile = fs.getGitSystemConfig();
if (configFile == null) {
return new FileBasedConfig(null, fs) {
public void load() {

Back to the top