annotate src/org/tmatesoft/hg/internal/PhasesHelper.java @ 446:9f0e6dfd417e smartgit3

Workaround for a Revlog#walk defect for the price of (almost) complete repo walk
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 05 Jun 2012 21:18:20 +0200
parents d0e5dc3cae6e
children 056f724bdc21
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;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.BufferedReader;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.File;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.FileReader;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.io.IOException;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.util.Arrays;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.Collections;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.HashMap;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import java.util.HashSet;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.LinkedList;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.List;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.core.HgChangeset;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.core.HgInvalidControlFileException;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import org.tmatesoft.hg.core.Nodeid;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 import org.tmatesoft.hg.repo.HgChangelog;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 import org.tmatesoft.hg.repo.HgInternals;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.repo.HgPhase;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.repo.HgRepository;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
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 * 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
43 *
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * @author Artem Tikhomirov
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 * @author TMate Software Ltd.
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 */
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 public final class PhasesHelper {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 private final HgRepository hgRepo;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 private final HgChangelog.ParentWalker parentHelper;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 private Boolean repoSupporsPhases;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 private List<Nodeid> draftPhaseRoots;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 private List<Nodeid> secretPhaseRoots;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public PhasesHelper(HgRepository repo) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 this(repo, null);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 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
60 hgRepo = repo;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 parentHelper = pw;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 public boolean isCapableOfPhases() throws HgInvalidControlFileException {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 if (null == repoSupporsPhases) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 repoSupporsPhases = readRoots();
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 return repoSupporsPhases.booleanValue();
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 }
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
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 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
73 final Nodeid csetRev = cset.getNodeid();
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 final int csetRevIndex = cset.getRevision();
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 return getPhase(csetRevIndex, csetRev);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 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
79 if (!isCapableOfPhases()) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 return HgPhase.Undefined;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 if (csetRev == null || csetRev.isNull()) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 csetRev = hgRepo.getChangelog().getRevision(csetRevIndex);
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
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 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
87 List<Nodeid> roots = getPhaseRoots(phase);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 if (roots.isEmpty()) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 continue;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 if (roots.contains(csetRev)) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 return phase;
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 (parentHelper != null) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 if (parentHelper.childrenOf(roots).contains(csetRev)) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 return phase;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 } else {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 // no parent helper
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 // search all descendants
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 int[] rootIndexes = toIndexes(roots);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 Arrays.sort(rootIndexes);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 if (rootIndexes[0] > csetRevIndex) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 // 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
105 continue;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 /*
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 * 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
109 * 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
110 * (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
111 * (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
112 */
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 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
114 final boolean[] result = new boolean[] { false };
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
115 hgRepo.getChangelog().walk(0/*rootIndexes[0]*/, csetRevIndex, new HgChangelog.ParentInspector() {
445
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 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
118 boolean descendant = false;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 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
120 parents2consider.add(revision);
445
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 descendant = true;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 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
124 parents2consider.add(revision);
445
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 descendant = true;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 if (descendant && revisionIndex == csetRevIndex) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 // 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
129 result[0] = true;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 }
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 if (result[0]) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 return phase;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 }
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 return HgPhase.Public;
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 }
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 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
144 int[] rv = new int[roots.size()];
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 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
146 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
147 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 return rv;
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
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 private Boolean readRoots() throws HgInvalidControlFileException {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 // 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
153 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
154 try {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 if (!phaseroots.exists()) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 return Boolean.FALSE;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 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
159 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
160 String line;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 while ((line = br.readLine()) != null) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 String[] lc = line.trim().split("\\s+");
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 if (lc.length == 0) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 continue;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 if (lc.length != 2) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 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
168 continue;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 int phaseIndex = Integer.parseInt(lc[0]);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 Nodeid rootRev = Nodeid.fromAscii(lc[1]);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 HgPhase phase = HgPhase.parse(phaseIndex);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 List<Nodeid> roots = phase2roots.get(phase);
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 if (roots == null) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 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
176 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 roots.add(rootRev);
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 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
180 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
181 } catch (IOException ex) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 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
183 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 return Boolean.TRUE;
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
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 private List<Nodeid> getPhaseRoots(HgPhase phase) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 switch (phase) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 case Draft : return draftPhaseRoots;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 case Secret : return secretPhaseRoots;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 return Collections.emptyList();
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 }