Top Description Inners Fields Constructors Methods
org.eclipse.jgit.lib

public Class Config

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.lib.StoredConfig, org.eclipse.jgit.lib.BlobBasedConfig
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Git style .config, .gitconfig, .gitmodules file.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Config.ConfigEnum

Converts enumeration values into configuration options and vice-versa, allowing to match a config option with an enum value.

public static interface
Config.SectionParser<
type of the application model created by the parser.
T
>

Parses a section of the configuration into an application model object.

private static class

Field Summary

Modifier and TypeField and Description
private final Config
private static final TypedConfigGetter
private static final String[]
private final ListenerList
listeners

the change listeners

private static final int
private static final String
MISSING_ENTRY

Magic value indicating a missing entry.

private final AtomicReference<ConfigSnapshot>
state

Immutable current state of the configuration data.

private static TypedConfigGetter

Constructor Summary

AccessConstructor and Description
public
Config()

Create a configuration with no default fallback.

public
Config(Config
the base configuration to be consulted when a key is missing from this configuration instance.
defaultConfig
)

Create an empty configuration with a fallback for missing keys.

Method Summary

Modifier and TypeMethod and Description
public ListenerHandle

Returns:

the handle to the registered listener
addChangeListener
(ConfigChangedListener
the listener
listener
)

Adds a listener to be notified about changes.

private void
addIncludedConfig(final List<ConfigLine> newEntries, ConfigLine line, int depth)

private static <T> T[]
allValuesOf(T value)

protected void
clear()

Clear the configuration file

private static List<ConfigLine>
copy(final ConfigSnapshot src, final List<String> values)

pack-priv static String
pack-priv static String

Returns:

the escaped value
escapeValue
(String
the value to escape
x
)

Escape the value before saving

private static int
findSectionEnd(final List<ConfigLine> entries, final String section, final String subsection, boolean skipIncludedLines)

protected void
fireConfigChangedEvent()

Notifies the listeners

public void
fromText(String
Git style text file listing configuration properties.
text
)

Clear this configuration and reset to the contents of the parsed string.

private List<ConfigLine>
fromTextRecurse(String text, int depth, String includedFrom)

public <
type of configuration model to return.
T
>
T

Returns:

the parsed object instance, which is cached inside this config.
get
(Config.SectionParser<T>
parser which can create the model if it is not already available in this configuration file. The parser is also used as the key into a cache and must obey the hashCode and equals contract in order to reuse a parsed model.
parser
)

Obtain a handle to a parsed set of configuration values.

public Config

Returns:

the base configuration of this config.
getBaseConfig
()

Retrieves this config's base config.

private ConfigSnapshot
public boolean

Returns:

true if any value or defaultValue is true, false for missing or explicit false
getBoolean
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
,
boolean
default value to return if no value was present.
defaultValue
)

Get a boolean value from the git config

public Boolean

Returns:

configured boolean value, or null if not set.
getBoolean
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
)

Get a boolean value from the git config

public boolean

Returns:

true if any value or defaultValue is true, false for missing or explicit false
getBoolean
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
boolean
default value to return if no value was present.
defaultValue
)

Get a boolean value from the git config

public Boolean

Returns:

configured boolean value, or null if not set.
getBoolean
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
)

Get a boolean value from the git config

public <
type of the returned enum
T extends Enum<?>
>
T

Returns:

the selected enumeration value, or defaultValue.
getEnum
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
T
default value to return if no value was present.
defaultValue
)

Parse an enumeration from the configuration.

public <
type of the returned enum
T extends Enum<?>
>
T

Returns:

the selected enumeration value, or defaultValue.
getEnum
(T[]
all possible values in the enumeration which should be recognized. Typically EnumType.values().
all
,
String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
T
default value to return if no value was present.
defaultValue
)

Parse an enumeration from the configuration.

public <
type of the returned enum
T extends Enum<?>
>
T

Returns:

the selected enumeration value, or null if not set.
getEnum
(T[]
all possible values in the enumeration which should be recognized. Typically EnumType.values().
all
,
String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
)

Parse an enumeration from the configuration.

public int

Returns:

an integer value from the configuration, or defaultValue.
getInt
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
,
int
default value to return if no value was present.
defaultValue
)

Obtain an integer value from the configuration.

public Integer

Returns:

an integer value from the configuration, or null if not set.
getInt
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
)

Obtain an integer value from the configuration.

public int

Returns:

an integer value from the configuration, or defaultValue.
getInt
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
int
default value to return if no value was present.
defaultValue
)

Obtain an integer value from the configuration.

public Integer

Returns:

an integer value from the configuration, or null if not set.
getInt
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
)

Obtain an integer value from the configuration.

public int

Returns:

an integer value from the configuration, or defaultValue.
getIntInRange
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
,
int
minimum value
minValue
,
int
maximum value
maxValue
,
int
default value to return if no value was present.
defaultValue
)

Obtain an integer value from the configuration which must be inside given range.

public Integer

Returns:

an integer value from the configuration, or null if not set.
getIntInRange
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
,
int
minimum value
minValue
,
int
maximum value
maxValue
)

Obtain an integer value from the configuration which must be inside given range.

public int

Returns:

an integer value from the configuration, or defaultValue.
getIntInRange
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
int
minimum value
minValue
,
int
maximum value
maxValue
,
int
default value to return if no value was present.
defaultValue
)

Obtain an integer value from the configuration which must be inside given range.

public Integer

Returns:

an integer value from the configuration, or null if not set.
getIntInRange
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
int
minimum value
minValue
,
int
maximum value
maxValue
)

Obtain an integer value from the configuration which must be inside given range.

public long

Returns:

an integer value from the configuration, or defaultValue.
getLong
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
,
long
default value to return if no value was present.
defaultValue
)

Obtain an integer value from the configuration.

public Long

Returns:

an integer value from the configuration, or null if not set.
getLong
(String
section the key is grouped within.
section
,
String
name of the key to get.
name
)

Obtain an integer value from the configuration.

public long

Returns:

an integer value from the configuration, or defaultValue.
getLong
(final String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
,
long
default value to return if no value was present.
defaultValue
)

Obtain an integer value from the configuration.

public Long

Returns:

an integer value from the configuration, or null if not set.
getLong
(String
section the key is grouped within.
section
,
String
subsection name, such a remote or branch name.
subsection
,
String
name of the key to get.
name
)

Obtain an integer value from the configuration.

public Set<String>

Returns:

the list of names defined for this section
getNames
(String
the section
section
)

Get the list of names defined for this section

public Set<String>

Returns:

the list of names defined for this subsection
getNames
(String
the section
section
,
String
the subsection
subsection
)

Get the list of names defined for this subsection

public Set<String>

Returns:

the list of names defined for this section
getNames
(String
the section
section
,
boolean
if true recursively adds the names defined in all base configurations
recursive
)

Get the list of names defined for this section

public Set<String>

Returns:

the list of names defined for this subsection
getNames
(String
the section
section
,
String
the subsection
subsection
,
boolean
if true recursively adds the names defined in all base configurations
recursive
)

Get the list of names defined for this section

public Path

Returns:

the Path, or defaultValue if not set
getPath
(String
section the key is in.
section
,
String
subsection the key is in, or null if not in a subsection.
subsection
,
String
the key name.
name
,
FS
to use to convert the string into a path.
fs
,
File
directory to resolve the path against if it is a relative path; null to use the Java process's current directory.
resolveAgainst
,
Path
to return if no value was present
defaultValue
)

Parse a string value and treat it as a file path, replacing a ~/ prefix by the user's home directory.

private String
getRawString(final String section, final String subsection, final String name)

private String[]
getRawStringList(String section, String subsection, String name)

public List<RefSpec>

Returns:

a possibly empty list of org.eclipse.jgit.transport.RefSpecs
getRefSpecs
(String
section the key is in.
section
,
String
subsection the key is in, or null if not in a subsection.
subsection
,
String
the key name.
name
)

Parse a list of org.eclipse.jgit.transport.RefSpecs from the configuration.

public Set<String>

Returns:

the sections defined in this org.eclipse.jgit.lib.Config. The set's iterator returns sections in the order they are declared by the configuration starting from this instance and progressing through the base.
getSections
()

Get the sections defined in this org.eclipse.jgit.lib.Config.

private ConfigSnapshot
public String

Returns:

a String value from the config, null if not found
getString
(String
the section
section
,
String
the subsection for the value
subsection
,
String
the key name
name
)

Get string value or null if not found.

public String[]

Returns:

array of zero or more values from the configuration.
getStringList
(final String
the section
section
,
String
the subsection for the value
subsection
,
final String
the key name
name
)

Get a list of string values

If this instance was created with a base, the base's values are returned first (if any).

public Set<String>

Returns:

set of all subsections of specified section within this configuration and its base configuration; may be empty if no subsection exists. The set's iterator returns sections in the order they are declared by the configuration starting from this instance and progressing through the base.
getSubsections
(String
section to search for.
section
)

Get set of all subsections of specified section within this configuration and its base configuration

public long

Returns:

the value, or defaultValue if not set, expressed in units.
getTimeUnit
(String
section the key is in.
section
,
String
subsection the key is in, or null if not in a subsection.
subsection
,
String
the key name.
name
,
long
default value to return if no value was present.
defaultValue
,
TimeUnit
the units of defaultValue and the return value, as well as the units to assume if the value does not contain an indication of the units.
wantUnit
)

Parse a numerical time unit, such as "1 minute", from the configuration.

public Long

Returns:

the value, or null if not set, expressed in units.
getTimeUnit
(String
section the key is in.
section
,
String
subsection the key is in, or null if not in a subsection.
subsection
,
String
the key name.
name
,
TimeUnit
the units of defaultValue and the return value, as well as the units to assume if the value does not contain an indication of the units.
wantUnit
)

Parse a numerical time unit, such as "1 minute", from the configuration.

public static boolean

Returns:

true if the given string is the "missing" value.
isMissing
(String
string to be checked.
value
)

Check if a given string is the "missing" value.

protected boolean

Returns:

true if bytes should be treated as UTF-8, false otherwise.
isUtf8
(final byte[]
the bytes to check encoding for.
bytes
)

Check if bytes should be treated as UTF-8 or not.

private ConfigSnapshot
private ConfigSnapshot
protected boolean

Returns:

whether to issue change events for transient changes
notifyUponTransientChanges
()

Determine whether to issue change events for transient changes.

protected byte[]

Returns:

the read bytes, or null if the included config should be ignored
readIncludedConfig
(String
possibly relative path to the included config, as specified in this config
relPath
)

Read the included config from the specified (possibly) relative path

private static String
private static String
private static String
private static String
public boolean

Returns:

true if a section was present and was removed; false if the config was not changed (i.e., no such section was present)
removeSection
(String
section name, e.g "branch"
section
,
String
optional subsection value, e.g. a branch name
subsection
)

Removes all configuration values under a single section.

private ConfigSnapshot
replaceStringList(final ConfigSnapshot srcState, final String section, final String subsection, final String name, final List<String> values)

public void
setBoolean(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
,
final boolean
parameter value
value
)

Add or modify a configuration value.

public <
type of the enum to set
T extends Enum<?>
>
void
setEnum(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
,
final T
parameter value
value
)

Add or modify a configuration value.

public void
setInt(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
,
final int
parameter value
value
)

Add or modify a configuration value.

public void
setLong(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
,
final long
parameter value
value
)

Add or modify a configuration value.

public void
setString(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
,
final String
parameter value, e.g. "true"
value
)

Add or modify a configuration value.

public void
setStringList(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
,
final List<String>
list of zero or more values for this key.
values
)

Set a configuration value.

public static void
setTypedConfigGetter(TypedConfigGetter
to use; if null use the default getter.
getter
)

Globally sets a org.eclipse.jgit.lib.TypedConfigGetter that is subsequently used to read typed values from all git configs.

public String

Returns:

this configuration, formatted as a Git style text file.
toText
()

Get this configuration, formatted as a Git style text file.

private static String
public void
uncache(Config.SectionParser<?>
parser used to obtain the configuration object.
parser
)

Remove a cached configuration object.

public void
unset(final String
section name, e.g "branch"
section
,
final String
optional subsection value, e.g. a branch name
subsection
,
final String
parameter name, e.g. "filemode"
name
)

Remove a configuration value.

public void
unsetSection(String
section name, e.g "branch"
section
,
String
optional subsection value, e.g. a branch name
subsection
)

Remove all configuration values under a single section.

private ConfigSnapshot
unsetSection(ConfigSnapshot srcState, String section, String subsection, AtomicBoolean changed)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait