annotate src/org/tmatesoft/hg/repo/HgPhase.java @ 658:d10399f80f4e

javac complained about casts, while eclipse compiler is fine
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 04 Jul 2013 21:09:33 +0200
parents cd77bf51b562
children
rev   line source
445
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
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.repo;
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 /**
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 * Phases for a changeset is a new functionality in Mercurial 2.1
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 *
626
5afc7eedb3dd @since, TODOs. Tests: add 1 sec to deal with fs timestamp granularity on linux
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 474
diff changeset
22 * @since 1.1
445
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 * @author Artem Tikhomirov
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 * @author TMate Software Ltd.
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 */
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 public enum HgPhase {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 Public("public"), Draft("draft"), Secret("secret"), Undefined("");
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 private final String hgString;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 private HgPhase(String stringRepresentation) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 hgString = stringRepresentation;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 // public String toMercurialString() {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 // return hgString;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 // }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 public static HgPhase parse(int value) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 switch (value) {
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 case 0 : return Public;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 case 1 : return Draft;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 case 2 : return Secret;
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 }
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 throw new IllegalArgumentException(String.format("Bad phase index: %d", value));
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 }
474
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
48
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
49 public static HgPhase parse(String value) {
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
50 if (Public.hgString.equals(value)) {
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
51 return Public;
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
52 }
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
53 if (Draft.hgString.equals(value)) {
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
54 return Draft;
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
55 }
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
56 if (Secret.hgString.equals(value)) {
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
57 return Secret;
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
58 }
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
59 throw new IllegalArgumentException(String.format("Bad phase name: %d", value));
09f2d38ecf26 Tests for phases support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 445
diff changeset
60 }
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
61
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
62 /**
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
63 * @return integer value Mercurial uses to identify the phase
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
64 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
65 public int mercurialOrdinal() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
66 if (this == Undefined) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
67 throw new IllegalStateException("Undefined phase is an artifical value, which doesn't possess a valid native mercurial ordinal");
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
68 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
69 return ordinal(); // what a coincidence
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
70 }
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: 649
diff changeset
71
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: 649
diff changeset
72 public String mercurialString() {
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: 649
diff changeset
73 return hgString;
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: 649
diff changeset
74 }
445
d0e5dc3cae6e Support for phases functionality from Mercurial 2.1
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 }