Merge branch 'stable-5.12' into stable-5.13
* stable-5.12: Better git system config finding Change-Id: Iebbae08b6bb6ef510ca07329df77223bc2128ec1 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
commit
9e4fe739c7
|
@ -60,6 +60,8 @@
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.jgit.annotations.NonNull;
|
import org.eclipse.jgit.annotations.NonNull;
|
||||||
import org.eclipse.jgit.annotations.Nullable;
|
import org.eclipse.jgit.annotations.Nullable;
|
||||||
|
@ -95,6 +97,9 @@ public abstract class FS {
|
||||||
*/
|
*/
|
||||||
protected static final Entry[] NO_ENTRIES = {};
|
protected static final Entry[] NO_ENTRIES = {};
|
||||||
|
|
||||||
|
private static final Pattern VERSION = Pattern
|
||||||
|
.compile("\\s(\\d+)\\.(\\d+)\\.(\\d+)"); //$NON-NLS-1$
|
||||||
|
|
||||||
private volatile Boolean supportSymlinks;
|
private volatile Boolean supportSymlinks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1517,8 +1522,10 @@ protected File discoverGitSystemConfig() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trick Git into printing the path to the config file by using "echo"
|
if (parseVersion(v) < makeVersion(2, 8, 0)) {
|
||||||
// as the editor.
|
// --show-origin was introduced in git 2.8.0. For older git: trick
|
||||||
|
// it into printing the path to the config file by using "echo" as
|
||||||
|
// the editor.
|
||||||
Map<String, String> env = new HashMap<>();
|
Map<String, String> env = new HashMap<>();
|
||||||
env.put("GIT_EDITOR", "echo"); //$NON-NLS-1$ //$NON-NLS-2$
|
env.put("GIT_EDITOR", "echo"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
@ -1527,7 +1534,8 @@ protected File discoverGitSystemConfig() {
|
||||||
w = readPipe(gitExe.getParentFile(),
|
w = readPipe(gitExe.getParentFile(),
|
||||||
new String[] { gitExe.getPath(), "config", "--system", //$NON-NLS-1$ //$NON-NLS-2$
|
new String[] { gitExe.getPath(), "config", "--system", //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
"--edit" }, //$NON-NLS-1$
|
"--edit" }, //$NON-NLS-1$
|
||||||
Charset.defaultCharset().name(), env);
|
Charset.defaultCharset().name(),
|
||||||
|
env);
|
||||||
} catch (CommandFailedException e) {
|
} catch (CommandFailedException e) {
|
||||||
LOG.warn(e.getMessage());
|
LOG.warn(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
@ -1538,6 +1546,53 @@ protected File discoverGitSystemConfig() {
|
||||||
|
|
||||||
return new File(w);
|
return new File(w);
|
||||||
}
|
}
|
||||||
|
String w;
|
||||||
|
try {
|
||||||
|
w = readPipe(gitExe.getParentFile(),
|
||||||
|
new String[] { gitExe.getPath(), "config", "--system", //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
"--show-origin", "--list", "-z" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
Charset.defaultCharset().name());
|
||||||
|
} catch (CommandFailedException e) {
|
||||||
|
LOG.warn(e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (w == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// We get NUL-terminated items; the first one will be a file name,
|
||||||
|
// prefixed by "file:". (Using -z is crucial, otherwise git quotes file
|
||||||
|
// names with special characters.)
|
||||||
|
int nul = w.indexOf(0);
|
||||||
|
if (nul <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
w = w.substring(0, nul);
|
||||||
|
int colon = w.indexOf(':');
|
||||||
|
if (colon < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
w = w.substring(colon + 1);
|
||||||
|
return w.isEmpty() ? null : new File(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long parseVersion(String version) {
|
||||||
|
Matcher m = VERSION.matcher(version);
|
||||||
|
if (m.find()) {
|
||||||
|
try {
|
||||||
|
return makeVersion(
|
||||||
|
Integer.parseInt(m.group(1)),
|
||||||
|
Integer.parseInt(m.group(2)),
|
||||||
|
Integer.parseInt(m.group(3)));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long makeVersion(int major, int minor, int patch) {
|
||||||
|
return ((major * 10_000L) + minor) * 10_000L + patch;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently used path to the system-wide Git configuration file.
|
* Get the currently used path to the system-wide Git configuration file.
|
||||||
|
|
Loading…
Reference in New Issue