Skip to content

Commit

Permalink
Add setBoolean, setInt to RepositoryConfig
Browse files Browse the repository at this point in the history
This makes it easier for application level code to make edits to the
configuration file, especially when setting boolean or integers into
any property.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
  • Loading branch information
spearce authored and robinrosenberg committed Feb 18, 2009
1 parent dcbb668 commit 0414c67
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
Expand Up @@ -436,6 +436,63 @@ private Object getRawEntry(final String section, final String subsection,
return o;
}

/**
* Add or modify a configuration value. The parameters will result in a
* configuration entry like this.
*
* <pre>
* [section &quot;subsection&quot;]
* name = value
* </pre>
*
* @param section
* section name, e.g "branch"
* @param subsection
* optional subsection value, e.g. a branch name
* @param name
* parameter name, e.g. "filemode"
* @param value
* parameter value
*/
public void setInt(final String section, final String subsection,
final String name, final int value) {
final String s;

if ((value % (1024 * 1024 * 1024)) == 0)
s = String.valueOf(value / (1024 * 1024 * 1024)) + " g";
else if ((value % (1024 * 1024)) == 0)
s = String.valueOf(value / (1024 * 1024)) + " m";
else if ((value % 1024) == 0)
s = String.valueOf(value / 1024) + " k";
else
s = String.valueOf(value);

setString(section, subsection, name, s);
}

/**
* Add or modify a configuration value. The parameters will result in a
* configuration entry like this.
*
* <pre>
* [section &quot;subsection&quot;]
* name = value
* </pre>
*
* @param section
* section name, e.g "branch"
* @param subsection
* optional subsection value, e.g. a branch name
* @param name
* parameter name, e.g. "filemode"
* @param value
* parameter value
*/
public void setBoolean(final String section, final String subsection,
final String name, final boolean value) {
setString(section, subsection, name, value ? "true" : "false");
}

/**
* Add or modify a configuration value. The parameters will result in a
* configuration entry like this.
Expand Down

0 comments on commit 0414c67

Please sign in to comment.