annotate src/org/tmatesoft/hg/repo/HgSubrepoLocation.java @ 434:7e1912b4ce99 v0.9.0

Record few known issues while skimming through TODOs
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 30 Mar 2012 17:11:39 +0200
parents 9c9c442b5f2e
children 6865eb742883
rev   line source
239
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
239
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.repo;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.File;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
21 import org.tmatesoft.hg.core.HgRepositoryNotFoundException;
239
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.internal.Experimental;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.util.Path;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 /**
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 * WORK IN PROGRESS, DO NOT USE
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 * @author Artem Tikhomirov
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 * @author TMate Software Ltd.
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 */
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 @Experimental(reason="Work in progress")
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 public class HgSubrepoLocation {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 private final HgRepository owner;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 private final Kind kind;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 private final Path location;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 private final String source;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 private final String revInfo;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 public enum Kind { Hg, SVN, Git, }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public HgSubrepoLocation(HgRepository parentRepo, String repoLocation, String actualLocation, Kind type, String revision) {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 owner = parentRepo;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 location = Path.create(repoLocation);
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 source = actualLocation;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 kind = type;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 revInfo = revision;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 // as defined in .hgsub, key value
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public Path getLocation() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 return location;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 // value from .hgsub
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public String getSource() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 return source;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 public Kind getType() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 return kind;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 public String getRevision() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 return revInfo;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 /**
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 * @return whether this sub repository is known only locally
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 */
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 public boolean isCommitted() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 return revInfo != null;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 /**
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 * @return <code>true</code> when there are local changes in the sub repository
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 */
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 public boolean hasChanges() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 throw HgRepository.notImplemented();
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 // public boolean isLocal() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 // }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 public HgRepository getOwner() {
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 return owner;
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
88 /**
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
89 *
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
90 * @return object to access sub-repository
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
91 * @throws HgRepositoryNotFoundException if failed to find repository
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
92 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
93 */
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
94 public HgRepository getRepo() throws HgRepositoryNotFoundException {
239
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 if (kind != Kind.Hg) {
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
96 throw new HgInvalidStateException(String.format("Unsupported subrepository %s", kind));
239
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 return new HgLookup().detect(new File(owner.getWorkingDir(), source));
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
df9d2854d3d6 Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }