Cache gitPrefix in FS_Win32
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.
This commit is contained in:
parent
ff6ac0aaef
commit
6f066dec02
|
@ -64,6 +64,9 @@ public String run() {
|
||||||
&& StringUtils.toLowerCase(osDotName).indexOf("windows") != -1;
|
&& StringUtils.toLowerCase(osDotName).indexOf("windows") != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File gitPrefix;
|
||||||
|
private boolean gitPrefixEvaluated;
|
||||||
|
|
||||||
public boolean supportsExecute() {
|
public boolean supportsExecute() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -83,21 +86,26 @@ public boolean retryFailedLockFileCommit() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File gitPrefix() {
|
public File gitPrefix() {
|
||||||
|
if (gitPrefixEvaluated)
|
||||||
|
return gitPrefix;
|
||||||
|
|
||||||
String path = SystemReader.getInstance().getenv("PATH");
|
String path = SystemReader.getInstance().getenv("PATH");
|
||||||
File gitExe = searchPath(path, "git.exe", "git.cmd");
|
File gitExe = searchPath(path, "git.exe", "git.cmd");
|
||||||
if (gitExe != null)
|
if (gitExe != null)
|
||||||
return gitExe.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();
|
||||||
|
}
|
||||||
|
|
||||||
// This isn't likely to work, if bash is in $PATH, git should
|
gitPrefixEvaluated = true;
|
||||||
// also be in $PATH. But its worth trying.
|
return gitPrefix;
|
||||||
//
|
|
||||||
String w = readPipe(userHome(), //
|
|
||||||
new String[] { "bash", "--login", "-c", "which git" }, //
|
|
||||||
Charset.defaultCharset().name());
|
|
||||||
if (w != null)
|
|
||||||
return new File(w).getParentFile().getParentFile();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue