git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 07/12] Clarify section and subsection values in Config code

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 21, 2009, 20:19 UTC
Message-ID
<1248207570-13880-8-git-send-email-spearce@spearce.org>
In-Reply-To
<1248207570-13880-7-git-send-email-spearce@spearce.org>

When I first wrote this code I wasn't clear in my intent; the section name was sometimes called "base" and the subsection name was somtimes called "extendedBase". This is nuts, everywhere else in our code we use "section" and "subsection". Renaming the fields makes the code much easier to follow.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/lib/Config.java           |   84 ++++++++++----------
 1 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
index 4940cc2..a2934a2 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
@@ -374,8 +374,8 @@ public String getString(final String section, String subsection,
 		ensureLoaded();
 
 		for (final Entry e : entries) {
-			if (section.equalsIgnoreCase(e.base) && e.extendedBase != null)
-				result.add(e.extendedBase);
+			if (section.equalsIgnoreCase(e.section) && e.subsection != null)
+				result.add(e.subsection);
 		}
 		if (baseConfig != null)
 			result.addAll(baseConfig.getSubsections(section));
@@ -582,8 +582,8 @@ public void setStringList(final String section, final String subsection,
 			byName.remove(key);
 		else if (values.size() == 1) {
 			final Entry e = new Entry();
-			e.base = section;
-			e.extendedBase = subsection;
+			e.section = section;
+			e.subsection = subsection;
 			e.name = name;
 			e.value = values.get(0);
 			byName.put(key, e);
@@ -591,8 +591,8 @@ else if (values.size() == 1) {
 			final ArrayList<Entry> eList = new ArrayList<Entry>(values.size());
 			for (final String v : values) {
 				final Entry e = new Entry();
-				e.base = section;
-				e.extendedBase = subsection;
+				e.section = section;
+				e.subsection = subsection;
 				e.name = name;
 				e.value = v;
 				eList.add(e);
@@ -639,15 +639,15 @@ else if (values.size() == 1) {
 				// so we must create a new section header at the end.
 				//
 				final Entry e = new Entry();
-				e.base = section;
-				e.extendedBase = subsection;
+				e.section = section;
+				e.subsection = subsection;
 				entries.add(e);
 				insertPosition = entries.size();
 			}
 			while (valueIndex < values.size()) {
 				final Entry e = new Entry();
-				e.base = section;
-				e.extendedBase = subsection;
+				e.section = section;
+				e.subsection = subsection;
 				e.name = name;
 				e.value = values.get(valueIndex++);
 				entries.add(insertPosition++, e);
@@ -686,17 +686,17 @@ protected void printConfig(final PrintWriter r) {
 			if (e.prefix != null) {
 				r.print(e.prefix);
 			}
-			if (e.base != null && e.name == null) {
+			if (e.section != null && e.name == null) {
 				r.print('[');
-				r.print(e.base);
-				if (e.extendedBase != null) {
+				r.print(e.section);
+				if (e.subsection != null) {
 					r.print(' ');
 					r.print('"');
-					r.print(escapeValue(e.extendedBase));
+					r.print(escapeValue(e.subsection));
 					r.print('"');
 				}
 				r.print(']');
-			} else if (e.base != null && e.name != null) {
+			} else if (e.section != null && e.name != null) {
 				if (e.prefix == null || "".equals(e.prefix)) {
 					r.print('\t');
 				}
@@ -740,7 +740,7 @@ public void load() throws IOException {
 				} else if ('\n' == in) {
 					// End of this entry.
 					add(e);
-					if (e.base != null) {
+					if (e.section != null) {
 						last = e;
 					}
 					e = new Entry();
@@ -750,18 +750,18 @@ public void load() throws IOException {
 				} else if (';' == in || '#' == in) {
 					// The rest of this line is a comment; put into suffix.
 					e.suffix = String.valueOf(in);
-				} else if (e.base == null && Character.isWhitespace(in)) {
+				} else if (e.section == null && Character.isWhitespace(in)) {
 					// Save the leading whitespace (if any).
 					if (e.prefix == null) {
 						e.prefix = "";
 					}
 					e.prefix += in;
 				} else if ('[' == in) {
-					// This is a group header line.
-					e.base = readBase(r);
+					// This is a section header.
+					e.section = readSectionName(r);
 					input = r.read();
 					if ('"' == input) {
-						e.extendedBase = readValue(r, true, '"');
+						e.subsection = readValue(r, true, '"');
 						input = r.read();
 					}
 					if (']' != input) {
@@ -770,10 +770,10 @@ public void load() throws IOException {
 					e.suffix = "";
 				} else if (last != null) {
 					// Read a value.
-					e.base = last.base;
-					e.extendedBase = last.extendedBase;
+					e.section = last.section;
+					e.subsection = last.subsection;
 					r.reset();
-					e.name = readName(r);
+					e.name = readKeyName(r);
 					if (e.name.endsWith("\n")) {
 						e.name = e.name.substring(0, e.name.length() - 1);
 						e.value = MAGIC_EMPTY_VALUE;
@@ -809,11 +809,11 @@ protected void clear() {
 	@SuppressWarnings("unchecked")
 	private void add(final Entry e) {
 		entries.add(e);
-		if (e.base != null) {
-			final String b = e.base.toLowerCase();
+		if (e.section != null) {
+			final String b = e.section.toLowerCase();
 			final String group;
-			if (e.extendedBase != null) {
-				group = b + "." + e.extendedBase;
+			if (e.subsection != null) {
+				group = b + "." + e.subsection;
 			} else {
 				group = b;
 			}
@@ -835,8 +835,9 @@ private void add(final Entry e) {
 		}
 	}
 
-	private static String readBase(final BufferedReader r) throws IOException {
-		final StringBuffer base = new StringBuffer();
+	private static String readSectionName(final BufferedReader r)
+			throws IOException {
+		final StringBuffer name = new StringBuffer();
 		for (;;) {
 			r.mark(1);
 			int c = r.read();
@@ -857,22 +858,23 @@ private static String readBase(final BufferedReader r) throws IOException {
 					} else if (' ' == c || '\t' == c) {
 						// Skipped...
 					} else {
-						throw new IOException("Bad base entry. : " + base + ","
-								+ c);
+						throw new IOException("Bad section entry. : " + name
+								+ "," + c);
 					}
 				}
 				break;
 			} else if (Character.isLetterOrDigit((char) c) || '.' == c
 					|| '-' == c) {
-				base.append((char) c);
+				name.append((char) c);
 			} else {
-				throw new IOException("Bad base entry. : " + base + ", " + c);
+				throw new IOException("Bad section entry. : " + name + ", " + c);
 			}
 		}
-		return base.toString();
+		return name.toString();
 	}
 
-	private static String readName(final BufferedReader r) throws IOException {
+	private static String readKeyName(final BufferedReader r)
+			throws IOException {
 		final StringBuffer name = new StringBuffer();
 		for (;;) {
 			r.mark(1);
@@ -1001,12 +1003,12 @@ private static String readValue(final BufferedReader r, boolean quote,
 		/**
 		 * The section name for the entry
 		 */
-		String base;
+		String section;
 
 		/**
 		 * Subsection name
 		 */
-		String extendedBase;
+		String subsection;
 
 		/**
 		 * The key name
@@ -1023,10 +1025,10 @@ private static String readValue(final BufferedReader r, boolean quote,
 		 */
 		String suffix;
 
-		boolean match(final String aBase, final String aExtendedBase,
-				final String aName) {
-			return eq(base, aBase) && eq(extendedBase, aExtendedBase)
-					&& eq(name, aName);
+		boolean match(final String aSection, final String aSubsection,
+				final String aKey) {
+			return eq(section, aSection) && eq(subsection, aSubsection)
+					&& eq(name, aKey);
 		}
 
 		private static boolean eq(final String a, final String b) {
-- 
1.6.4.rc1.186.g60aa0c
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 8 of 18 in “Cleanup Config class”
  1. 00/12 Cleanup Config classShawn O. Pearce, Jul 21, 2009
  2. 01/12 Use NB.readFully(File) to slurp complete file contentsShawn O. Pearce, Jul 21, 2009
  3. 02/12 Correct name of fileRead member of Config classShawn O. Pearce, Jul 21, 2009
  4. 03/12 Add setLong to ConfigShawn O. Pearce, Jul 21, 2009
  5. 04/12 Fix Config setInt(..., 0) to store "0" not "0 g"Shawn O. Pearce, Jul 21, 2009
  6. 05/12 Rename Config.unsetString to just unset()Shawn O. Pearce, Jul 21, 2009
  7. 06/12 Remove pointless null assignments in ConfigShawn O. Pearce, Jul 21, 2009
  8. 07/12 Clarify section and subsection values in Config codeShawn O. Pearce, Jul 21, 2009
  9. 08/12 Don't subclass PrintWriter when writing the ConfigShawn O. Pearce, Jul 21, 2009
  10. 09/12 Use a Java 5 style iteration over the Config entries listShawn O. Pearce, Jul 21, 2009
  11. 10/12 Match config subsection names using case sensitive searchShawn O. Pearce, Jul 21, 2009
  12. 11/12 Cleanup Config's MAGIC_EMPTY_VALUE to be more safeShawn O. Pearce, Jul 21, 2009
  13. 12/12 Remove unreferenced REMOTE_SECTION from RepositoryConfigShawn O. Pearce, Jul 21, 2009
  14. Robin RosenbergJul 21, 2009
  15. Shawn O. PearceJul 21, 2009
  16. Constantine PlotnikovJul 22, 2009
  17. Robin RosenbergJul 22, 2009
  18. Ensure Config readers handle case insensitive names correctlyShawn O. Pearce, Jul 24, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.