# HG changeset patch # User Artem Tikhomirov # Date 1297890538 -3600 # Node ID 947bf231acbb33278315568c91794d2b81cd245d # Parent 3959bffb14e967b54198f49ccd2a79618b371f3b Strip off comments in config file diff -r 3959bffb14e9 -r 947bf231acbb TODO --- a/TODO Wed Feb 16 22:00:39 2011 +0100 +++ b/TODO Wed Feb 16 22:08:58 2011 +0100 @@ -46,9 +46,6 @@ - Data access - not bytes, but ByteChannel - HgRepository constants (TIP, BAD, WC) to HgRevisions enum -* defects - - ConfigFile to strip comments from values (#) - Proposed: - LogCommand.revision(int... rev)+ to walk selected revisions only (list->sort(array) on execute, binary search) - LogCommand.before(Date date) and .after() diff -r 3959bffb14e9 -r 947bf231acbb design.txt --- a/design.txt Wed Feb 16 22:00:39 2011 +0100 +++ b/design.txt Wed Feb 16 22:08:58 2011 +0100 @@ -86,7 +86,7 @@ + RepositoryTreeWalker to ManifestCommand to match other command classes * defects - - ConfigFile to strip comments from values (#) + + ConfigFile to strip comments from values (#) <<<<< diff -r 3959bffb14e9 -r 947bf231acbb src/org/tmatesoft/hg/internal/ConfigFile.java --- a/src/org/tmatesoft/hg/internal/ConfigFile.java Wed Feb 16 22:00:39 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/ConfigFile.java Wed Feb 16 22:08:58 2011 +0100 @@ -107,10 +107,14 @@ Map section = new LinkedHashMap(); while ((line = br.readLine()) != null) { line = line.trim(); + int x; + if ((x = line.indexOf('#')) != -1) { + // do not keep comments in memory, get new, shorter string + line = new String(line.substring(0, x).trim()); + } if (line.length() <= 2) { // a=b or [a] are at least of length 3 continue; } - int x; if (line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') { sectionName = line.substring(1, line.length() - 1); if (sections.indexOf(sectionName) == -1) { @@ -120,6 +124,7 @@ section = null; // drop cached value } } else if ((x = line.indexOf('=')) != -1) { + // share char[] of the original string String key = line.substring(0, x).trim(); String value = line.substring(x+1).trim(); if (section == null) {