# HG changeset patch # User Artem Tikhomirov # Date 1345129714 -7200 # Node ID b3c16d1aede0227247f9c64122d74f9e896f0068 # Parent 9c0138cda59a4a476e22366b855159be2f76f02e Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library) diff -r 9c0138cda59a -r b3c16d1aede0 TODO --- a/TODO Mon Aug 13 19:24:29 2012 +0200 +++ b/TODO Thu Aug 16 17:08:34 2012 +0200 @@ -1,3 +1,4 @@ + Read-only support, version 1.0 ============================== Committed: diff -r 9c0138cda59a -r b3c16d1aede0 cmdline/org/tmatesoft/hg/console/Main.java --- a/cmdline/org/tmatesoft/hg/console/Main.java Mon Aug 13 19:24:29 2012 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Thu Aug 16 17:08:34 2012 +0200 @@ -154,7 +154,7 @@ // TODO as test private void readConfigFile() throws Exception { - ConfigFile configFile = new ConfigFile(HgInternals.getContext(hgRepo)); + ConfigFile configFile = new ConfigFile(hgRepo.getSessionContext()); configFile.addLocation(new File(System.getProperty("user.home"), "test-cfg/aaa/config1")); for (String s : configFile.getSectionNames()) { System.out.printf("[%s]\n", s); diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/core/HgCloneCommand.java --- a/src/org/tmatesoft/hg/core/HgCloneCommand.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/core/HgCloneCommand.java Thu Aug 16 17:08:34 2012 +0200 @@ -30,11 +30,10 @@ import java.util.TreeMap; import java.util.zip.DeflaterOutputStream; -import org.tmatesoft.hg.internal.BasicSessionContext; import org.tmatesoft.hg.internal.ByteArrayDataAccess; import org.tmatesoft.hg.internal.DataAccess; import org.tmatesoft.hg.internal.DigestHelper; -import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.internal.RepoInitializer; import org.tmatesoft.hg.repo.HgBundle; import org.tmatesoft.hg.repo.HgBundle.GroupElement; import org.tmatesoft.hg.repo.HgInvalidControlFileException; @@ -108,7 +107,7 @@ // pull all changes from the very beginning // XXX consult getContext() if by any chance has a bundle ready, if not, then read and register HgBundle completeChanges = srcRepo.getChanges(Collections.singletonList(NULL)); - WriteDownMate mate = new WriteDownMate(destination); + WriteDownMate mate = new WriteDownMate(srcRepo.getSessionContext(), destination); try { // instantiate new repo in the destdir mate.initEmptyRepository(); @@ -143,17 +142,17 @@ private final ArrayList revisionSequence = new ArrayList(); // last visited nodes first private final LinkedList fncacheFiles = new LinkedList(); - private Internals implHelper; + private RepoInitializer repoInit; - public WriteDownMate(File destDir) { + public WriteDownMate(SessionContext ctx, File destDir) { hgDir = new File(destDir, ".hg"); - implHelper = new Internals(new BasicSessionContext(null)); - implHelper.setStorageConfig(1, STORE | FNCACHE | DOTENCODE); - storagePathHelper = implHelper.buildDataFilesHelper(); + repoInit = new RepoInitializer(); + repoInit.setRequires(STORE | FNCACHE | DOTENCODE); + storagePathHelper = repoInit.buildDataFilesHelper(ctx); } public void initEmptyRepository() throws IOException { - implHelper.initEmptyRepository(hgDir); + repoInit.initEmptyRepository(hgDir); } public void complete() throws IOException { diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/core/HgLogCommand.java --- a/src/org/tmatesoft/hg/core/HgLogCommand.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/core/HgLogCommand.java Thu Aug 16 17:08:34 2012 +0200 @@ -35,7 +35,6 @@ import org.tmatesoft.hg.repo.HgChangelog; import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; import org.tmatesoft.hg.repo.HgDataFile; -import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgInvalidControlFileException; import org.tmatesoft.hg.repo.HgInvalidRevisionException; import org.tmatesoft.hg.repo.HgInvalidStateException; @@ -547,7 +546,7 @@ } } if (!sanity) { - HgInternals.getContext(repo).getLog().dump(getClass(), Error, "Index of revision %d:%s doesn't match any of requested", cs.getRevisionIndex(), cs.getNodeid().shortNotation()); + repo.getSessionContext().getLog().dump(getClass(), Error, "Index of revision %d:%s doesn't match any of requested", cs.getRevisionIndex(), cs.getNodeid().shortNotation()); } assert sanity; } diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java --- a/src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java Thu Aug 16 17:08:34 2012 +0200 @@ -51,8 +51,8 @@ } public static HgUpdateConfigCommand forRepository(HgRepository hgRepo) { - // XXX HgRepository to implement SessionContextProvider (with getContext())? - return new HgUpdateConfigCommand(HgInternals.getContext(hgRepo), new File(HgInternals.getRepositoryDir(hgRepo), "hgrc")); + // XXX HgRepository to implement SessionContext.Provider (with getContext())? + return new HgUpdateConfigCommand(hgRepo.getSessionContext(), new File(HgInternals.getRepositoryDir(hgRepo), "hgrc")); } public static HgUpdateConfigCommand forUser(SessionContext ctx) { diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/core/SessionContext.java --- a/src/org/tmatesoft/hg/core/SessionContext.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/core/SessionContext.java Thu Aug 16 17:08:34 2012 +0200 @@ -45,4 +45,11 @@ public abstract Object getConfigurationProperty(String name, Object defaultValue); // perhaps, later may add Configuration object, with PropertyMarshal's helpers // e.g. when there's standalone Caches and WritableSessionProperties objects + + /** + * Providers of the context may implement + */ + public interface Source { + SessionContext getSessionContext(); + } } diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/internal/Internals.java --- a/src/org/tmatesoft/hg/internal/Internals.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/internal/Internals.java Thu Aug 16 17:08:34 2012 +0200 @@ -20,7 +20,6 @@ import static org.tmatesoft.hg.util.LogFacility.Severity.Error; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.Charset; import java.util.ArrayList; @@ -32,7 +31,6 @@ import java.util.StringTokenizer; import org.tmatesoft.hg.core.SessionContext; -import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgInvalidControlFileException; import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection; import org.tmatesoft.hg.repo.HgRepository; @@ -77,17 +75,43 @@ private int requiresFlags = 0; private List filterFactories; - private final SessionContext sessionContext; + private final HgRepository repo; + private final File repoDir; private final boolean isCaseSensitiveFileSystem; private final boolean shallCacheRevlogsInRepo; + private final DataAccessProvider dataAccess; - public Internals(SessionContext ctx) { - sessionContext = ctx; + public Internals(HgRepository hgRepo, File hgDir) { + repo = hgRepo; + repoDir = hgDir; isCaseSensitiveFileSystem = !runningOnWindows(); + SessionContext ctx = repo.getSessionContext(); shallCacheRevlogsInRepo = new PropertyMarshal(ctx).getBoolean(CFG_PROPERTY_REVLOG_STREAM_CACHE, true); + dataAccess = new DataAccessProvider(ctx); } - public void parseRequires(HgRepository hgRepo, File requiresFile) throws HgInvalidControlFileException { + public boolean isInvalid() { + return !repoDir.exists() || !repoDir.isDirectory(); + } + + public File getFileFromRepoDir(String name) { + return new File(repoDir, name); + } + + public SessionContext getContext() { + return repo.getSessionContext(); + } + + public HgRepository getRepo() { + return repo; + } + + public DataAccessProvider getDataAccess() { + return dataAccess; + } + + public void parseRequires() throws HgInvalidControlFileException { + File requiresFile =getFileFromRepoDir("requires"); try { new RequiresFile().parse(this, requiresFile); } catch (IOException ex) { @@ -109,10 +133,7 @@ // XXX perhaps, should keep both fields right here, not in the HgRepository public PathRewrite buildDataFilesHelper() { - // Note, tests in TestStorePath depend on the encoding not being cached - Charset cs = getFileEncoding(); - // StoragePathHelper needs fine-grained control over char encoding, hence doesn't use EncodingHelper - return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0, cs); + return new RepoInitializer().setRequires(requiresFlags).buildDataFilesHelper(getContext()); } public PathRewrite buildRepositoryFilesHelper() { @@ -127,53 +148,35 @@ } } - public List getFilters(HgRepository hgRepo) { + public List getFilters() { if (filterFactories == null) { filterFactories = new ArrayList(); - ExtensionsSection cfg = hgRepo.getConfiguration().getExtensions(); + ExtensionsSection cfg = repo.getConfiguration().getExtensions(); if (cfg.isEnabled("eol")) { NewlineFilter.Factory ff = new NewlineFilter.Factory(); - ff.initialize(hgRepo); + ff.initialize(repo); filterFactories.add(ff); } if (cfg.isEnabled("keyword")) { KeywordFilter.Factory ff = new KeywordFilter.Factory(); - ff.initialize(hgRepo); + ff.initialize(repo); filterFactories.add(ff); } } return filterFactories; } - public void initEmptyRepository(File hgDir) throws IOException { - hgDir.mkdir(); - FileOutputStream requiresFile = new FileOutputStream(new File(hgDir, "requires")); - StringBuilder sb = new StringBuilder(40); - sb.append("revlogv1\n"); - if ((requiresFlags & STORE) != 0) { - sb.append("store\n"); - } - if ((requiresFlags & FNCACHE) != 0) { - sb.append("fncache\n"); - } - if ((requiresFlags & DOTENCODE) != 0) { - sb.append("dotencode\n"); - } - requiresFile.write(sb.toString().getBytes()); - requiresFile.close(); - new File(hgDir, "store").mkdir(); // with that, hg verify says ok. - } - public boolean isCaseSensitiveFileSystem() { return isCaseSensitiveFileSystem; } public EncodingHelper buildFileNameEncodingHelper() { - return new EncodingHelper(getFileEncoding(), sessionContext); + SessionContext ctx = repo.getSessionContext(); + return new EncodingHelper(getFileEncoding(ctx), ctx); } - private Charset getFileEncoding() { - Object altEncoding = sessionContext.getConfigurationProperty(CFG_PROPERTY_FS_FILENAME_ENCODING, null); + /*package-local*/ static Charset getFileEncoding(SessionContext ctx) { + Object altEncoding = ctx.getConfigurationProperty(CFG_PROPERTY_FS_FILENAME_ENCODING, null); Charset cs; if (altEncoding == null) { cs = Charset.defaultCharset(); @@ -183,7 +186,7 @@ } catch (IllegalArgumentException ex) { // both IllegalCharsetNameException and UnsupportedCharsetException are subclasses of IAE, too // not severe enough to throw an exception, imo. Just record the fact it's bad ad we ignore it - sessionContext.getLog().dump(Internals.class, Error, ex, String.format("Bad configuration value for filename encoding %s", altEncoding)); + ctx.getLog().dump(Internals.class, Error, ex, String.format("Bad configuration value for filename encoding %s", altEncoding)); cs = Charset.defaultCharset(); } } @@ -245,9 +248,8 @@ /** * @see http://www.selenic.com/mercurial/hgrc.5.html */ - public ConfigFile readConfiguration(HgRepository hgRepo, File repoRoot) throws IOException { - // XXX Internals now have sessionContext field, is there real need to extract one from the repo? - SessionContext sessionCtx = HgInternals.getContext(hgRepo); + public ConfigFile readConfiguration() throws IOException { + SessionContext sessionCtx = repo.getSessionContext(); ConfigFile configFile = new ConfigFile(sessionCtx); File hgInstallRoot = findHgInstallRoot(sessionCtx); // may be null // @@ -288,7 +290,7 @@ } // last one, overrides anything else // /.hg/hgrc - configFile.addLocation(new File(repoRoot, "hgrc")); + configFile.addLocation(getFileFromRepoDir("hgrc")); return configFile; } diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/internal/KeywordFilter.java --- a/src/org/tmatesoft/hg/internal/KeywordFilter.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/internal/KeywordFilter.java Thu Aug 16 17:08:34 2012 +0200 @@ -25,7 +25,6 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; -import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgRuntimeException; import org.tmatesoft.hg.util.Pair; @@ -265,7 +264,7 @@ int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP); return repo.getChangelog().getRevision(csetRev).shortNotation(); } catch (HgRuntimeException ex) { - HgInternals.getContext(repo).getLog().dump(getClass(), Error, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); return Nodeid.NULL.shortNotation(); // XXX perhaps, might return anything better? Not sure how hg approaches this. } } @@ -274,7 +273,7 @@ try { return getChangeset().user(); } catch (HgRuntimeException ex) { - HgInternals.getContext(repo).getLog().dump(getClass(), Error, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); return ""; } } @@ -284,7 +283,7 @@ try { d = getChangeset().date(); } catch (HgRuntimeException ex) { - HgInternals.getContext(repo).getLog().dump(getClass(), Error, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); d = new Date(0l); } return String.format("%tY/% bookmarks = Collections.emptyMap(); private String activeBookmark; - HgBookmarks(HgRepository hgRepo) { - repo = hgRepo; + HgBookmarks(Internals internals) { + internalRepo = internals; } /*package-local*/ void read() throws HgInvalidControlFileException { - final LogFacility log = repo.getContext().getLog(); - File all = new File (repo.getRepositoryRoot(), HgRepositoryFiles.Bookmarks.getName()); + final LogFacility log = internalRepo.getContext().getLog(); + final HgRepository repo = internalRepo.getRepo(); + File all = internalRepo.getFileFromRepoDir(HgRepositoryFiles.Bookmarks.getName()); LinkedHashMap bm = new LinkedHashMap(); if (all.canRead()) { LineReader lr1 = new LineReader(all, log); @@ -74,9 +76,9 @@ } activeBookmark = null; - File active = new File(repo.getRepositoryRoot(), HgRepositoryFiles.BookmarksCurrent.getName()); + File active = internalRepo.getFileFromRepoDir(HgRepositoryFiles.BookmarksCurrent.getName()); if (active.canRead()) { - LineReader lr2 = new LineReader(active, repo.getContext().getLog()); + LineReader lr2 = new LineReader(active, log); ArrayList c = new ArrayList(2); lr2.read(new LineReader.SimpleLineCollector(), c); if (c.size() > 0) { diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgBranches.java --- a/src/org/tmatesoft/hg/repo/HgBranches.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgBranches.java Thu Aug 16 17:08:34 2012 +0200 @@ -39,6 +39,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.internal.Experimental; +import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; import org.tmatesoft.hg.util.ProgressSupport; @@ -51,10 +52,12 @@ private final Map branches = new TreeMap(); private final HgRepository repo; + private final Internals internalRepo; private boolean isCacheActual = false; - HgBranches(HgRepository hgRepo) { - repo = hgRepo; + HgBranches(Internals internals) { + internalRepo = internals; + repo = internals.getRepo(); // merely a cached value } private int readCache() { @@ -101,24 +104,24 @@ return lastInCache; } catch (IOException ex) { // log error, but otherwise do nothing - repo.getContext().getLog().dump(getClass(), Warn, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); // FALL THROUGH to return -1 indicating no cache information } catch (NumberFormatException ex) { - repo.getContext().getLog().dump(getClass(), Warn, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); // FALL THROUGH } catch (HgInvalidControlFileException ex) { // shall not happen, thus log as error - repo.getContext().getLog().dump(getClass(), Error, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); // FALL THROUGH } catch (HgInvalidRevisionException ex) { - repo.getContext().getLog().dump(getClass(), Error, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); // FALL THROUGH } finally { if (br != null) { try { br.close(); } catch (IOException ex) { - repo.getContext().getLog().dump(getClass(), Warn, ex, null); // ignore + repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); // ignore } } } @@ -275,7 +278,7 @@ private File getCacheFile() { // prior to 1.8 used to be .hg/branchheads.cache - return new File(repo.getRepositoryRoot(), "cache/branchheads"); + return internalRepo.getFileFromRepoDir("cache/branchheads"); } public static class BranchInfo { diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgDataFile.java --- a/src/org/tmatesoft/hg/repo/HgDataFile.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Thu Aug 16 17:08:34 2012 +0200 @@ -182,7 +182,7 @@ try { fc.close(); } catch (IOException ex) { - getRepo().getContext().getLog().dump(getClass(), Warn, ex, null); + getRepo().getSessionContext().getLog().dump(getClass(), Warn, ex, null); } } } @@ -208,7 +208,7 @@ final int csetRevIndex; if (p.isNull()) { // no dirstate parents - getRepo().getContext().getLog().dump(getClass(), Info, "No dirstate parents, resort to TIP", getPath()); + getRepo().getSessionContext().getLog().dump(getClass(), Info, "No dirstate parents, resort to TIP", getPath()); // if it's a repository with no dirstate, use TIP then csetRevIndex = clog.getLastRevision(); if (csetRevIndex == -1) { @@ -283,7 +283,7 @@ metadata = new Metadata(); } ErrorHandlingInspector insp; - final LogFacility lf = getRepo().getContext().getLog(); + final LogFacility lf = getRepo().getSessionContext().getLog(); if (metadata.none(fileRevisionIndex)) { insp = new ContentPipe(sink, 0, lf); } else if (metadata.known(fileRevisionIndex)) { diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgDirstate.java --- a/src/org/tmatesoft/hg/repo/HgDirstate.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgDirstate.java Thu Aug 16 17:08:34 2012 +0200 @@ -17,6 +17,7 @@ package org.tmatesoft.hg.repo; import static org.tmatesoft.hg.core.Nodeid.NULL; +import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate; import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; import java.io.BufferedReader; @@ -33,6 +34,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.internal.DataAccess; import org.tmatesoft.hg.internal.EncodingHelper; +import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathRewrite; @@ -52,8 +54,7 @@ Normal, Added, Removed, Merged, // order is being used in code of this class, don't change unless any use is checked } - private final HgRepository repo; - private final File dirstateFile; + private final Internals repo; private final Path.Source pathPool; private final PathRewrite canonicalPathRewrite; private Map normal; @@ -67,14 +68,14 @@ private Pair parents; // canonicalPath may be null if we don't need to check for names other than in dirstate - /*package-local*/ HgDirstate(HgRepository hgRepo, File dirstate, Path.Source pathSource, PathRewrite canonicalPath) { + /*package-local*/ HgDirstate(Internals hgRepo, Path.Source pathSource, PathRewrite canonicalPath) { repo = hgRepo; - dirstateFile = dirstate; // XXX decide whether file names shall be kept local to reader (see #branches()) or passed from outside pathPool = pathSource; canonicalPathRewrite = canonicalPath; } - /*package-local*/ void read(EncodingHelper encodingHelper) throws HgInvalidControlFileException { + /*package-local*/ void read() throws HgInvalidControlFileException { + EncodingHelper encodingHelper = repo.buildFileNameEncodingHelper(); normal = added = removed = merged = Collections.emptyMap(); parents = new Pair(Nodeid.NULL, Nodeid.NULL); if (canonicalPathRewrite != null) { @@ -82,6 +83,7 @@ } else { canonical2dirstateName = Collections.emptyMap(); } + File dirstateFile = getDirstateFile(repo); if (dirstateFile == null || !dirstateFile.exists()) { return; } @@ -170,15 +172,20 @@ return parents; } + private static File getDirstateFile(Internals repo) { + return repo.getFileFromRepoDir(Dirstate.getName()); + } + /** * @return pair of parents, both {@link Nodeid#NULL} if dirstate is not available */ - /*package-local*/ static Pair readParents(HgRepository repo, File dirstateFile) throws HgInvalidControlFileException { + /*package-local*/ static Pair readParents(Internals internalRepo) throws HgInvalidControlFileException { // do not read whole dirstate if all we need is WC parent information + File dirstateFile = getDirstateFile(internalRepo); if (dirstateFile == null || !dirstateFile.exists()) { return new Pair(NULL, NULL); } - DataAccess da = repo.getDataAccess().create(dirstateFile); + DataAccess da = internalRepo.getDataAccess().create(dirstateFile); try { if (da.isEmpty()) { return new Pair(NULL, NULL); @@ -195,7 +202,8 @@ * TODO [post-1.0] it's really not a proper place for the method, need WorkingCopyContainer or similar * @return branch associated with the working directory */ - /*package-local*/ static String readBranch(HgRepository repo, File branchFile) throws HgInvalidControlFileException { + /*package-local*/ static String readBranch(Internals internalRepo) throws HgInvalidControlFileException { + File branchFile = internalRepo.getFileFromRepoDir("branch"); String branch = HgRepository.DEFAULT_BRANCH_NAME; if (branchFile.exists()) { try { @@ -207,7 +215,7 @@ branch = b == null || b.length() == 0 ? HgRepository.DEFAULT_BRANCH_NAME : b; r.close(); } catch (FileNotFoundException ex) { - repo.getContext().getLog().dump(HgDirstate.class, Debug, ex, null); // log verbose debug, exception might be legal here + internalRepo.getContext().getLog().dump(HgDirstate.class, Debug, ex, null); // log verbose debug, exception might be legal here // IGNORE } catch (IOException ex) { throw new HgInvalidControlFileException("Error reading file with branch information", ex, branchFile); diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgInternals.java --- a/src/org/tmatesoft/hg/repo/HgInternals.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgInternals.java Thu Aug 16 17:08:34 2012 +0200 @@ -26,7 +26,6 @@ import java.net.UnknownHostException; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.core.SessionContext; import org.tmatesoft.hg.internal.Experimental; import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.internal.RelativePathRewrite; @@ -73,8 +72,8 @@ } }; } - HgDirstate ds = new HgDirstate(repo, new File(repo.getRepositoryRoot(), "dirstate"), new Path.SimpleSource(), canonicalPath); - ds.read(repo.getImplHelper().buildFileNameEncodingHelper()); + HgDirstate ds = new HgDirstate(repo.getImplHelper(), new Path.SimpleSource(), canonicalPath); + ds.read(); return ds; } @@ -145,16 +144,9 @@ // Impl note: simple source is enough as files in the working dir are all unique // even if they might get reused (i.e. after FileIterator#reset() and walking once again), // path caching is better to be done in the code which knows that path are being reused - return new FileWalker(repo.getContext(), repoRoot, pathSrc, workindDirScope); + return new FileWalker(repo.getSessionContext(), repoRoot, pathSrc, workindDirScope); } - // expose otherwise package-local information primarily to use in our own o.t.hg.core package - public static SessionContext getContext(HgRepository repo) { - // TODO SessionContext.Source and HgRepo to implement it - return repo.getContext(); - } - - // Convenient check of revision index for validity (not all negative values are wrong as long as we use negative constants) public static boolean wrongRevisionIndex(int rev) { // TODO Another method to check,throw and expand TIP at once (check[Revision|Revlog]Index() diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgManifest.java --- a/src/org/tmatesoft/hg/repo/HgManifest.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgManifest.java Thu Aug 16 17:08:34 2012 +0200 @@ -169,7 +169,7 @@ i++; } while (manifestFirst == BAD_REVISION && csetFirst+i <= csetLast); if (manifestFirst == BAD_REVISION) { - getRepo().getContext().getLog().dump(getClass(), Info, "None of changesets [%d..%d] have associated manifest revision", csetFirst, csetLast); + getRepo().getSessionContext().getLog().dump(getClass(), Info, "None of changesets [%d..%d] have associated manifest revision", csetFirst, csetLast); // we ran through all revisions in [start..end] and none of them had manifest. // we reported that to inspector and proceeding is done now. return; @@ -618,7 +618,7 @@ // TODO calculate those missing effectively (e.g. cache and sort nodeids to speed lookup // right away in the #next (may refactor ParentWalker's sequential and sorted into dedicated helper and reuse here) if (manifest.isNull()) { - repo.getContext().getLog().dump(getClass(), Severity.Warn, "Changeset %d has no associated manifest entry", u); + repo.getSessionContext().getLog().dump(getClass(), Severity.Warn, "Changeset %d has no associated manifest entry", u); // keep -1 in the changelog2manifest map. } else { changelog2manifest[u] = repo.getManifest().getRevisionIndex(manifest); diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgMergeState.java --- a/src/org/tmatesoft/hg/repo/HgMergeState.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgMergeState.java Thu Aug 16 17:08:34 2012 +0200 @@ -29,6 +29,7 @@ import org.tmatesoft.hg.core.HgFileRevision; import org.tmatesoft.hg.core.Nodeid; +import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.internal.ManifestRevision; import org.tmatesoft.hg.internal.Pool; import org.tmatesoft.hg.util.Pair; @@ -83,11 +84,11 @@ } } - private final HgRepository repo; + private final Internals repo; private Entry[] entries; - HgMergeState(HgRepository hgRepo) { - repo = hgRepo; + HgMergeState(Internals internalRepo) { + repo = internalRepo; } /** @@ -95,15 +96,16 @@ * @throws HgRuntimeException subclass thereof to indicate issues with the library. Runtime exception */ public void refresh() throws HgRuntimeException { + final HgRepository hgRepo = repo.getRepo(); entries = null; // it's possible there are two parents but no merge/state, we shall report this case as 'merging', with proper // first and second parent values stateParent = Nodeid.NULL; Pool nodeidPool = new Pool(); Pool fnamePool = new Pool(); - Pair wcParents = repo.getWorkingCopyParents(); + Pair wcParents = hgRepo.getWorkingCopyParents(); wcp1 = nodeidPool.unify(wcParents.first()); wcp2 = nodeidPool.unify(wcParents.second()); - final File f = new File(repo.getRepositoryRoot(), "merge/state"); + final File f = repo.getFileFromRepoDir("merge/state"); if (!f.canRead()) { // empty state return; @@ -115,25 +117,25 @@ final ManifestRevision m1 = new ManifestRevision(nodeidPool, fnamePool); final ManifestRevision m2 = new ManifestRevision(nodeidPool, fnamePool); if (!wcp2.isNull()) { - final int rp2 = repo.getChangelog().getRevisionIndex(wcp2); - repo.getManifest().walk(rp2, rp2, m2); + final int rp2 = hgRepo.getChangelog().getRevisionIndex(wcp2); + hgRepo.getManifest().walk(rp2, rp2, m2); } BufferedReader br = new BufferedReader(new FileReader(f)); String s = br.readLine(); stateParent = nodeidPool.unify(Nodeid.fromAscii(s)); - final int rp1 = repo.getChangelog().getRevisionIndex(stateParent); - repo.getManifest().walk(rp1, rp1, m1); + final int rp1 = hgRepo.getChangelog().getRevisionIndex(stateParent); + hgRepo.getManifest().walk(rp1, rp1, m1); while ((s = br.readLine()) != null) { String[] r = s.split("\\00"); Path p1fname = pathPool.path(r[3]); Nodeid nidP1 = m1.nodeid(p1fname); Nodeid nidCA = nodeidPool.unify(Nodeid.fromAscii(r[5])); - HgFileRevision p1 = new HgFileRevision(repo, nidP1, m1.flags(p1fname), p1fname); + HgFileRevision p1 = new HgFileRevision(hgRepo, nidP1, m1.flags(p1fname), p1fname); HgFileRevision ca; if (nidCA == nidP1 && r[3].equals(r[4])) { ca = p1; } else { - ca = new HgFileRevision(repo, nidCA, null, pathPool.path(r[4])); + ca = new HgFileRevision(hgRepo, nidCA, null, pathPool.path(r[4])); } HgFileRevision p2; if (!wcp2.isNull() || !r[6].equals(r[4])) { @@ -143,7 +145,7 @@ assert false : "There's not enough information (or I don't know where to look) in merge/state to find out what's the second parent"; nidP2 = NULL; } - p2 = new HgFileRevision(repo, nidP2, m2.flags(p2fname), p2fname); + p2 = new HgFileRevision(hgRepo, nidP2, m2.flags(p2fname), p2fname); } else { // no second parent known. no idea what to do here, assume linear merge, use common ancestor as parent p2 = ca; diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgRemoteRepository.java --- a/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Thu Aug 16 17:08:34 2012 +0200 @@ -67,7 +67,7 @@ * @author Artem Tikhomirov * @author TMate Software Ltd. */ -public class HgRemoteRepository { +public class HgRemoteRepository implements SessionContext.Source { private final URL url; private final SSLContext sslContext; @@ -186,6 +186,10 @@ return String.format("%s://%s%s", url.getProtocol(), url.getHost(), url.getPath()); } } + + public SessionContext getSessionContext() { + return sessionContext; + } public List heads() throws HgRemoteConnectionException { try { diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgRepository.java --- a/src/org/tmatesoft/hg/repo/HgRepository.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Thu Aug 16 17:08:34 2012 +0200 @@ -34,7 +34,6 @@ import org.tmatesoft.hg.core.SessionContext; import org.tmatesoft.hg.internal.ByteArrayChannel; import org.tmatesoft.hg.internal.ConfigFile; -import org.tmatesoft.hg.internal.DataAccessProvider; import org.tmatesoft.hg.internal.Experimental; import org.tmatesoft.hg.internal.Filter; import org.tmatesoft.hg.internal.Internals; @@ -54,7 +53,7 @@ * @author Artem Tikhomirov * @author TMate Software Ltd. */ -public final class HgRepository { +public final class HgRepository implements SessionContext.Source { // IMPORTANT: if new constants added, consider fixing HgInternals#wrongRevisionIndex and HgInvalidRevisionException#getMessage @@ -100,7 +99,6 @@ private final File repoDir; // .hg folder private final File workingDir; // .hg/../ private final String repoLocation; - private final DataAccessProvider dataAccess; private final PathRewrite normalizePath; // normalized slashes but otherwise regular file names private final PathRewrite dataPathHelper; // access to file storage area (usually under .hg/store/data/), with filenames mangled private final PathRewrite repoPathHelper; // access to system files @@ -133,7 +131,6 @@ repoDir = null; workingDir = null; repoLocation = repositoryPath; - dataAccess = null; dataPathHelper = repoPathHelper = null; normalizePath = null; sessionContext = null; @@ -153,11 +150,10 @@ if (workingDir == null) { throw new IllegalArgumentException(repoDir.toString()); } - impl = new org.tmatesoft.hg.internal.Internals(ctx); repoLocation = repositoryPath; sessionContext = ctx; - dataAccess = new DataAccessProvider(ctx); - impl.parseRequires(this, new File(repoDir, "requires")); + impl = new org.tmatesoft.hg.internal.Internals(this, repositoryRoot); + impl.parseRequires(); normalizePath = impl.buildNormalizePathRewrite(); dataPathHelper = impl.buildDataFilesHelper(); repoPathHelper = impl.buildRepositoryFilesHelper(); @@ -173,7 +169,7 @@ } public boolean isInvalid() { - return repoDir == null || !repoDir.exists() || !repoDir.isDirectory(); + return impl == null || impl.isInvalid(); } public HgChangelog getChangelog() { @@ -210,12 +206,12 @@ tags.readGlobal(new StringReader(content)); } catch (CancelledException ex) { // IGNORE, can't happen, we did not configure cancellation - getContext().getLog().dump(getClass(), Debug, ex, null); + getSessionContext().getLog().dump(getClass(), Debug, ex, null); } catch (IOException ex) { // UnsupportedEncodingException can't happen (UTF8) // only from readGlobal. Need to reconsider exceptions thrown from there: // BufferedReader wraps String and unlikely to throw IOException, perhaps, log is enough? - getContext().getLog().dump(getClass(), Error, ex, null); + getSessionContext().getLog().dump(getClass(), Error, ex, null); // XXX need to decide what to do this. failure to read single revision shall not break complete cycle } } @@ -224,10 +220,10 @@ try { file2read = new File(getWorkingDir(), HgTags.getPath()); tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy - file2read = new File(repoDir, HgLocalTags.getName()); + file2read = impl.getFileFromRepoDir(HgLocalTags.getName()); // XXX pass internalrepo to readLocal, keep filename there tags.readLocal(file2read); } catch (IOException ex) { - getContext().getLog().dump(getClass(), Error, ex, null); + getSessionContext().getLog().dump(getClass(), Error, ex, null); throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); } } @@ -241,7 +237,7 @@ */ public HgBranches getBranches() throws HgInvalidControlFileException { if (branches == null) { - branches = new HgBranches(this); + branches = new HgBranches(impl); branches.collect(ProgressSupport.Factory.get(null)); } return branches; @@ -253,7 +249,7 @@ */ public HgMergeState getMergeState() { if (mergeState == null) { - mergeState = new HgMergeState(this); + mergeState = new HgMergeState(impl); } return mergeState; } @@ -289,7 +285,7 @@ * @throws HgInvalidControlFileException if attempt to read information about working copy parents from dirstate failed */ public Pair getWorkingCopyParents() throws HgInvalidControlFileException { - return HgDirstate.readParents(this, new File(repoDir, Dirstate.getName())); + return HgDirstate.readParents(impl); } /** @@ -298,7 +294,7 @@ */ public String getWorkingCopyBranchName() throws HgInvalidControlFileException { if (wcBranch == null) { - wcBranch = HgDirstate.readBranch(this, new File(repoDir, "branch")); + wcBranch = HgDirstate.readBranch(impl); } return wcBranch; } @@ -328,12 +324,12 @@ public HgRepoConfig getConfiguration() /* XXX throws HgInvalidControlFileException? Description of the exception suggests it is only for files under ./hg/*/ { if (repoConfig == null) { try { - ConfigFile configFile = impl.readConfiguration(this, getRepositoryRoot()); + ConfigFile configFile = impl.readConfiguration(); repoConfig = new HgRepoConfig(configFile); } catch (IOException ex) { String m = "Errors while reading user configuration file"; - getContext().getLog().dump(getClass(), Warn, ex, m); - return new HgRepoConfig(new ConfigFile(getContext())); // empty config, do not cache, allow to try once again + getSessionContext().getLog().dump(getClass(), Warn, ex, m); + return new HgRepoConfig(new ConfigFile(getSessionContext())); // empty config, do not cache, allow to try once again //throw new HgInvalidControlFileException(m, ex, null); } } @@ -362,9 +358,8 @@ } }; } - File dirstateFile = new File(repoDir, Dirstate.getName()); - HgDirstate ds = new HgDirstate(this, dirstateFile, pathFactory, canonicalPath); - ds.read(impl.buildFileNameEncodingHelper()); + HgDirstate ds = new HgDirstate(impl, pathFactory, canonicalPath); + ds.read(); return ds; } @@ -381,7 +376,7 @@ try { final List errors = ignore.read(ignoreFile); if (errors != null) { - getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n")); + getSessionContext().getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n")); } } catch (IOException ex) { final String m = String.format("Error reading %s file", ignoreFile); @@ -399,7 +394,7 @@ * @throws HgRuntimeException subclass thereof to indicate issues with the library. Runtime exception */ public String getCommitLastMessage() throws HgInvalidControlFileException { - File lastMessage = new File(repoDir, LastMessage.getPath()); + File lastMessage = impl.getFileFromRepoDir(LastMessage.getPath()); if (!lastMessage.canRead()) { return null; } @@ -416,7 +411,7 @@ try { fr.close(); } catch (IOException ex) { - getContext().getLog().dump(getClass(), Warn, "Failed to close %s after read", lastMessage); + getSessionContext().getLog().dump(getClass(), Warn, "Failed to close %s after read", lastMessage); } } } @@ -439,7 +434,7 @@ public HgRepositoryLock getWorkingDirLock() { if (wdLock == null) { int timeout = getLockTimeout(); - File lf = new File(getRepositoryRoot(), "wlock"); + File lf = impl.getFileFromRepoDir("wlock"); synchronized (this) { if (wdLock == null) { wdLock = new HgRepositoryLock(lf, timeout); @@ -453,7 +448,7 @@ public HgRepositoryLock getStoreLock() { if (storeLock == null) { int timeout = getLockTimeout(); - File fl = new File(getRepositoryRoot(), repoPathHelper.rewrite("lock").toString()); + File fl = impl.getFileFromRepoDir(repoPathHelper.rewrite("lock").toString()); synchronized (this) { if (storeLock == null) { storeLock = new HgRepositoryLock(fl, timeout); @@ -470,14 +465,17 @@ */ public HgBookmarks getBookmarks() throws HgInvalidControlFileException { if (bookmarks == null) { - bookmarks = new HgBookmarks(this); + bookmarks = new HgBookmarks(impl); bookmarks.read(); } return bookmarks; } - /*package-local*/ DataAccessProvider getDataAccess() { - return dataAccess; + /** + * @return session environment of the repository + */ + public SessionContext getSessionContext() { + return sessionContext; } /** @@ -492,7 +490,7 @@ } File f = new File(repoDir, path.toString()); if (f.exists()) { - RevlogStream s = new RevlogStream(dataAccess, f); + RevlogStream s = new RevlogStream(impl.getDataAccess(), f); if (impl.shallCacheRevlogs()) { streamsCache.put(path, new SoftReference(s)); } @@ -502,9 +500,9 @@ try { File fake = File.createTempFile(f.getName(), null); fake.deleteOnExit(); - return new RevlogStream(dataAccess, fake); + return new RevlogStream(impl.getDataAccess(), fake); } catch (IOException ex) { - getContext().getLog().dump(getClass(), Info, ex, null); + getSessionContext().getLog().dump(getClass(), Info, ex, null); } } } @@ -523,16 +521,12 @@ return new File(getWorkingDir(), dataFile.getPath().toString()); } - /*package-local*/ SessionContext getContext() { - return sessionContext; - } - /*package-local*/ Internals getImplHelper() { return impl; } private List instantiateFilters(Path p, Filter.Options opts) { - List factories = impl.getFilters(this); + List factories = impl.getFilters(); if (factories.isEmpty()) { return Collections.emptyList(); } diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgTags.java --- a/src/org/tmatesoft/hg/repo/HgTags.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgTags.java Thu Aug 16 17:08:34 2012 +0200 @@ -109,7 +109,7 @@ continue; } if (line.length() < 40+2 /*nodeid, space and at least single-char tagname*/) { - repo.getContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); + repo.getSessionContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); continue; } int spacePos = line.indexOf(' '); @@ -153,7 +153,7 @@ } } else { - repo.getContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); + repo.getSessionContext().getLog().dump(getClass(), Warn, "Bad tags line: %s", line); } } } diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java --- a/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Thu Aug 16 17:08:34 2012 +0200 @@ -365,7 +365,7 @@ } } } catch (HgRuntimeException ex) { - repo.getContext().getLog().dump(getClass(), Warn, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); inspector.invalid(fname, ex); } } @@ -457,7 +457,7 @@ inspector.modified(fname); } } catch (HgRuntimeException ex) { - repo.getContext().getLog().dump(getClass(), Warn, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); inspector.invalid(fname, ex); } baseRevNames.remove(fname); // consumed, processed, handled. @@ -494,7 +494,7 @@ private boolean areTheSame(FileInfo f, final byte[] data, Path p) throws HgInvalidFileException { ReadableByteChannel is = null; class Check implements ByteChannel { - final boolean debug = repo.getContext().getLog().isDebug(); + final boolean debug = repo.getSessionContext().getLog().isDebug(); boolean sameSoFar = true; int x = 0; @@ -514,7 +514,7 @@ int offset = max(0, x - 4); exp = new String(data, offset, min(data.length - offset, 20)); } - repo.getContext().getLog().dump(getClass(), Debug, "expected >>%s<< but got >>%s<<", exp, new String(xx)); + repo.getSessionContext().getLog().dump(getClass(), Debug, "expected >>%s<< but got >>%s<<", exp, new String(xx)); } sameSoFar = false; break; @@ -547,7 +547,7 @@ try { is.close(); } catch (IOException ex) { - repo.getContext().getLog().dump(getClass(), Info, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Info, ex, null); } is = f.newInputChannel(); fb.clear(); @@ -559,7 +559,7 @@ } return check.ultimatelyTheSame(); } catch (CancelledException ex) { - repo.getContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation"); + repo.getSessionContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation"); return check.ultimatelyTheSame(); } catch (IOException ex) { throw new HgInvalidFileException("File comparison failed", ex).setFileName(p); @@ -568,7 +568,7 @@ try { is.close(); } catch (IOException ex) { - repo.getContext().getLog().dump(getClass(), Info, ex, null); + repo.getSessionContext().getLog().dump(getClass(), Info, ex, null); } } } @@ -631,7 +631,7 @@ // final Path[] dirs = f.toArray(new Path[d.size()]); if (d.isEmpty()) { final Path[] files = f.toArray(new Path[f.size()]); - FileIterator fi = new FileListIterator(hgRepo.getContext(), hgRepo.getWorkingDir(), files); + FileIterator fi = new FileListIterator(hgRepo.getSessionContext(), hgRepo.getWorkingDir(), files); return new HgWorkingCopyStatusCollector(hgRepo, fi); } // diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/Revlog.java --- a/src/org/tmatesoft/hg/repo/Revlog.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Thu Aug 16 17:08:34 2012 +0200 @@ -202,7 +202,7 @@ throw new IllegalArgumentException(); } try { - ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); + ContentPipe insp = new ContentPipe(sink, 0, repo.getSessionContext().getLog()); insp.checkCancelled(); content.iterate(revisionIndex, revisionIndex, true, insp); insp.checkFailed(); diff -r 9c0138cda59a -r b3c16d1aede0 src/org/tmatesoft/hg/repo/ext/MqManager.java --- a/src/org/tmatesoft/hg/repo/ext/MqManager.java Mon Aug 13 19:24:29 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/ext/MqManager.java Thu Aug 16 17:08:34 2012 +0200 @@ -64,7 +64,7 @@ applied = allKnown = Collections.emptyList(); queueNames = Collections.emptyList(); File repoDir = HgInternals.getRepositoryDir(repo); - final LogFacility log = HgInternals.getContext(repo).getLog(); + final LogFacility log = repo.getSessionContext().getLog(); try { File queues = new File(repoDir, "patches.queues"); if (queues.isFile()) { diff -r 9c0138cda59a -r b3c16d1aede0 test/org/tmatesoft/hg/test/TestFileFlags.java --- a/test/org/tmatesoft/hg/test/TestFileFlags.java Mon Aug 13 19:24:29 2012 +0200 +++ b/test/org/tmatesoft/hg/test/TestFileFlags.java Thu Aug 16 17:08:34 2012 +0200 @@ -28,7 +28,6 @@ import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.internal.RelativePathRewrite; import org.tmatesoft.hg.repo.HgDataFile; -import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.util.FileInfo; @@ -66,7 +65,7 @@ public void testFlagsInWorkingCopy() throws Exception { File repoRoot = repo.getWorkingDir(); Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(repoRoot), repo.getToRepoPathHelper())); - FileWalker fw = new FileWalker(HgInternals.getContext(repo), repoRoot, pathSrc); + FileWalker fw = new FileWalker(repo.getSessionContext(), repoRoot, pathSrc); if (Internals.runningOnWindows()) { System.out.println("Executing tests on Windows, no actual file flags in working area are checked"); diff -r 9c0138cda59a -r b3c16d1aede0 test/org/tmatesoft/hg/test/TestIncoming.java --- a/test/org/tmatesoft/hg/test/TestIncoming.java Mon Aug 13 19:24:29 2012 +0200 +++ b/test/org/tmatesoft/hg/test/TestIncoming.java Thu Aug 16 17:08:34 2012 +0200 @@ -32,8 +32,7 @@ import org.tmatesoft.hg.core.HgIncomingCommand; import org.tmatesoft.hg.core.HgLogCommand; import org.tmatesoft.hg.core.Nodeid; -import org.tmatesoft.hg.internal.BasicSessionContext; -import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.internal.RepoInitializer; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRemoteRepository; import org.tmatesoft.hg.repo.HgRepository; @@ -135,9 +134,9 @@ static File initEmptyTempRepo(String dirName) throws IOException { File dest = createEmptyDir(dirName); - Internals implHelper = new Internals(new BasicSessionContext(null)); - implHelper.setStorageConfig(1, STORE | FNCACHE | DOTENCODE); - implHelper.initEmptyRepository(new File(dest, ".hg")); + RepoInitializer ri = new RepoInitializer(); + ri.setRequires(STORE | FNCACHE | DOTENCODE); + ri.initEmptyRepository(new File(dest, ".hg")); return dest; } } diff -r 9c0138cda59a -r b3c16d1aede0 test/org/tmatesoft/hg/test/TestStorePath.java --- a/test/org/tmatesoft/hg/test/TestStorePath.java Mon Aug 13 19:24:29 2012 +0200 +++ b/test/org/tmatesoft/hg/test/TestStorePath.java Thu Aug 16 17:08:34 2012 +0200 @@ -16,6 +16,8 @@ */ package org.tmatesoft.hg.test; +import static org.tmatesoft.hg.internal.RequiresFile.*; + import java.util.HashMap; import java.util.Map; @@ -25,8 +27,10 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.tmatesoft.hg.core.SessionContext; import org.tmatesoft.hg.internal.BasicSessionContext; import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.internal.RepoInitializer; import org.tmatesoft.hg.util.PathRewrite; /** @@ -42,7 +46,8 @@ private PathRewrite storePathHelper; private final Map propertyOverrides = new HashMap(); - private Internals internals; + private final SessionContext sessionCtx; + private final RepoInitializer repoInit; public static void main(String[] args) throws Throwable { final TestStorePath test = new TestStorePath(); @@ -54,9 +59,9 @@ public TestStorePath() { propertyOverrides.put("hg.consolelog.debug", true); - internals = new Internals(new BasicSessionContext(propertyOverrides, null)); - internals.setStorageConfig(1, 0x7); - storePathHelper = internals.buildDataFilesHelper(); + sessionCtx = new BasicSessionContext(propertyOverrides, null); + repoInit = new RepoInitializer().setRequires(STORE + FNCACHE + DOTENCODE); + storePathHelper = repoInit.buildDataFilesHelper(sessionCtx); } @Before @@ -120,11 +125,11 @@ String s = "Привет.txt"; // propertyOverrides.put(Internals.CFG_PROPERTY_FS_FILENAME_ENCODING, "cp1251"); - PathRewrite sph = internals.buildDataFilesHelper(); + PathRewrite sph = repoInit.buildDataFilesHelper(sessionCtx); errorCollector.checkThat(sph.rewrite(s), CoreMatchers.equalTo("store/data/~cf~f0~e8~e2~e5~f2.txt.i")); // propertyOverrides.put(Internals.CFG_PROPERTY_FS_FILENAME_ENCODING, "UTF8"); - sph = internals.buildDataFilesHelper(); + sph = repoInit.buildDataFilesHelper(sessionCtx); errorCollector.checkThat(sph.rewrite(s), CoreMatchers.equalTo("store/data/~d0~9f~d1~80~d0~b8~d0~b2~d0~b5~d1~82.txt.i")); } }