Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgIgnore.java @ 610:5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Thu, 09 May 2013 21:06:48 +0200 | 
| parents | e6407313bab7 | 
| children | 7efabe0cddcf | 
   comparison
  equal
  deleted
  inserted
  replaced
| 609:e4a71afd3c71 | 610:5c68567b3645 | 
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License | 
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com | 
| 16 */ | 16 */ | 
| 17 package org.tmatesoft.hg.repo; | 17 package org.tmatesoft.hg.repo; | 
| 18 | 18 | 
| 19 import static org.tmatesoft.hg.repo.HgRepositoryFiles.HgIgnore; | |
| 20 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; | |
| 21 | |
| 19 import java.io.BufferedReader; | 22 import java.io.BufferedReader; | 
| 20 import java.io.File; | 23 import java.io.File; | 
| 21 import java.io.FileReader; | 24 import java.io.FileReader; | 
| 22 import java.io.IOException; | 25 import java.io.IOException; | 
| 23 import java.util.ArrayList; | 26 import java.util.ArrayList; | 
| 24 import java.util.Collections; | 27 import java.util.Collections; | 
| 25 import java.util.List; | 28 import java.util.List; | 
| 26 import java.util.regex.Pattern; | 29 import java.util.regex.Pattern; | 
| 27 import java.util.regex.PatternSyntaxException; | 30 import java.util.regex.PatternSyntaxException; | 
| 28 | 31 | 
| 32 import org.tmatesoft.hg.internal.FileChangeMonitor; | |
| 33 import org.tmatesoft.hg.internal.Internals; | |
| 29 import org.tmatesoft.hg.util.Path; | 34 import org.tmatesoft.hg.util.Path; | 
| 30 import org.tmatesoft.hg.util.PathRewrite; | 35 import org.tmatesoft.hg.util.PathRewrite; | 
| 31 | 36 | 
| 32 /** | 37 /** | 
| 33 * Handling of ignored paths according to .hgignore configuration | 38 * Handling of ignored paths according to .hgignore configuration | 
| 37 */ | 42 */ | 
| 38 public class HgIgnore implements Path.Matcher { | 43 public class HgIgnore implements Path.Matcher { | 
| 39 | 44 | 
| 40 private List<Pattern> entries; | 45 private List<Pattern> entries; | 
| 41 private final PathRewrite globPathHelper; | 46 private final PathRewrite globPathHelper; | 
| 47 private FileChangeMonitor ignoreFileTracker; | |
| 42 | 48 | 
| 43 HgIgnore(PathRewrite globPathRewrite) { | 49 HgIgnore(PathRewrite globPathRewrite) { | 
| 44 entries = Collections.emptyList(); | 50 entries = Collections.emptyList(); | 
| 45 globPathHelper = globPathRewrite; | 51 globPathHelper = globPathRewrite; | 
| 46 } | 52 } | 
| 47 | 53 | 
| 48 /* package-local */ List<String> read(File hgignoreFile) throws IOException { | 54 /* package-local */ void read(Internals repo) throws HgInvalidControlFileException { | 
| 49 if (!hgignoreFile.exists()) { | 55 File ignoreFile = repo.getRepositoryFile(HgIgnore); | 
| 50 return null; | 56 BufferedReader fr = null; | 
| 51 } | |
| 52 BufferedReader fr = new BufferedReader(new FileReader(hgignoreFile)); | |
| 53 try { | 57 try { | 
| 54 return read(fr); | 58 if (ignoreFile.canRead() && ignoreFile.isFile()) { | 
| 59 fr = new BufferedReader(new FileReader(ignoreFile)); | |
| 60 final List<String> errors = read(fr); | |
| 61 if (errors != null) { | |
| 62 repo.getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n")); | |
| 63 } | |
| 64 } | |
| 65 if (ignoreFileTracker == null) { | |
| 66 ignoreFileTracker = new FileChangeMonitor(ignoreFile); | |
| 67 } | |
| 68 ignoreFileTracker.touch(this); | |
| 69 } catch (IOException ex) { | |
| 70 final String m = String.format("Error reading %s file", ignoreFile); | |
| 71 throw new HgInvalidControlFileException(m, ex, ignoreFile); | |
| 55 } finally { | 72 } finally { | 
| 56 fr.close(); | 73 try { | 
| 74 if (fr != null) { | |
| 75 fr.close(); | |
| 76 } | |
| 77 } catch (IOException ex) { | |
| 78 repo.getLog().dump(getClass(), Warn, ex, null); // it's read, don't treat as error | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 /*package-local*/ void reloadIfChanged(Internals repo) throws HgInvalidControlFileException { | |
| 84 assert ignoreFileTracker != null; | |
| 85 if (ignoreFileTracker.changed(this)) { | |
| 86 entries = Collections.emptyList(); | |
| 87 read(repo); | |
| 57 } | 88 } | 
| 58 } | 89 } | 
| 59 | 90 | 
| 60 /* package-local */ List<String> read(BufferedReader content) throws IOException { | 91 /* package-local */ List<String> read(BufferedReader content) throws IOException { | 
| 61 final String REGEXP = "regexp", GLOB = "glob"; | 92 final String REGEXP = "regexp", GLOB = "glob"; | 
