comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 114:46291ec605a0

Filters to read and initialize according to configuration files
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 03 Feb 2011 22:13:55 +0100
parents 54562de502f7
children c0cc2535462c
comparison
equal deleted inserted replaced
113:67ae317408c9 114:46291ec605a0
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.lang.ref.SoftReference; 21 import java.lang.ref.SoftReference;
22 import java.util.ArrayList;
23 import java.util.Collections;
22 import java.util.HashMap; 24 import java.util.HashMap;
25 import java.util.List;
23 26
24 import org.tmatesoft.hg.core.Path; 27 import org.tmatesoft.hg.core.Path;
28 import org.tmatesoft.hg.internal.ConfigFile;
25 import org.tmatesoft.hg.internal.DataAccessProvider; 29 import org.tmatesoft.hg.internal.DataAccessProvider;
30 import org.tmatesoft.hg.internal.Filter;
26 import org.tmatesoft.hg.internal.RequiresFile; 31 import org.tmatesoft.hg.internal.RequiresFile;
27 import org.tmatesoft.hg.internal.RevlogStream; 32 import org.tmatesoft.hg.internal.RevlogStream;
28 import org.tmatesoft.hg.util.FileWalker; 33 import org.tmatesoft.hg.util.FileWalker;
29 import org.tmatesoft.hg.util.PathRewrite; 34 import org.tmatesoft.hg.util.PathRewrite;
30 35
70 // XXX perhaps, shall enable caching explicitly 75 // XXX perhaps, shall enable caching explicitly
71 private final HashMap<Path, SoftReference<RevlogStream>> streamsCache = new HashMap<Path, SoftReference<RevlogStream>>(); 76 private final HashMap<Path, SoftReference<RevlogStream>> streamsCache = new HashMap<Path, SoftReference<RevlogStream>>();
72 77
73 private final org.tmatesoft.hg.internal.Internals impl = new org.tmatesoft.hg.internal.Internals(); 78 private final org.tmatesoft.hg.internal.Internals impl = new org.tmatesoft.hg.internal.Internals();
74 private HgIgnore ignore; 79 private HgIgnore ignore;
80 private ConfigFile configFile;
75 81
76 HgRepository(String repositoryPath) { 82 HgRepository(String repositoryPath) {
77 repoDir = null; 83 repoDir = null;
78 repoLocation = repositoryPath; 84 repoLocation = repositoryPath;
79 dataAccess = null; 85 dataAccess = null;
145 151
146 public PathRewrite getPathHelper() { // Really need to be public? 152 public PathRewrite getPathHelper() { // Really need to be public?
147 return normalizePath; 153 return normalizePath;
148 } 154 }
149 155
156 // local to hide use of io.File.
150 /*package-local*/ File getRepositoryRoot() { 157 /*package-local*/ File getRepositoryRoot() {
151 return repoDir; 158 return repoDir;
152 } 159 }
153 160
154 // XXX package-local, unless there are cases when required from outside (guess, working dir/revision walkers may hide dirstate access and no public visibility needed) 161 // XXX package-local, unless there are cases when required from outside (guess, working dir/revision walkers may hide dirstate access and no public visibility needed)
196 streamsCache.put(path, new SoftReference<RevlogStream>(s)); 203 streamsCache.put(path, new SoftReference<RevlogStream>(s));
197 return s; 204 return s;
198 } 205 }
199 return null; // XXX empty stream instead? 206 return null; // XXX empty stream instead?
200 } 207 }
208
209 // can't expose internal class, otherwise seems reasonable to have it in API
210 /*package-local*/ ConfigFile getConfigFile() {
211 if (configFile == null) {
212 configFile = impl.newConfigFile();
213 configFile.addLocation(new File(System.getProperty("user.home"), ".hgrc"));
214 // last one, overrides anything else
215 // <repo>/.hg/hgrc
216 configFile.addLocation(new File(getRepositoryRoot(), "hgrc"));
217 }
218 return configFile;
219 }
220
221 /*package-local*/ List<Filter> getFiltersFromRepoToWorkingDir(Path p) {
222 return instantiateFilters(p, new Filter.Options(Filter.Direction.FromRepo));
223 }
224
225 /*package-local*/ List<Filter> getFiltersFromWorkingDirToRepo(Path p) {
226 return instantiateFilters(p, new Filter.Options(Filter.Direction.ToRepo));
227 }
228
229 private List<Filter> instantiateFilters(Path p, Filter.Options opts) {
230 List<Filter.Factory> factories = impl.getFilters(this, getConfigFile());
231 if (factories.isEmpty()) {
232 return Collections.emptyList();
233 }
234 ArrayList<Filter> rv = new ArrayList<Filter>(factories.size());
235 for (Filter.Factory ff : factories) {
236 Filter f = ff.create(p, opts);
237 if (f != null) {
238 rv.add(f);
239 }
240 }
241 return rv;
242 }
201 243
202 private void parseRequires() { 244 private void parseRequires() {
203 new RequiresFile().parse(impl, new File(repoDir, "requires")); 245 new RequiresFile().parse(impl, new File(repoDir, "requires"));
204 } 246 }
247
205 } 248 }