Mercurial > hg4j
diff src/org/tmatesoft/hg/internal/PhasesHelper.java @ 493:ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 18 Oct 2012 18:36:13 +0200 |
parents | b3c16d1aede0 |
children | d2f6ab541330 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/PhasesHelper.java Thu Oct 18 16:27:32 2012 +0200 +++ b/src/org/tmatesoft/hg/internal/PhasesHelper.java Thu Oct 18 18:36:13 2012 +0200 @@ -33,7 +33,6 @@ import org.tmatesoft.hg.core.HgChangeset; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgChangelog; -import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgInvalidControlFileException; import org.tmatesoft.hg.repo.HgParentChildMap; import org.tmatesoft.hg.repo.HgPhase; @@ -50,24 +49,24 @@ */ public final class PhasesHelper { - private final HgRepository repo; + private final Internals repo; private final HgParentChildMap<HgChangelog> parentHelper; private Boolean repoSupporsPhases; private List<Nodeid> draftPhaseRoots; private List<Nodeid> secretPhaseRoots; private RevisionDescendants[][] phaseDescendants = new RevisionDescendants[HgPhase.values().length][]; - public PhasesHelper(HgRepository hgRepo) { - this(hgRepo, null); + public PhasesHelper(Internals internalRepo) { + this(internalRepo, null); } - public PhasesHelper(HgRepository hgRepo, HgParentChildMap<HgChangelog> pw) { - repo = hgRepo; + public PhasesHelper(Internals internalRepo, HgParentChildMap<HgChangelog> pw) { + repo = internalRepo; parentHelper = pw; } public HgRepository getRepo() { - return repo; + return repo.getRepo(); } public boolean isCapableOfPhases() throws HgInvalidControlFileException { @@ -90,7 +89,7 @@ } // csetRev is only used when parentHelper is available if (parentHelper != null && (csetRev == null || csetRev.isNull())) { - csetRev = repo.getChangelog().getRevision(csetRevIndex); + csetRev = getRepo().getChangelog().getRevision(csetRevIndex); } for (HgPhase phase : new HgPhase[] {HgPhase.Secret, HgPhase.Draft }) { @@ -121,8 +120,7 @@ } private Boolean readRoots() throws HgInvalidControlFileException { - // FIXME shall access phaseroots through HgRepository#repoPathHelper - File phaseroots = new File(HgInternals.getRepositoryDir(repo), "store/phaseroots"); + File phaseroots = repo.getFileFromStoreDir("phaseroots"); BufferedReader br = null; try { if (!phaseroots.exists()) { @@ -137,13 +135,13 @@ continue; } if (lc.length != 2) { - repo.getSessionContext().getLog().dump(getClass(), Warn, "Bad line in phaseroots:%s", line); + repo.getContext().getLog().dump(getClass(), Warn, "Bad line in phaseroots:%s", line); continue; } int phaseIndex = Integer.parseInt(lc[0]); Nodeid rootRev = Nodeid.fromAscii(lc[1]); - if (!repo.getChangelog().isKnown(rootRev)) { - repo.getSessionContext().getLog().dump(getClass(), Warn, "Phase(%d) root node %s doesn't exist in the repository, ignored.", phaseIndex, rootRev); + if (!getRepo().getChangelog().isKnown(rootRev)) { + repo.getContext().getLog().dump(getClass(), Warn, "Phase(%d) root node %s doesn't exist in the repository, ignored.", phaseIndex, rootRev); continue; } HgPhase phase = HgPhase.parse(phaseIndex); @@ -162,7 +160,7 @@ try { br.close(); } catch (IOException ex) { - repo.getSessionContext().getLog().dump(getClass(), Info, ex, null); + repo.getContext().getLog().dump(getClass(), Info, ex, null); // ignore the exception otherwise } } @@ -191,7 +189,7 @@ int[] roots = toIndexes(getPhaseRoots(phase)); RevisionDescendants[] rv = new RevisionDescendants[roots.length]; for (int i = 0; i < roots.length; i++) { - rv[i] = new RevisionDescendants(repo, roots[i]); + rv[i] = new RevisionDescendants(getRepo(), roots[i]); rv[i].build(); } return rv; @@ -200,7 +198,7 @@ private int[] toIndexes(List<Nodeid> roots) throws HgInvalidControlFileException { int[] rv = new int[roots.size()]; for (int i = 0; i < rv.length; i++) { - rv[i] = repo.getChangelog().getRevisionIndex(roots.get(i)); + rv[i] = getRepo().getChangelog().getRevisionIndex(roots.get(i)); } return rv; }