comparison src/org/tmatesoft/hg/repo/HgSubrepoLocation.java @ 442:6865eb742883

Tests for subrepo API, refactor status tests for reuse, better subrepos API
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 27 Apr 2012 20:57:20 +0200
parents 9c9c442b5f2e
children 51d682cf9cdc
comparison
equal deleted inserted replaced
441:2a08466838d3 442:6865eb742883
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import java.io.File; 19 import java.io.File;
20 20
21 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; 21 import org.tmatesoft.hg.core.HgRepositoryNotFoundException;
22 import org.tmatesoft.hg.core.Nodeid;
22 import org.tmatesoft.hg.internal.Experimental; 23 import org.tmatesoft.hg.internal.Experimental;
23 import org.tmatesoft.hg.util.Path; 24 import org.tmatesoft.hg.util.Path;
24 25
25 /** 26 /**
26 * WORK IN PROGRESS, DO NOT USE 27 * WORK IN PROGRESS, DO NOT USE
28 *
29 * @see http://mercurial.selenic.com/wiki/Subrepository
27 * @author Artem Tikhomirov 30 * @author Artem Tikhomirov
28 * @author TMate Software Ltd. 31 * @author TMate Software Ltd.
29 */ 32 */
30 @Experimental(reason="Work in progress") 33 @Experimental(reason="Work in progress")
31 public class HgSubrepoLocation { 34 public class HgSubrepoLocation {
32 35
33 private final HgRepository owner; 36 private final HgRepository owner;
34 private final Kind kind; 37 private final Kind kind;
35 private final Path location; 38 private final Path location;
36 private final String source; 39 private final String source;
37 private final String revInfo; 40 private final Nodeid revInfo;
38 41
39 public enum Kind { Hg, SVN, Git, } 42 public enum Kind { Hg, SVN, Git, }
40 43
41 public HgSubrepoLocation(HgRepository parentRepo, String repoLocation, String actualLocation, Kind type, String revision) { 44 /**
45 *
46 * @param parentRepo
47 * @param repoLocation path, shall be valid directory (i.e. even if .hgsub doesn't specify trailing slash, this one shall)
48 * @param actualLocation
49 * @param type
50 * @param revision may be <code>null</code>
51 */
52 /*package-local*/ HgSubrepoLocation(HgRepository parentRepo, Path repoLocation, String actualLocation, Kind type, Nodeid revision) {
42 owner = parentRepo; 53 owner = parentRepo;
43 location = Path.create(repoLocation); 54 location = repoLocation;
44 source = actualLocation; 55 source = actualLocation;
45 kind = type; 56 kind = type;
46 revInfo = revision; 57 revInfo = revision;
47 } 58 }
48 59
49 // as defined in .hgsub, key value 60 /**
61 * Sub-repository's location within owning repository, always directory, <code>path/to/nested</code>.
62 * <p>
63 * May differ from left-hand, key value from <code>.hgsub</code> if the latter doesn't include trailing slash, which is required
64 * for {@link Path} objects
65 *
66 * @return path to nested repository relative to owner's location
67 */
50 public Path getLocation() { 68 public Path getLocation() {
51 return location; 69 return location;
52 } 70 }
53 71
54 // value from .hgsub 72 /**
73 * Right-hand value from <code>.hgsub</code>, with <code>[kind]</code> stripped, if any.
74 * @return sub-repository's source
75 */
55 public String getSource() { 76 public String getSource() {
56 return source; 77 return source;
57 } 78 }
58 79
80 /**
81 * Sub-repository kind, either Mercurial, Subversion or Git
82 * @return one of predefined constants
83 */
59 public Kind getType() { 84 public Kind getType() {
60 return kind; 85 return kind;
61 } 86 }
62 87
63 public String getRevision() { 88 /**
89 * For a nested repository that has been committed at least once, returns
90 * its revision as known from <code>.hgsubstate</code>
91 *
92 * <p>Note, this revision belongs to the nested repository history, not that of owning repository.
93 *
94 * @return revision of the nested repository, or <code>null</code> if not yet committed
95 */
96 public Nodeid getRevision() {
64 return revInfo; 97 return revInfo;
65 } 98 }
66 99
67 /** 100 /**
68 * @return whether this sub repository is known only locally 101 * Answers whether this sub repository has ever been part of a commit of the owner repository
102 *
103 * @return <code>true</code> if owning repository records {@link #getRevision() revision} of this sub-repository
69 */ 104 */
70 public boolean isCommitted() { 105 public boolean isCommitted() {
71 return revInfo != null; 106 return revInfo != null;
72 } 107 }
73 108
74 /** 109 /**
75 * @return <code>true</code> when there are local changes in the sub repository 110 * Answers whether there are local changes in the sub-repository,
111 * @return <code>true</code> if it's dirty
76 */ 112 */
77 public boolean hasChanges() { 113 public boolean hasChanges() {
78 throw HgRepository.notImplemented(); 114 throw HgRepository.notImplemented();
79 } 115 }
80 116
81 // public boolean isLocal() { 117 /**
82 // } 118 * Access repository that owns nested one described by this object
83 119 */
84 public HgRepository getOwner() { 120 public HgRepository getOwner() {
85 return owner; 121 return owner;
86 } 122 }
87 123
88 /** 124 /**
125 * Access nested repository as a full-fledged Mercurial repository
89 * 126 *
90 * @return object to access sub-repository 127 * @return object to access sub-repository
91 * @throws HgRepositoryNotFoundException if failed to find repository 128 * @throws HgRepositoryNotFoundException if failed to find repository
92 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> 129 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
93 */ 130 */