Permalink
Browse files

Add setBoolean, setInt to RepositoryConfig

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...
1 parent dcbb668 commit 0414c6762fb91d04a52509dd8d0829774d304904 @spearce spearce committed with robinrosenberg Feb 12, 2009
Showing with 57 additions and 0 deletions.
  1. +57 −0 org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
View
57 org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
@@ -452,6 +452,63 @@ private Object getRawEntry(final String section, final String subsection,
* @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.
+ *
+ * <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, e.g. "true"
*/
public void setString(final String section, final String subsection,

0 comments on commit 0414c67

Please sign in to comment.