Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/PhasesHelper.java @ 657:6334b0267103
ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 20:27:45 +0200 |
parents | 12a4f60ea972 |
children | 46b56864b483 |
rev | line source |
---|---|
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
2 * Copyright (c) 2012-2013 TMate Software Ltd |
445
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; |
647
c75297c17867
Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
21 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Phaseroots; |
471
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.File; |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
25 import java.io.FileWriter; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.io.IOException; |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
27 import java.util.ArrayList; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
28 import java.util.Collection; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.Collections; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.util.HashMap; |
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; |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
35 import org.tmatesoft.hg.core.HgIOException; |
445
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; |
471
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.HgInvalidControlFileException; |
652
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
39 import org.tmatesoft.hg.repo.HgInvalidStateException; |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
40 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
|
41 import org.tmatesoft.hg.repo.HgPhase; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 import org.tmatesoft.hg.repo.HgRepository; |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
43 import org.tmatesoft.hg.repo.HgRuntimeException; |
445
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 /** |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
46 * Support to deal with Mercurial phases feature (as of Mercurial version 2.1) |
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
47 * |
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
48 * @see http://mercurial.selenic.com/wiki/Phases |
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
474
diff
changeset
|
49 * @see http://mercurial.selenic.com/wiki/PhasesDevel |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 * |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 * @author Artem Tikhomirov |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 * @author TMate Software Ltd. |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 */ |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 public final class PhasesHelper { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
56 private final Internals repo; |
471
7bcfbc255f48
Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
451
diff
changeset
|
57 private final HgParentChildMap<HgChangelog> parentHelper; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 private Boolean repoSupporsPhases; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 private List<Nodeid> draftPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 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
|
61 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
|
62 |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
63 public PhasesHelper(Internals internalRepo) { |
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
64 this(internalRepo, null); |
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 |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
67 public PhasesHelper(Internals internalRepo, HgParentChildMap<HgChangelog> pw) { |
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
68 repo = internalRepo; |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 parentHelper = pw; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 } |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
71 |
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
72 public HgRepository getRepo() { |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
73 return repo.getRepo(); |
474
09f2d38ecf26
Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
471
diff
changeset
|
74 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
76 public boolean isCapableOfPhases() throws HgRuntimeException { |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 if (null == repoSupporsPhases) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 repoSupporsPhases = readRoots(); |
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 return repoSupporsPhases.booleanValue(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
650
3b275cc2d2aa
Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
649
diff
changeset
|
82 |
3b275cc2d2aa
Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
649
diff
changeset
|
83 public boolean withSecretRoots() { |
3b275cc2d2aa
Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
649
diff
changeset
|
84 return !secretPhaseRoots.isEmpty(); |
3b275cc2d2aa
Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
649
diff
changeset
|
85 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
87 /** |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
88 * @param cset revision to query |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
89 * @return phase of the changeset, never <code>null</code> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
90 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
91 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
92 */ |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
93 public HgPhase getPhase(HgChangeset cset) throws HgRuntimeException { |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 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
|
95 final int csetRevIndex = cset.getRevisionIndex(); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 return getPhase(csetRevIndex, csetRev); |
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 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
99 /** |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
100 * @param csetRevIndex revision index to query |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
101 * @param csetRev revision nodeid, optional |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
102 * @return phase of the changeset, never <code>null</code> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
103 * @throws HgInvalidControlFileException if failed to access revlog index/data entry. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
104 * @throws HgRuntimeException subclass thereof to indicate other issues with the library. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
105 */ |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
106 public HgPhase getPhase(final int csetRevIndex, Nodeid csetRev) throws HgRuntimeException { |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 if (!isCapableOfPhases()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 return HgPhase.Undefined; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
110 // 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
|
111 if (parentHelper != null && (csetRev == null || csetRev.isNull())) { |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
112 csetRev = getRepo().getChangelog().getRevision(csetRevIndex); |
445
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 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
|
116 List<Nodeid> roots = getPhaseRoots(phase); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 if (roots.isEmpty()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 continue; |
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 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
|
121 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
|
122 return phase; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
123 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 if (parentHelper.childrenOf(roots).contains(csetRev)) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 return phase; |
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 } else { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 // 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
|
129 // 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
|
130 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
|
131 // 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
|
132 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
|
133 return phase; |
445
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 } |
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; |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
139 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
141 |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
142 /** |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
143 * @return all revisions with secret phase |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
144 */ |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
145 public RevisionSet allSecret() { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
146 return allOf(HgPhase.Secret); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
147 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
148 |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
149 /** |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
150 * @return all revisions with draft phase |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
151 */ |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
152 public RevisionSet allDraft() { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
153 return allOf(HgPhase.Draft).subtract(allOf(HgPhase.Secret)); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
154 } |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
155 |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
156 public void updateRoots(Collection<Nodeid> draftRoots, Collection<Nodeid> secretRoots) throws HgInvalidControlFileException { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
157 draftPhaseRoots = draftRoots.isEmpty() ? Collections.<Nodeid>emptyList() : new ArrayList<Nodeid>(draftRoots); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
158 secretPhaseRoots = secretRoots.isEmpty() ? Collections.<Nodeid>emptyList() : new ArrayList<Nodeid>(secretRoots); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
159 String fmt = "%d %s\n"; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
160 File phaseroots = repo.getRepositoryFile(Phaseroots); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
161 FileWriter fw = null; |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
162 try { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
163 fw = new FileWriter(phaseroots); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
164 for (Nodeid n : secretPhaseRoots) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
165 fw.write(String.format(fmt, HgPhase.Secret.mercurialOrdinal(), n.toString())); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
166 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
167 for (Nodeid n : draftPhaseRoots) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
168 fw.write(String.format(fmt, HgPhase.Draft.mercurialOrdinal(), n.toString())); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
169 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
170 fw.flush(); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
171 } catch (IOException ex) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
172 throw new HgInvalidControlFileException(ex.getMessage(), ex, phaseroots); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
173 } finally { |
654
12a4f60ea972
1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
652
diff
changeset
|
174 new FileUtils(repo.getLog(), this).closeQuietly(fw); |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
175 } |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
176 } |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
177 |
652
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
178 public void newCommitNode(Nodeid newChangeset, HgPhase newCommitPhase) throws HgRuntimeException { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
179 final int riCset = repo.getRepo().getChangelog().getRevisionIndex(newChangeset); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
180 HgPhase ph = getPhase(riCset, newChangeset); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
181 if (ph.compareTo(newCommitPhase) >= 0) { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
182 // present phase is more secret than the desired one |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
183 return; |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
184 } |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
185 // newCommitPhase can't be public here, condition above would be satisfied |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
186 assert newCommitPhase != HgPhase.Public; |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
187 // ph is e.g public when newCommitPhase is draft |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
188 // or is draft when desired phase is secret |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
189 final RevisionSet rs = allOf(newCommitPhase).union(new RevisionSet(Collections.singleton(newChangeset))); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
190 final RevisionSet newRoots; |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
191 if (parentHelper != null) { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
192 newRoots = rs.roots(parentHelper); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
193 } else { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
194 newRoots = rs.roots(repo.getRepo()); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
195 } |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
196 if (newCommitPhase == HgPhase.Draft) { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
197 updateRoots(newRoots.asList(), secretPhaseRoots); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
198 } else if (newCommitPhase == HgPhase.Secret) { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
199 updateRoots(draftPhaseRoots, newRoots.asList()); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
200 } else { |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
201 throw new HgInvalidStateException(String.format("Unexpected phase %s for new commits", newCommitPhase)); |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
202 } |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
203 } |
cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
650
diff
changeset
|
204 |
648
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
205 /** |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
206 * For a given phase, collect all revisions with phase that is the same or more private (i.e. for Draft, returns Draft+Secret) |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
207 * The reason is not a nice API intention (which is awful, indeed), but an ease of implementation |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
208 */ |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
209 private RevisionSet allOf(HgPhase phase) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
210 assert phase != HgPhase.Public; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
211 if (!isCapableOfPhases()) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
212 return new RevisionSet(Collections.<Nodeid>emptyList()); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
213 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
214 final List<Nodeid> roots = getPhaseRoots(phase); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
215 if (parentHelper != null) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
216 return new RevisionSet(roots).union(new RevisionSet(parentHelper.childrenOf(roots))); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
217 } else { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
218 RevisionSet rv = new RevisionSet(Collections.<Nodeid>emptyList()); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
219 for (RevisionDescendants rd : getPhaseDescendants(phase)) { |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
220 rv = rv.union(rd.asRevisionSet()); |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
221 } |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
222 return rv; |
690e71d29bf6
Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
223 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
224 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
225 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
226 private Boolean readRoots() throws HgRuntimeException { |
647
c75297c17867
Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
227 File phaseroots = repo.getRepositoryFile(Phaseroots); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
228 try { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
229 if (!phaseroots.exists()) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
230 return Boolean.FALSE; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 } |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
232 LineReader lr = new LineReader(phaseroots, repo.getLog()); |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
233 final Collection<String> lines = lr.read(new LineReader.SimpleLineCollector(), new LinkedList<String>()); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 HashMap<HgPhase, List<Nodeid>> phase2roots = new HashMap<HgPhase, List<Nodeid>>(); |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
235 for (String line : lines) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
236 String[] lc = line.split("\\s+"); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
237 if (lc.length == 0) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 continue; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
239 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
240 if (lc.length != 2) { |
501
d2f6ab541330
Change the way extensions are accessed (with ExtensionsManager now), add preliminary Rebase extension support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
493
diff
changeset
|
241 repo.getSessionContext().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
|
242 continue; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
243 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
244 int phaseIndex = Integer.parseInt(lc[0]); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
245 Nodeid rootRev = Nodeid.fromAscii(lc[1]); |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
246 if (!getRepo().getChangelog().isKnown(rootRev)) { |
501
d2f6ab541330
Change the way extensions are accessed (with ExtensionsManager now), add preliminary Rebase extension support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
493
diff
changeset
|
247 repo.getSessionContext().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
|
248 continue; |
39fe00407937
HgBadStateException in ParentWalker.assertSortedIndex when phaseroots lists non-existent revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
449
diff
changeset
|
249 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
250 HgPhase phase = HgPhase.parse(phaseIndex); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
251 List<Nodeid> roots = phase2roots.get(phase); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
252 if (roots == null) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
253 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
|
254 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
255 roots.add(rootRev); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
257 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
|
258 secretPhaseRoots = phase2roots.containsKey(Secret) ? phase2roots.get(Secret) : Collections.<Nodeid>emptyList(); |
649
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
259 } catch (HgIOException ex) { |
e79cf9a8130b
Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
648
diff
changeset
|
260 throw new HgInvalidControlFileException(ex, true); |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
261 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 return Boolean.TRUE; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 private List<Nodeid> getPhaseRoots(HgPhase phase) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
266 switch (phase) { |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
267 case Draft : return draftPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
268 case Secret : return secretPhaseRoots; |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
269 } |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
270 return Collections.emptyList(); |
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 } |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
272 |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
273 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
274 private RevisionDescendants[] getPhaseDescendants(HgPhase phase) throws HgRuntimeException { |
447
056f724bdc21
Cache earliest phase root revision not to evaluate all the time
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
446
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 } |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
279 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
|
280 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
281 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
282 private RevisionDescendants[] buildPhaseDescendants(HgPhase phase) throws HgRuntimeException { |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
283 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
|
284 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
|
285 for (int i = 0; i < roots.length; i++) { |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
286 rv[i] = new RevisionDescendants(getRepo(), roots[i]); |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
287 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
|
288 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
289 return rv; |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
290 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
291 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
501
diff
changeset
|
292 private int[] toIndexes(List<Nodeid> roots) throws HgRuntimeException { |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
293 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
|
294 for (int i = 0; i < rv.length; i++) { |
493
ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
295 rv[i] = getRepo().getChangelog().getRevisionIndex(roots.get(i)); |
449
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
296 } |
5787e912f60e
Speed up changeset phase detection when no parent cache is avalable
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
448
diff
changeset
|
297 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
|
298 } |
445
d0e5dc3cae6e
Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
299 } |