# HG changeset patch # User Artem Tikhomirov # Date 1320900252 -3600 # Node ID 3d41dc148d14338953df7ab2ce96d0e9272dd51c # Parent 15e1961719f2cf3c047f13b44a0fd409e337589f Do not fail with exception on syntax errors in .hgignore diff -r 15e1961719f2 -r 3d41dc148d14 src/org/tmatesoft/hg/core/HgInvalidControlFileException.java --- a/src/org/tmatesoft/hg/core/HgInvalidControlFileException.java Wed Nov 09 05:22:26 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgInvalidControlFileException.java Thu Nov 10 05:44:12 2011 +0100 @@ -23,7 +23,8 @@ /** * WORK IN PROGRESS * - * Subclass of {@link HgInvalidFileException} to indicate failure to deal with one of Mercurial control files (those under .hg/) + * Subclass of {@link HgInvalidFileException} to indicate failure to deal with one of Mercurial control files + * (most likely those under .hg/, but also those residing in the repository, with special meaning to the Mercurial, like .hgtags or .hgignore) * @author Artem Tikhomirov * @author TMate Software Ltd. */ diff -r 15e1961719f2 -r 3d41dc148d14 src/org/tmatesoft/hg/repo/HgIgnore.java --- a/src/org/tmatesoft/hg/repo/HgIgnore.java Wed Nov 09 05:22:26 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgIgnore.java Thu Nov 10 05:44:12 2011 +0100 @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.tmatesoft.hg.util.Path; @@ -41,19 +42,20 @@ entries = Collections.emptyList(); } - /* package-local */void read(File hgignoreFile) throws IOException { + /* package-local */List read(File hgignoreFile) throws IOException { if (!hgignoreFile.exists()) { - return; + return null; } BufferedReader fr = new BufferedReader(new FileReader(hgignoreFile)); try { - read(fr); + return read(fr); } finally { fr.close(); } } - /* package-local */void read(BufferedReader content) throws IOException { + /* package-local */List read(BufferedReader content) throws IOException { + ArrayList errors = new ArrayList(); ArrayList result = new ArrayList(entries); // start with existing String syntax = "regexp"; // or "glob" String line; @@ -62,7 +64,9 @@ if (line.startsWith("syntax:")) { syntax = line.substring("syntax:".length()).trim(); if (!"regexp".equals(syntax) && !"glob".equals(syntax)) { - throw new IllegalStateException(line); + errors.add(line); + continue; + //throw new IllegalStateException(line); } } else if (line.length() > 0) { // shall I account for local paths in the file (i.e. @@ -87,11 +91,16 @@ // however, own attempts make me think '\' on Windows are not treated as escapes line = glob2regex(line); } - result.add(Pattern.compile(line)); // case-sensitive + try { + result.add(Pattern.compile(line)); // case-sensitive + } catch (PatternSyntaxException ex) { + errors.add(line + "@" + ex.getMessage()); + } } } result.trimToSize(); entries = result; + return errors.isEmpty() ? null : errors; } // note, #isIgnored(), even if queried for directories and returned positive reply, may still get diff -r 15e1961719f2 -r 3d41dc148d14 src/org/tmatesoft/hg/repo/HgRepository.java --- a/src/org/tmatesoft/hg/repo/HgRepository.java Wed Nov 09 05:22:26 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Thu Nov 10 05:44:12 2011 +0100 @@ -323,15 +323,20 @@ * Access to configured set of ignored files. * @see HgIgnore#isIgnored(Path) */ - public HgIgnore getIgnore() { + public HgIgnore getIgnore() /*throws HgInvalidControlFileException */{ // TODO read config for additional locations if (ignore == null) { ignore = new HgIgnore(); + File ignoreFile = new File(getWorkingDir(), ".hgignore"); try { - File ignoreFile = new File(getWorkingDir(), ".hgignore"); - ignore.read(ignoreFile); + final List errors = ignore.read(ignoreFile); + if (errors != null) { + getContext().getLog().warn(getClass(), "Syntax errors parsing .hgignore:\n%s", errors); + } } catch (IOException ex) { - getContext().getLog().warn(getClass(), ex, null); + final String m = "Error reading .hgignore file"; + getContext().getLog().warn(getClass(), ex, m); +// throw new HgInvalidControlFileException(m, ex, ignoreFile); } } return ignore;