Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/PhasesHelper.java @ 447:056f724bdc21 smartgit3
Cache earliest phase root revision not to evaluate all the time
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 06 Jun 2012 20:11:17 +0200 |
parents | 9f0e6dfd417e |
children | 2e402c12ebc6 |
rev | line source |
---|---|
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012 TMate Software Ltd |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgPhase.Draft; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgPhase.Secret; |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
21 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.io.BufferedReader; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.File; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.FileReader; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.io.IOException; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.util.Arrays; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.util.Collections; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.HashMap; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.util.HashSet; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.util.LinkedList; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import java.util.List; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import org.tmatesoft.hg.core.HgChangeset; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.core.HgInvalidControlFileException; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.core.Nodeid; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import org.tmatesoft.hg.repo.HgChangelog; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 import org.tmatesoft.hg.repo.HgInternals; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 import org.tmatesoft.hg.repo.HgPhase; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgRepository; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 /** |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * Support to deal with phases feature fo Mercurial (as of Mercutial version 2.1) |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 * |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 * @author Artem Tikhomirov |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 * @author TMate Software Ltd. |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 */ |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 public final class PhasesHelper { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 private final HgRepository hgRepo; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 private final HgChangelog.ParentWalker parentHelper; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 private Boolean repoSupporsPhases; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 private List<Nodeid> draftPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 private List<Nodeid> secretPhaseRoots; |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
55 private int[] earliestRevIndex = new int[HgPhase.values().length]; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 public PhasesHelper(HgRepository repo) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 this(repo, null); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 public PhasesHelper(HgRepository repo, HgChangelog.ParentWalker pw) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 hgRepo = repo; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 parentHelper = pw; |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
64 Arrays.fill(earliestRevIndex, BAD_REVISION); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 public boolean isCapableOfPhases() throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 if (null == repoSupporsPhases) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 repoSupporsPhases = readRoots(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 return repoSupporsPhases.booleanValue(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 public HgPhase getPhase(HgChangeset cset) throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 final Nodeid csetRev = cset.getNodeid(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 final int csetRevIndex = cset.getRevision(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 return getPhase(csetRevIndex, csetRev); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 public HgPhase getPhase(final int csetRevIndex, Nodeid csetRev) throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 if (!isCapableOfPhases()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 return HgPhase.Undefined; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 if (csetRev == null || csetRev.isNull()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 csetRev = hgRepo.getChangelog().getRevision(csetRevIndex); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 for (HgPhase phase : new HgPhase[] {HgPhase.Secret, HgPhase.Draft }) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 List<Nodeid> roots = getPhaseRoots(phase); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 if (roots.isEmpty()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 continue; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 if (roots.contains(csetRev)) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 return phase; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 if (parentHelper != null) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 if (parentHelper.childrenOf(roots).contains(csetRev)) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 return phase; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 } else { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 // no parent helper |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 // search all descendants |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
104 int earliestRootRevIndex = getEarliestPhaseRevision(phase); |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
105 if (earliestRootRevIndex > csetRevIndex) { |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 // this phase started later than our changeset was added, try another phase |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 continue; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 /* |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 * TODO descendants() method to build a BitSet with 1 at index of those that are descendants |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 * wrap it into a class with root nodeid to |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 * (a) collect only for a subset of repository, |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 * (b) be able to answer isDescendant(int csetRevIndex) using absolute indexing (i.e bitAt(csetRevIndex - rootRevIndex)) |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 */ |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 final HashSet<Nodeid> parents2consider = new HashSet<Nodeid>(roots); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 final boolean[] result = new boolean[] { false }; |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
117 hgRepo.getChangelog().walk(0/*earlierstRootRevIndex*/, csetRevIndex, new HgChangelog.ParentInspector() { |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 public void next(int revisionIndex, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 boolean descendant = false; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 if (!nidParent1.isNull() && parents2consider.contains(nidParent1)) { |
446
9f0e6dfd417e
Workaround for a Revlog#walk defect for the price of (almost) complete repo walk
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
445
diff
changeset
|
122 parents2consider.add(revision); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 descendant = true; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 if (!nidParent2.isNull() && parents2consider.contains(nidParent2)) { |
446
9f0e6dfd417e
Workaround for a Revlog#walk defect for the price of (almost) complete repo walk
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
445
diff
changeset
|
126 parents2consider.add(revision); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 descendant = true; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 if (descendant && revisionIndex == csetRevIndex) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 // revision of interest descends from one of the roots |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 result[0] = true; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 }); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 if (result[0]) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 return phase; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 return HgPhase.Public; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 private int[] toIndexes(List<Nodeid> roots) throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 int[] rv = new int[roots.size()]; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 for (int i = 0; i < rv.length; i++) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 rv[i] = hgRepo.getChangelog().getRevisionIndex(roots.get(i)); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 return rv; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 private Boolean readRoots() throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 // FIXME shall access phaseroots through HgRepository#repoPathHelper |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 File phaseroots = new File(HgInternals.getRepositoryDir(hgRepo), "store/phaseroots"); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 try { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 if (!phaseroots.exists()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 return Boolean.FALSE; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 HashMap<HgPhase, List<Nodeid>> phase2roots = new HashMap<HgPhase, List<Nodeid>>(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 BufferedReader br = new BufferedReader(new FileReader(phaseroots)); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 String line; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 while ((line = br.readLine()) != null) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 String[] lc = line.trim().split("\\s+"); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 if (lc.length == 0) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 continue; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 if (lc.length != 2) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 HgInternals.getContext(hgRepo).getLog().warn(getClass(), "Bad line in phaseroots:%s", line); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 continue; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 int phaseIndex = Integer.parseInt(lc[0]); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 Nodeid rootRev = Nodeid.fromAscii(lc[1]); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 HgPhase phase = HgPhase.parse(phaseIndex); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 List<Nodeid> roots = phase2roots.get(phase); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 if (roots == null) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 phase2roots.put(phase, roots = new LinkedList<Nodeid>()); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 roots.add(rootRev); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 draftPhaseRoots = phase2roots.containsKey(Draft) ? phase2roots.get(Draft) : Collections.<Nodeid>emptyList(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 secretPhaseRoots = phase2roots.containsKey(Secret) ? phase2roots.get(Secret) : Collections.<Nodeid>emptyList(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 } catch (IOException ex) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 throw new HgInvalidControlFileException(ex.toString(), ex, phaseroots); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 return Boolean.TRUE; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 private List<Nodeid> getPhaseRoots(HgPhase phase) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 switch (phase) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 case Draft : return draftPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 case Secret : return secretPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 return Collections.emptyList(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 } |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
196 |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
197 private int getEarliestPhaseRevision(HgPhase phase) throws HgInvalidControlFileException { |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
198 int ordinal = phase.ordinal(); |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
199 if (earliestRevIndex[ordinal] == BAD_REVISION) { |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
200 int[] rootIndexes = toIndexes(getPhaseRoots(phase)); |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
201 Arrays.sort(rootIndexes); |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
202 // instead of MAX_VALUE may use clog.getLastRevision() + 1 |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
203 earliestRevIndex[ordinal] = rootIndexes.length == 0 ? Integer.MAX_VALUE : rootIndexes[0]; |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
204 } |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
205 return earliestRevIndex[ordinal]; |
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
206 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 } |