comparison src/org/tmatesoft/hg/internal/PhasesHelper.java @ 451:39fe00407937 smartgit3

HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 08 Jun 2012 17:55:00 +0200
parents 5787e912f60e
children 7bcfbc255f48
comparison
equal deleted inserted replaced
450:03fd8d079e9c 451:39fe00407937
111 } 111 }
112 112
113 private Boolean readRoots() throws HgInvalidControlFileException { 113 private Boolean readRoots() throws HgInvalidControlFileException {
114 // FIXME shall access phaseroots through HgRepository#repoPathHelper 114 // FIXME shall access phaseroots through HgRepository#repoPathHelper
115 File phaseroots = new File(HgInternals.getRepositoryDir(repo), "store/phaseroots"); 115 File phaseroots = new File(HgInternals.getRepositoryDir(repo), "store/phaseroots");
116 BufferedReader br = null;
116 try { 117 try {
117 if (!phaseroots.exists()) { 118 if (!phaseroots.exists()) {
118 return Boolean.FALSE; 119 return Boolean.FALSE;
119 } 120 }
120 HashMap<HgPhase, List<Nodeid>> phase2roots = new HashMap<HgPhase, List<Nodeid>>(); 121 HashMap<HgPhase, List<Nodeid>> phase2roots = new HashMap<HgPhase, List<Nodeid>>();
121 BufferedReader br = new BufferedReader(new FileReader(phaseroots)); 122 br = new BufferedReader(new FileReader(phaseroots));
122 String line; 123 String line;
123 while ((line = br.readLine()) != null) { 124 while ((line = br.readLine()) != null) {
124 String[] lc = line.trim().split("\\s+"); 125 String[] lc = line.trim().split("\\s+");
125 if (lc.length == 0) { 126 if (lc.length == 0) {
126 continue; 127 continue;
129 HgInternals.getContext(repo).getLog().warn(getClass(), "Bad line in phaseroots:%s", line); 130 HgInternals.getContext(repo).getLog().warn(getClass(), "Bad line in phaseroots:%s", line);
130 continue; 131 continue;
131 } 132 }
132 int phaseIndex = Integer.parseInt(lc[0]); 133 int phaseIndex = Integer.parseInt(lc[0]);
133 Nodeid rootRev = Nodeid.fromAscii(lc[1]); 134 Nodeid rootRev = Nodeid.fromAscii(lc[1]);
135 if (!repo.getChangelog().isKnown(rootRev)) {
136 HgInternals.getContext(repo).getLog().warn(getClass(), "Phase(%d) root node %s doesn't exist in the repository, ignored.", phaseIndex, rootRev);
137 continue;
138 }
134 HgPhase phase = HgPhase.parse(phaseIndex); 139 HgPhase phase = HgPhase.parse(phaseIndex);
135 List<Nodeid> roots = phase2roots.get(phase); 140 List<Nodeid> roots = phase2roots.get(phase);
136 if (roots == null) { 141 if (roots == null) {
137 phase2roots.put(phase, roots = new LinkedList<Nodeid>()); 142 phase2roots.put(phase, roots = new LinkedList<Nodeid>());
138 } 143 }
140 } 145 }
141 draftPhaseRoots = phase2roots.containsKey(Draft) ? phase2roots.get(Draft) : Collections.<Nodeid>emptyList(); 146 draftPhaseRoots = phase2roots.containsKey(Draft) ? phase2roots.get(Draft) : Collections.<Nodeid>emptyList();
142 secretPhaseRoots = phase2roots.containsKey(Secret) ? phase2roots.get(Secret) : Collections.<Nodeid>emptyList(); 147 secretPhaseRoots = phase2roots.containsKey(Secret) ? phase2roots.get(Secret) : Collections.<Nodeid>emptyList();
143 } catch (IOException ex) { 148 } catch (IOException ex) {
144 throw new HgInvalidControlFileException(ex.toString(), ex, phaseroots); 149 throw new HgInvalidControlFileException(ex.toString(), ex, phaseroots);
150 } finally {
151 if (br != null) {
152 try {
153 br.close();
154 } catch (IOException ex) {
155 HgInternals.getContext(repo).getLog().info(getClass(), ex, null);
156 // ignore the exception otherwise
157 }
158 }
145 } 159 }
146 return Boolean.TRUE; 160 return Boolean.TRUE;
147 } 161 }
148 162
149 private List<Nodeid> getPhaseRoots(HgPhase phase) { 163 private List<Nodeid> getPhaseRoots(HgPhase phase) {