# HG changeset patch # User Artem Tikhomirov # Date 1339170900 -7200 # Node ID 39fe00407937eeb193609f72e25208a061aaa35e # Parent 03fd8d079e9cb35f66fe22db0c151a79302c096d HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision diff -r 03fd8d079e9c -r 39fe00407937 src/org/tmatesoft/hg/internal/PhasesHelper.java --- a/src/org/tmatesoft/hg/internal/PhasesHelper.java Thu Jun 07 17:06:23 2012 +0200 +++ b/src/org/tmatesoft/hg/internal/PhasesHelper.java Fri Jun 08 17:55:00 2012 +0200 @@ -113,12 +113,13 @@ private Boolean readRoots() throws HgInvalidControlFileException { // FIXME shall access phaseroots through HgRepository#repoPathHelper File phaseroots = new File(HgInternals.getRepositoryDir(repo), "store/phaseroots"); + BufferedReader br = null; try { if (!phaseroots.exists()) { return Boolean.FALSE; } HashMap> phase2roots = new HashMap>(); - BufferedReader br = new BufferedReader(new FileReader(phaseroots)); + br = new BufferedReader(new FileReader(phaseroots)); String line; while ((line = br.readLine()) != null) { String[] lc = line.trim().split("\\s+"); @@ -131,6 +132,10 @@ } int phaseIndex = Integer.parseInt(lc[0]); Nodeid rootRev = Nodeid.fromAscii(lc[1]); + if (!repo.getChangelog().isKnown(rootRev)) { + HgInternals.getContext(repo).getLog().warn(getClass(), "Phase(%d) root node %s doesn't exist in the repository, ignored.", phaseIndex, rootRev); + continue; + } HgPhase phase = HgPhase.parse(phaseIndex); List roots = phase2roots.get(phase); if (roots == null) { @@ -142,6 +147,15 @@ secretPhaseRoots = phase2roots.containsKey(Secret) ? phase2roots.get(Secret) : Collections.emptyList(); } catch (IOException ex) { throw new HgInvalidControlFileException(ex.toString(), ex, phaseroots); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + HgInternals.getContext(repo).getLog().info(getClass(), ex, null); + // ignore the exception otherwise + } + } } return Boolean.TRUE; }