Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 331:a37ce7145c3f
Access to repository configuration
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Sat, 05 Nov 2011 04:21:18 +0100 |
| parents | c3d2233ba842 |
| children | 3d41dc148d14 |
comparison
equal
deleted
inserted
replaced
| 330:9747a786a34d | 331:a37ce7145c3f |
|---|---|
| 71 private final String repoLocation; | 71 private final String repoLocation; |
| 72 private final DataAccessProvider dataAccess; | 72 private final DataAccessProvider dataAccess; |
| 73 private final PathRewrite normalizePath; | 73 private final PathRewrite normalizePath; |
| 74 private final PathRewrite dataPathHelper; | 74 private final PathRewrite dataPathHelper; |
| 75 private final PathRewrite repoPathHelper; | 75 private final PathRewrite repoPathHelper; |
| 76 private final boolean isCaseSensitiveFileSystem; | 76 private final boolean isCaseSensitiveFileSystem; // FIXME keep this inside Internals impl and delegate to Internals all os/fs-specific tasks |
| 77 private final SessionContext sessionContext; | 77 private final SessionContext sessionContext; |
| 78 | 78 |
| 79 private HgChangelog changelog; | 79 private HgChangelog changelog; |
| 80 private HgManifest manifest; | 80 private HgManifest manifest; |
| 81 private HgTags tags; | 81 private HgTags tags; |
| 86 // XXX perhaps, shall enable caching explicitly | 86 // XXX perhaps, shall enable caching explicitly |
| 87 private final HashMap<Path, SoftReference<RevlogStream>> streamsCache = new HashMap<Path, SoftReference<RevlogStream>>(); | 87 private final HashMap<Path, SoftReference<RevlogStream>> streamsCache = new HashMap<Path, SoftReference<RevlogStream>>(); |
| 88 | 88 |
| 89 private final org.tmatesoft.hg.internal.Internals impl = new org.tmatesoft.hg.internal.Internals(); | 89 private final org.tmatesoft.hg.internal.Internals impl = new org.tmatesoft.hg.internal.Internals(); |
| 90 private HgIgnore ignore; | 90 private HgIgnore ignore; |
| 91 private ConfigFile configFile; | 91 private HgRepoConfig repoConfig; |
| 92 | 92 |
| 93 HgRepository(String repositoryPath) { | 93 HgRepository(String repositoryPath) { |
| 94 repoDir = null; | 94 repoDir = null; |
| 95 workingDir = null; | 95 workingDir = null; |
| 96 repoLocation = repositoryPath; | 96 repoLocation = repositoryPath; |
| 281 subRepos = new SubrepoManager(this); | 281 subRepos = new SubrepoManager(this); |
| 282 } | 282 } |
| 283 return subRepos.all(); | 283 return subRepos.all(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 | |
| 287 public HgRepoConfig getConfiguration() /* XXX throws HgInvalidControlFileException? Description of the exception suggests it is only for files under ./hg/*/ { | |
| 288 if (repoConfig == null) { | |
| 289 try { | |
| 290 ConfigFile configFile = impl.readConfiguration(this, getRepositoryRoot()); | |
| 291 repoConfig = new HgRepoConfig(configFile); | |
| 292 } catch (IOException ex) { | |
| 293 String m = "Errors while reading user configuration file"; | |
| 294 getContext().getLog().warn(getClass(), ex, m); | |
| 295 return new HgRepoConfig(new ConfigFile()); // empty config, do not cache, allow to try once again | |
| 296 //throw new HgInvalidControlFileException(m, ex, null); | |
| 297 } | |
| 298 } | |
| 299 return repoConfig; | |
| 300 } | |
| 301 | |
| 286 // shall be of use only for internal classes | 302 // shall be of use only for internal classes |
| 287 /*package-local*/ File getRepositoryRoot() { | 303 /*package-local*/ File getRepositoryRoot() { |
| 288 return repoDir; | 304 return repoDir; |
| 289 } | 305 } |
| 290 | 306 |
| 352 } | 368 } |
| 353 } | 369 } |
| 354 return null; // XXX empty stream instead? | 370 return null; // XXX empty stream instead? |
| 355 } | 371 } |
| 356 | 372 |
| 357 // can't expose internal class, otherwise seems reasonable to have it in API | |
| 358 /*package-local*/ ConfigFile getConfigFile() { | |
| 359 if (configFile == null) { | |
| 360 configFile = new ConfigFile(); | |
| 361 try { | |
| 362 configFile.addLocation(new File(System.getProperty("user.home"), ".hgrc")); | |
| 363 // last one, overrides anything else | |
| 364 // <repo>/.hg/hgrc | |
| 365 configFile.addLocation(new File(getRepositoryRoot(), "hgrc")); | |
| 366 } catch (IOException ex) { | |
| 367 getContext().getLog().warn(getClass(), ex, "Errors while reading user configuration file"); | |
| 368 } | |
| 369 } | |
| 370 return configFile; | |
| 371 } | |
| 372 | |
| 373 /*package-local*/ List<Filter> getFiltersFromRepoToWorkingDir(Path p) { | 373 /*package-local*/ List<Filter> getFiltersFromRepoToWorkingDir(Path p) { |
| 374 return instantiateFilters(p, new Filter.Options(Filter.Direction.FromRepo)); | 374 return instantiateFilters(p, new Filter.Options(Filter.Direction.FromRepo)); |
| 375 } | 375 } |
| 376 | 376 |
| 377 /*package-local*/ List<Filter> getFiltersFromWorkingDirToRepo(Path p) { | 377 /*package-local*/ List<Filter> getFiltersFromWorkingDirToRepo(Path p) { |
| 385 /*package-local*/ SessionContext getContext() { | 385 /*package-local*/ SessionContext getContext() { |
| 386 return sessionContext; | 386 return sessionContext; |
| 387 } | 387 } |
| 388 | 388 |
| 389 private List<Filter> instantiateFilters(Path p, Filter.Options opts) { | 389 private List<Filter> instantiateFilters(Path p, Filter.Options opts) { |
| 390 List<Filter.Factory> factories = impl.getFilters(this, getConfigFile()); | 390 List<Filter.Factory> factories = impl.getFilters(this); |
| 391 if (factories.isEmpty()) { | 391 if (factories.isEmpty()) { |
| 392 return Collections.emptyList(); | 392 return Collections.emptyList(); |
| 393 } | 393 } |
| 394 ArrayList<Filter> rv = new ArrayList<Filter>(factories.size()); | 394 ArrayList<Filter> rv = new ArrayList<Filter>(factories.size()); |
| 395 for (Filter.Factory ff : factories) { | 395 for (Filter.Factory ff : factories) { |
