aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-03-14 09:07:53 -0700
committerShawn O. Pearce <spearce@spearce.org>2011-03-14 09:07:53 -0700
commit5f82569cab3386306bca546b87d3919723449c90 (patch)
treefffe9a55852ab99c6f55c8ccf475d235ea3e8cbb /org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
parent2f705ad240ba7731a105f9b438240fa7cd3c52a1 (diff)
downloadjgit-5f82569cab3386306bca546b87d3919723449c90.tar.gz
jgit-5f82569cab3386306bca546b87d3919723449c90.zip
FS: Allow gitPrefix to be set and cached
This permits callers to modify the meaning of gitPrefix, which may be useful if their application allows the user to select the location where C Git is installed. Bug: 337101 Change-Id: I07362a5772da4955e01406bdeb8eaf87416be1d6 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java34
1 files changed, 33 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 857b980a33..51b5a45ac2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
@@ -101,6 +101,8 @@ public abstract class FS {
private final File userHome;
+ private volatile Holder<File> gitPrefix;
+
/**
* Constructs a file system abstraction.
*/
@@ -258,7 +260,29 @@ public abstract class FS {
}
/** @return the $prefix directory C Git would use. */
- public abstract File gitPrefix();
+ public File gitPrefix() {
+ Holder<File> p = gitPrefix;
+ if (p == null) {
+ p = new Holder<File>(discoverGitPrefix());
+ gitPrefix = p;
+ }
+ return p.value;
+ }
+
+ /** @return the $prefix directory C Git would use. */
+ protected abstract File discoverGitPrefix();
+
+ /**
+ * Set the $prefix directory C Git uses.
+ *
+ * @param path
+ * the directory. Null if C Git is not installed.
+ * @return {@code this}
+ */
+ public FS setGitPrefix(File path) {
+ gitPrefix = new Holder<File>(path);
+ return this;
+ }
/**
* Initialize a ProcesssBuilder to run a command using the system shell.
@@ -273,4 +297,12 @@ public abstract class FS {
* populating directory, environment, and then start the process.
*/
public abstract ProcessBuilder runInShell(String cmd, String[] args);
+
+ private static class Holder<V> {
+ final V value;
+
+ Holder(V value) {
+ this.value = value;
+ }
+ }
}