comparison src/org/tmatesoft/hg/repo/HgBranches.java @ 657:6334b0267103

ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 04 Jul 2013 20:27:45 +0200
parents a937e63b6e02
children af5223b86dd3
comparison
equal deleted inserted replaced
656:a937e63b6e02 657:6334b0267103
44 import org.tmatesoft.hg.internal.Internals; 44 import org.tmatesoft.hg.internal.Internals;
45 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 45 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
46 import org.tmatesoft.hg.util.ProgressSupport; 46 import org.tmatesoft.hg.util.ProgressSupport;
47 47
48 /** 48 /**
49 * 49 * Access information about branches in the repository
50 *
50 * @author Artem Tikhomirov 51 * @author Artem Tikhomirov
51 * @author TMate Software Ltd. 52 * @author TMate Software Ltd.
52 */ 53 */
53 public class HgBranches { 54 public class HgBranches {
54 55
123 } 124 }
124 125
125 void collect(final ProgressSupport ps) throws HgRuntimeException { 126 void collect(final ProgressSupport ps) throws HgRuntimeException {
126 branches.clear(); 127 branches.clear();
127 final HgRepository repo = internalRepo.getRepo(); 128 final HgRepository repo = internalRepo.getRepo();
128 ps.start(1 + repo.getChangelog().getRevisionCount() * 2); 129 final HgChangelog clog = repo.getChangelog();
130 final HgRevisionMap<HgChangelog> rmap;
131 ps.start(1 + clog.getRevisionCount() * 2);
129 // 132 //
130 int lastCached = readCache(); 133 int lastCached = readCache();
131 isCacheActual = lastCached == repo.getChangelog().getLastRevision(); 134 isCacheActual = lastCached == clog.getLastRevision();
132 if (!isCacheActual) { 135 if (!isCacheActual) {
133 final HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(repo.getChangelog()); 136 // XXX need a way to share HgParentChildMap<HgChangelog>
137 final HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(clog);
134 pw.init(); 138 pw.init();
135 ps.worked(repo.getChangelog().getRevisionCount()); 139 ps.worked(clog.getRevisionCount());
136 // 140 //
137 // first revision branch found at 141 // first revision branch found at
138 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>(); 142 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>();
139 // revisions from the branch that have no children at all 143 // revisions from the branch that have no children at all
140 final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>(); 144 final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>();
165 ps.worked(1); 169 ps.worked(1);
166 } 170 }
167 }; 171 };
168 // XXX alternatively may iterate with pw.all().subList(lastCached) 172 // XXX alternatively may iterate with pw.all().subList(lastCached)
169 // but need an effective way to find out branch of particular changeset 173 // but need an effective way to find out branch of particular changeset
170 repo.getChangelog().range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp); 174 clog.range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp);
171 // 175 //
172 // build BranchInfo, based on found and cached 176 // build BranchInfo, based on found and cached
173 for (String bn : branchStart.keySet()) { 177 for (String bn : branchStart.keySet()) {
174 BranchInfo bi = branches.get(bn); 178 BranchInfo bi = branches.get(bn);
175 if (bi != null) { 179 if (bi != null) {
190 Nodeid[] heads = branchHeads.get(bn).toArray(new Nodeid[0]); 194 Nodeid[] heads = branchHeads.get(bn).toArray(new Nodeid[0]);
191 bi = new BranchInfo(bn, branchStart.get(bn), heads); 195 bi = new BranchInfo(bn, branchStart.get(bn), heads);
192 } 196 }
193 branches.put(bn, bi); 197 branches.put(bn, bi);
194 } 198 }
195 } // !cacheActual 199 rmap = pw.getRevisionMap();
196 final HgChangelog clog = repo.getChangelog(); 200 } else { // !cacheActual
197 /// FIXME use HgParentChildMap if available (need to decide how to get HgRevisionMap and HgParentChildMap to a common denominator) 201 rmap = new HgRevisionMap<HgChangelog>(clog).init();
198 final HgRevisionMap<HgChangelog> rmap = new HgRevisionMap<HgChangelog>(clog).init(); 202 }
199 for (BranchInfo bi : branches.values()) { 203 for (BranchInfo bi : branches.values()) {
200 bi.validate(clog, rmap); 204 bi.validate(clog, rmap);
201 } 205 }
202 repoChangeTracker.touch(); 206 repoChangeTracker.touch();
203 ps.done(); 207 ps.done();