Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/Internals.java @ 591:e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 30 Apr 2013 18:55:42 +0200 |
parents | ed243b668502 |
children | e1b29756f901 |
comparison
equal
deleted
inserted
replaced
590:8cbc2a883d95 | 591:e447384f3771 |
---|---|
30 import java.util.StringTokenizer; | 30 import java.util.StringTokenizer; |
31 | 31 |
32 import org.tmatesoft.hg.core.SessionContext; | 32 import org.tmatesoft.hg.core.SessionContext; |
33 import org.tmatesoft.hg.repo.HgDataFile; | 33 import org.tmatesoft.hg.repo.HgDataFile; |
34 import org.tmatesoft.hg.repo.HgInternals; | 34 import org.tmatesoft.hg.repo.HgInternals; |
35 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | |
35 import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection; | 36 import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection; |
36 import org.tmatesoft.hg.repo.HgRepository; | 37 import org.tmatesoft.hg.repo.HgRepository; |
37 import org.tmatesoft.hg.repo.HgRepositoryFiles; | 38 import org.tmatesoft.hg.repo.HgRepositoryFiles; |
38 import org.tmatesoft.hg.repo.HgRepositoryLock; | 39 import org.tmatesoft.hg.repo.HgRepositoryLock; |
39 import org.tmatesoft.hg.repo.HgRuntimeException; | 40 import org.tmatesoft.hg.repo.HgRuntimeException; |
41 import org.tmatesoft.hg.util.Path; | |
40 import org.tmatesoft.hg.util.PathRewrite; | 42 import org.tmatesoft.hg.util.PathRewrite; |
41 | 43 |
42 /** | 44 /** |
43 * Fields/members that shall not be visible | 45 * Fields/members that shall not be visible |
44 * | 46 * |
113 | 115 |
114 private List<Filter.Factory> filterFactories; | 116 private List<Filter.Factory> filterFactories; |
115 private final HgRepository repo; | 117 private final HgRepository repo; |
116 private final File repoDir; | 118 private final File repoDir; |
117 private final boolean isCaseSensitiveFileSystem; | 119 private final boolean isCaseSensitiveFileSystem; |
118 private final boolean shallCacheRevlogsInRepo; | |
119 private final DataAccessProvider dataAccess; | 120 private final DataAccessProvider dataAccess; |
121 private final ImplAccess implAccess; | |
120 | 122 |
121 private final int requiresFlags; | 123 private final int requiresFlags; |
122 | 124 |
123 private final PathRewrite dataPathHelper; // access to file storage area (usually under .hg/store/data/), with filenames mangled | 125 private final PathRewrite dataPathHelper; // access to file storage area (usually under .hg/store/data/), with filenames mangled |
124 private final PathRewrite repoPathHelper; // access to system files (under .hg/store if requires has 'store' flag) | 126 private final PathRewrite repoPathHelper; // access to system files (under .hg/store if requires has 'store' flag) |
125 | 127 |
126 public Internals(HgRepository hgRepo, File hgDir) throws HgRuntimeException { | 128 private final RevlogStreamFactory streamProvider; |
129 | |
130 public Internals(HgRepository hgRepo, File hgDir, ImplAccess implementationAccess) throws HgRuntimeException { | |
127 repo = hgRepo; | 131 repo = hgRepo; |
128 repoDir = hgDir; | 132 repoDir = hgDir; |
133 implAccess = implementationAccess; | |
129 isCaseSensitiveFileSystem = !runningOnWindows(); | 134 isCaseSensitiveFileSystem = !runningOnWindows(); |
130 SessionContext ctx = repo.getSessionContext(); | 135 SessionContext ctx = repo.getSessionContext(); |
131 shallCacheRevlogsInRepo = new PropertyMarshal(ctx).getBoolean(CFG_PROPERTY_REVLOG_STREAM_CACHE, true); | |
132 dataAccess = new DataAccessProvider(ctx); | 136 dataAccess = new DataAccessProvider(ctx); |
133 RepoInitializer repoInit = new RepoInitializer().initRequiresFromFile(repoDir); | 137 RepoInitializer repoInit = new RepoInitializer().initRequiresFromFile(repoDir); |
134 requiresFlags = repoInit.getRequires(); | 138 requiresFlags = repoInit.getRequires(); |
135 dataPathHelper = repoInit.buildDataFilesHelper(getSessionContext()); | 139 dataPathHelper = repoInit.buildDataFilesHelper(getSessionContext()); |
136 repoPathHelper = repoInit.buildStoreFilesHelper(); | 140 repoPathHelper = repoInit.buildStoreFilesHelper(); |
141 boolean shallCacheRevlogsInRepo = new PropertyMarshal(ctx).getBoolean(CFG_PROPERTY_REVLOG_STREAM_CACHE, true); | |
142 streamProvider = new RevlogStreamFactory(this, shallCacheRevlogsInRepo); | |
137 } | 143 } |
138 | 144 |
139 public boolean isInvalid() { | 145 public boolean isInvalid() { |
140 return !repoDir.exists() || !repoDir.isDirectory(); | 146 return !repoDir.exists() || !repoDir.isDirectory(); |
141 } | 147 } |
369 // <repo>/.hg/hgrc | 375 // <repo>/.hg/hgrc |
370 configFile.addLocation(getFileFromRepoDir("hgrc")); | 376 configFile.addLocation(getFileFromRepoDir("hgrc")); |
371 return configFile; | 377 return configFile; |
372 } | 378 } |
373 | 379 |
380 /*package-local*/ImplAccess getImplAccess() { | |
381 return implAccess; | |
382 } | |
374 | 383 |
375 private static List<File> getWindowsConfigFilesPerInstall(File hgInstallDir) { | 384 private static List<File> getWindowsConfigFilesPerInstall(File hgInstallDir) { |
376 File f = new File(hgInstallDir, "Mercurial.ini"); | 385 File f = new File(hgInstallDir, "Mercurial.ini"); |
377 if (f.exists()) { | 386 if (f.exists()) { |
378 return Collections.singletonList(f); | 387 return Collections.singletonList(f); |
452 } | 461 } |
453 } | 462 } |
454 // fallback to default, let calling code fail with Exception if can't write | 463 // fallback to default, let calling code fail with Exception if can't write |
455 return new File(System.getProperty("user.home"), ".hgrc"); | 464 return new File(System.getProperty("user.home"), ".hgrc"); |
456 } | 465 } |
457 | 466 |
458 public boolean shallCacheRevlogs() { | 467 public RevlogStream createManifestStream() { |
459 return shallCacheRevlogsInRepo; | 468 File manifestFile = getFileFromStoreDir("00manifest.i"); |
460 } | 469 return streamProvider.create(manifestFile); |
461 | 470 } |
471 | |
472 public RevlogStream createChangelogStream() { | |
473 File chlogFile = getFileFromStoreDir("00changelog.i"); | |
474 return streamProvider.create(chlogFile); | |
475 } | |
476 | |
477 public RevlogStream resolveStoreFile(Path path) { | |
478 return streamProvider.resolveStoreFile(path); | |
479 } | |
480 | |
481 /*package-local*/ RevlogStream createStoreFile(Path path) throws HgInvalidControlFileException { | |
482 return streamProvider.createStoreFile(path); | |
483 } | |
484 | |
462 // marker method | 485 // marker method |
463 public static IllegalStateException notImplemented() { | 486 public static IllegalStateException notImplemented() { |
464 return new IllegalStateException("Not implemented"); | 487 return new IllegalStateException("Not implemented"); |
465 } | 488 } |
466 | 489 |
494 public static int ltoi(long l) { | 517 public static int ltoi(long l) { |
495 int i = (int) l; | 518 int i = (int) l; |
496 assert ((long) i) == l : "Loss of data!"; | 519 assert ((long) i) == l : "Loss of data!"; |
497 return i; | 520 return i; |
498 } | 521 } |
522 | |
523 // access implementation details (fields, methods) of oth.repo package | |
524 public interface ImplAccess { | |
525 public RevlogStream getStream(HgDataFile df); | |
526 public RevlogStream getManifestStream(); | |
527 public RevlogStream getChangelogStream(); | |
528 } | |
499 } | 529 } |