Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/PhasesHelper.java @ 474:09f2d38ecf26
Tests for phases support
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 12 Jul 2012 15:36:21 +0200 |
parents | 7bcfbc255f48 |
children | b3c16d1aede0 |
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; |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
21 import static org.tmatesoft.hg.util.LogFacility.Severity.Info; |
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.BufferedReader; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.File; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.io.FileReader; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.io.IOException; |
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.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.Nodeid; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.repo.HgChangelog; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import org.tmatesoft.hg.repo.HgInternals; |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
37 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
38 import org.tmatesoft.hg.repo.HgParentChildMap; |
445
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 |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
50 private final HgRepository repo; |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
51 private final HgParentChildMap<HgChangelog> parentHelper; |
445
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; |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
55 private RevisionDescendants[][] phaseDescendants = new RevisionDescendants[HgPhase.values().length][]; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
57 public PhasesHelper(HgRepository hgRepo) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
58 this(hgRepo, null); |
445
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 |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
61 public PhasesHelper(HgRepository hgRepo, HgParentChildMap<HgChangelog> pw) { |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
62 repo = hgRepo; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 parentHelper = pw; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
65 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
66 public HgRepository getRepo() { |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
67 return repo; |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
68 } |
445
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 public boolean isCapableOfPhases() throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 if (null == repoSupporsPhases) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 repoSupporsPhases = readRoots(); |
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 return repoSupporsPhases.booleanValue(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
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(HgChangeset cset) throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 final Nodeid csetRev = cset.getNodeid(); |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
80 final int csetRevIndex = cset.getRevisionIndex(); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 return getPhase(csetRevIndex, csetRev); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 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
|
85 if (!isCapableOfPhases()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 return HgPhase.Undefined; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
88 // csetRev is only used when parentHelper is available |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
89 if (parentHelper != null && (csetRev == null || csetRev.isNull())) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
90 csetRev = repo.getChangelog().getRevision(csetRevIndex); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 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
|
94 List<Nodeid> roots = getPhaseRoots(phase); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 if (roots.isEmpty()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 continue; |
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 if (parentHelper != null) { |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
99 if (roots.contains(csetRev)) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
100 return phase; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
101 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 if (parentHelper.childrenOf(roots).contains(csetRev)) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 return phase; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } else { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 // no parent helper |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
107 // search all descendants.RevisuionDescendats includes root as well. |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
108 for (RevisionDescendants rd : getPhaseDescendants(phase)) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
109 // isCandidate is to go straight to another root if changeset was added later that the current root |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
110 if (rd.isCandidate(csetRevIndex) && rd.isDescendant(csetRevIndex)) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
111 return phase; |
445
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 } |
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 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 return HgPhase.Public; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 |
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 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 private Boolean readRoots() throws HgInvalidControlFileException { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 // FIXME shall access phaseroots through HgRepository#repoPathHelper |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
122 File phaseroots = new File(HgInternals.getRepositoryDir(repo), "store/phaseroots"); |
451
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
123 BufferedReader br = null; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 try { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 if (!phaseroots.exists()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 return Boolean.FALSE; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 HashMap<HgPhase, List<Nodeid>> phase2roots = new HashMap<HgPhase, List<Nodeid>>(); |
451
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
129 br = new BufferedReader(new FileReader(phaseroots)); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 String line; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 while ((line = br.readLine()) != null) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 String[] lc = line.trim().split("\\s+"); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 if (lc.length == 0) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 continue; |
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 if (lc.length != 2) { |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
137 HgInternals.getContext(repo).getLog().dump(getClass(), Warn, "Bad line in phaseroots:%s", line); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 continue; |
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 int phaseIndex = Integer.parseInt(lc[0]); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 Nodeid rootRev = Nodeid.fromAscii(lc[1]); |
451
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
142 if (!repo.getChangelog().isKnown(rootRev)) { |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
143 HgInternals.getContext(repo).getLog().dump(getClass(), Warn, "Phase(%d) root node %s doesn't exist in the repository, ignored.", phaseIndex, rootRev); |
451
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
144 continue; |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
145 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 HgPhase phase = HgPhase.parse(phaseIndex); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 List<Nodeid> roots = phase2roots.get(phase); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 if (roots == null) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 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
|
150 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 roots.add(rootRev); |
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 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
|
154 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
|
155 } catch (IOException ex) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 throw new HgInvalidControlFileException(ex.toString(), ex, phaseroots); |
451
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
157 } finally { |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
158 if (br != null) { |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
159 try { |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
160 br.close(); |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
161 } catch (IOException ex) { |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
162 HgInternals.getContext(repo).getLog().dump(getClass(), Info, ex, null); |
451
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
163 // ignore the exception otherwise |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
164 } |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
165 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 return Boolean.TRUE; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 } |
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 private List<Nodeid> getPhaseRoots(HgPhase phase) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 switch (phase) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 case Draft : return draftPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 case Secret : return secretPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 return Collections.emptyList(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 } |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
177 |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
178 |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
179 private RevisionDescendants[] getPhaseDescendants(HgPhase phase) throws HgInvalidControlFileException { |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
180 int ordinal = phase.ordinal(); |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
181 if (phaseDescendants[ordinal] == null) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
182 phaseDescendants[ordinal] = buildPhaseDescendants(phase); |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
183 } |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
184 return phaseDescendants[ordinal]; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
185 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
186 |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
187 private RevisionDescendants[] buildPhaseDescendants(HgPhase phase) throws HgInvalidControlFileException { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
188 int[] roots = toIndexes(getPhaseRoots(phase)); |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
189 RevisionDescendants[] rv = new RevisionDescendants[roots.length]; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
190 for (int i = 0; i < roots.length; i++) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
191 rv[i] = new RevisionDescendants(repo, roots[i]); |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
192 rv[i].build(); |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
193 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
194 return rv; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
195 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
196 |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
197 private int[] toIndexes(List<Nodeid> roots) throws HgInvalidControlFileException { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
198 int[] rv = new int[roots.size()]; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
199 for (int i = 0; i < rv.length; i++) { |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
200 rv[i] = repo.getChangelog().getRevisionIndex(roots.get(i)); |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
201 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
202 return rv; |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
203 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 } |