--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jgit" version="2">
+ <resource path="src/org/eclipse/jgit/lib/TypedConfigGetter.java" type="org.eclipse.jgit.lib.TypedConfigGetter">
+ <filter id="404000815">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.lib.TypedConfigGetter"/>
+ <message_argument value="getPath(Config, String, String, String, FS, File, Path)"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
import static java.nio.charset.StandardCharsets.UTF_8;
+import java.io.File;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.events.ConfigChangedEvent;
import org.eclipse.jgit.events.ConfigChangedListener;
import org.eclipse.jgit.events.ListenerList;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.RawParseUtils;
/**
defaultValue, wantUnit);
}
+ /**
+ * Parse a string value and treat it as a file path, replacing a ~/ prefix
+ * by the user's home directory.
+ * <p>
+ * <b>Note:</b> this may throw {@link InvalidPathException} if the string is
+ * not a valid path.
+ * </p>
+ *
+ * @param section
+ * section the key is in.
+ * @param subsection
+ * subsection the key is in, or null if not in a subsection.
+ * @param name
+ * the key name.
+ * @param fs
+ * to use to convert the string into a path.
+ * @param resolveAgainst
+ * directory to resolve the path against if it is a relative
+ * path; {@code null} to use the Java process's current
+ * directory.
+ * @param defaultValue
+ * to return if no value was present
+ * @return the {@link Path}, or {@code defaultValue} if not set
+ * @since 5.10
+ */
+ public Path getPath(String section, String subsection, String name,
+ @NonNull FS fs, File resolveAgainst, Path defaultValue) {
+ return typedGetter.getPath(this, section, subsection, name, fs,
+ resolveAgainst, defaultValue);
+ }
+
/**
* Parse a list of {@link org.eclipse.jgit.transport.RefSpec}s from the
* configuration.
/*
- * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch> and others
+ * Copyright (C) 2017, 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
package org.eclipse.jgit.lib;
+import java.io.File;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.util.FS;
/**
- * Something that knows how to convert plain strings from a git
- * {@link org.eclipse.jgit.lib.Config} to typed values.
+ * Something that knows how to convert plain strings from a git {@link Config}
+ * to typed values.
*
* @since 4.9
*/
public interface TypedConfigGetter {
/**
- * Get a boolean value from a git {@link org.eclipse.jgit.lib.Config}.
+ * Get a boolean value from a git {@link Config}.
*
* @param config
* to get the value from
String name, boolean defaultValue);
/**
- * Parse an enumeration from a git {@link org.eclipse.jgit.lib.Config}.
+ * Parse an enumeration from a git {@link Config}.
*
* @param config
* to get the value from
String subsection, String name, T defaultValue);
/**
- * Obtain an integer value from a git {@link org.eclipse.jgit.lib.Config}.
+ * Obtain an integer value from a git {@link Config}.
*
* @param config
* to get the value from
int defaultValue);
/**
- * Obtain a long value from a git {@link org.eclipse.jgit.lib.Config}.
+ * Obtain a long value from a git {@link Config}.
*
* @param config
* to get the value from
/**
* Parse a numerical time unit, such as "1 minute", from a git
- * {@link org.eclipse.jgit.lib.Config}.
+ * {@link Config}.
*
* @param config
* to get the value from
long getTimeUnit(Config config, String section, String subsection,
String name, long defaultValue, TimeUnit wantUnit);
+ /**
+ * Parse a string value from a git {@link Config} and treat it as a file
+ * path, replacing a ~/ prefix by the user's home directory.
+ * <p>
+ * <b>Note:</b> this may throw {@link InvalidPathException} if the string is
+ * not a valid path.
+ * </p>
+ *
+ * @param config
+ * to get the path from.
+ * @param section
+ * section the key is in.
+ * @param subsection
+ * subsection the key is in, or null if not in a subsection.
+ * @param name
+ * the key name.
+ * @param fs
+ * to use to convert the string into a path.
+ * @param resolveAgainst
+ * directory to resolve the path against if it is a relative
+ * path.
+ * @param defaultValue
+ * to return if no value was present
+ * @return the {@link Path}, or {@code defaultValue} if not set
+ * @since 5.10
+ */
+ default Path getPath(Config config, String section, String subsection,
+ String name, @NonNull FS fs, File resolveAgainst,
+ Path defaultValue) {
+ String value = config.getString(section, subsection, name);
+ if (value == null) {
+ return defaultValue;
+ }
+ File file;
+ if (value.startsWith("~/")) { //$NON-NLS-1$
+ file = fs.resolve(fs.userHome(), value.substring(2));
+ } else {
+ file = fs.resolve(resolveAgainst, value);
+ }
+ return file.toPath();
+ }
/**
- * Parse a list of {@link org.eclipse.jgit.transport.RefSpec}s from a git
- * {@link org.eclipse.jgit.lib.Config}.
+ * Parse a list of {@link RefSpec}s from a git {@link Config}.
*
* @param config
* to get the list from
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetEncoder;
+import java.nio.file.Path;
import java.text.MessageFormat;
import java.time.Instant;
import java.util.Arrays;
import org.eclipse.jgit.ignore.FastIgnoreRule;
import org.eclipse.jgit.ignore.IgnoreNode;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.CoreConfig;
import org.eclipse.jgit.lib.CoreConfig.CheckStat;
import org.eclipse.jgit.lib.CoreConfig.EolStreamType;
import org.eclipse.jgit.lib.CoreConfig.SymLinks;
}
FS fs = repository.getFS();
- String path = repository.getConfig().get(CoreConfig.KEY)
- .getExcludesFile();
+ Path path = repository.getConfig().getPath(
+ ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_EXCLUDESFILE, fs, null, null);
if (path != null) {
- File excludesfile;
- if (path.startsWith("~/")) //$NON-NLS-1$
- excludesfile = fs.resolve(fs.userHome(), path.substring(2));
- else
- excludesfile = fs.resolve(null, path);
- loadRulesFromFile(r, excludesfile);
+ loadRulesFromFile(r, path.toFile());
}
File exclude = fs.resolve(repository.getDirectory(),