comparison src/org/tmatesoft/hg/repo/HgBranches.java @ 309:962f78aac342

Branch with few children forked shall not ignore other children once one of them is processed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 24 Sep 2011 13:02:48 +0200
parents 3f40262153a4
children 8952f89be195
comparison
equal deleted inserted replaced
308:3f40262153a4 309:962f78aac342
179 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>(); 179 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>();
180 // last revision seen for the branch 180 // last revision seen for the branch
181 final HashMap<String, Nodeid> branchLastSeen = new HashMap<String, Nodeid>(); 181 final HashMap<String, Nodeid> branchLastSeen = new HashMap<String, Nodeid>();
182 // revisions from the branch that have no children at all 182 // revisions from the branch that have no children at all
183 final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>(); 183 final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>();
184 // revisions that are immediate children of a node from a given branch 184 // revisions that are immediate children of a node from a given branch
185 // after iteration, there are some revisions left in this map (children of a branch last revision
186 // that doesn't belong to the branch. No use of this now, perhaps can deduce isInactive (e.g.those
187 // branches that have non-empty candidates are inactive if all their heads are roots for those left)
185 final HashMap<String, List<Nodeid>> branchHeadCandidates = new HashMap<String, List<Nodeid>>(); 188 final HashMap<String, List<Nodeid>> branchHeadCandidates = new HashMap<String, List<Nodeid>>();
186 HgChangelog.Inspector insp = new HgChangelog.Inspector() { 189 HgChangelog.Inspector insp = new HgChangelog.Inspector() {
187 190
188 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 191 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
189 String branchName = cset.branch(); 192 String branchName = cset.branch();
192 branchHeads.put(branchName, new LinkedList<Nodeid>()); 195 branchHeads.put(branchName, new LinkedList<Nodeid>());
193 branchHeadCandidates.put(branchName, new LinkedList<Nodeid>()); 196 branchHeadCandidates.put(branchName, new LinkedList<Nodeid>());
194 } else { 197 } else {
195 final List<Nodeid> headCandidates = branchHeadCandidates.get(branchName); 198 final List<Nodeid> headCandidates = branchHeadCandidates.get(branchName);
196 if (headCandidates.remove(nodeid)) { 199 if (headCandidates.remove(nodeid)) {
197 // no need to keep parent, as we found at least 1 child thereof to be at the same branch 200 // likely we don't need to keep parent anymore, as we found at least 1 child thereof to be at the same branch
198 branchLastSeen.remove(branchName); 201 // however, it's possible the child we found is a result of an earlier fork, and revision in the
202 // branchLastSeen is 'parallel' head, which needs to be kept
203 Nodeid lastSeenInBranch = branchLastSeen.get(branchName);
204 // check if current revision is on descendant line. Seems direct parents check is enough
205 if (pw.safeFirstParent(nodeid).equals(lastSeenInBranch) || pw.safeSecondParent(nodeid).equals(lastSeenInBranch)) {
206 branchLastSeen.remove(branchName);
207 }
199 } 208 }
200 } 209 }
201 List<Nodeid> immediateChildren = pw.directChildren(nodeid); 210 List<Nodeid> immediateChildren = pw.directChildren(nodeid);
202 if (immediateChildren.size() > 0) { 211 if (immediateChildren.size() > 0) {
203 // 1) children may be in another branch 212 // 1) children may be in another branch
213 } 222 }
214 ps.worked(1); 223 ps.worked(1);
215 } 224 }
216 }; 225 };
217 repo.getChangelog().range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp); 226 repo.getChangelog().range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp);
218 // System.out.println("HEAD CANDIDATES>>>");
219 // for (String bn : branchHeadCandidates.keySet()) {
220 // System.out.println(bn + ":" + branchHeadCandidates.get(bn).toString());
221 // }
222 // System.out.println("HEAD CANDIDATES<<<");
223 // those last seen revisions from the branch that had no children from the same branch are heads. 227 // those last seen revisions from the branch that had no children from the same branch are heads.
224 for (String bn : branchLastSeen.keySet()) { 228 for (String bn : branchLastSeen.keySet()) {
225 // these are inactive branches? - there were children, but not from the same branch? 229 // these are inactive branches? - there were children, but not from the same branch?
226 branchHeads.get(bn).add(branchLastSeen.get(bn)); 230 branchHeads.get(bn).add(branchLastSeen.get(bn));
227 } 231 }