aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Strapetz2011-03-10 07:17:57 (EST)
committerMarc Strapetz2011-03-10 07:17:57 (EST)
commit6f066dec02052876493b4ca9f20b7bfa941b14ce (patch)
tree7c391a09dfbe2f80e233a060985ca5744a6d7259
parentff6ac0aaef3a5605e6913c3d87da665ff3878226 (diff)
downloadjgit-6f066dec02052876493b4ca9f20b7bfa941b14ce.zip
jgit-6f066dec02052876493b4ca9f20b7bfa941b14ce.tar.gz
jgit-6f066dec02052876493b4ca9f20b7bfa941b14ce.tar.bz2
Cache gitPrefix in FS_Win32refs/changes/87/2687/1
readPipe() may consume rather much time, so gitPrefix should be cached. If the git executable changes, users should run FS.detect() again to get a new instance of FS_Win32.
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java30
1 files changed, 19 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
index 0e05de0..bde633c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
@@ -64,6 +64,9 @@ class FS_Win32 extends FS {
&& StringUtils.toLowerCase(osDotName).indexOf("windows") != -1;
}
+ private File gitPrefix;
+ private boolean gitPrefixEvaluated;
+
public boolean supportsExecute() {
return false;
}
@@ -83,21 +86,26 @@ class FS_Win32 extends FS {
@Override
public File gitPrefix() {
+ if (gitPrefixEvaluated)
+ return gitPrefix;
+
String path = SystemReader.getInstance().getenv("PATH");
File gitExe = searchPath(path, "git.exe", "git.cmd");
if (gitExe != null)
- return gitExe.getParentFile().getParentFile();
-
- // This isn't likely to work, if bash is in $PATH, git should
- // also be in $PATH. But its worth trying.
- //
- String w = readPipe(userHome(), //
- new String[] { "bash", "--login", "-c", "which git" }, //
- Charset.defaultCharset().name());
- if (w != null)
- return new File(w).getParentFile().getParentFile();
+ gitPrefix = gitExe.getParentFile().getParentFile();
+ else {
+ // This isn't likely to work, if bash is in $PATH, git should
+ // also be in $PATH. But its worth trying.
+ //
+ String w = readPipe(userHome(), //
+ new String[] { "bash", "--login", "-c", "which git" }, //
+ Charset.defaultCharset().name());
+ if (w != null)
+ gitPrefix = new File(w).getParentFile().getParentFile();
+ }
- return null;
+ gitPrefixEvaluated = true;
+ return gitPrefix;
}
@Override