comparison src/org/tmatesoft/hg/core/HgChangeset.java @ 403:2747b0723867

FIXMEs: work on exceptions and javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 05 Mar 2012 14:50:51 +0100
parents 9517df1ef7ec
children ee8264d80747
comparison
equal deleted inserted replaced
402:1fcc7f7b6d65 403:2747b0723867
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2012 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
76 throw new IllegalArgumentException(); 76 throw new IllegalArgumentException();
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 /**
82 * Index of the changeset in local repository. Note, this number is relevant only for local repositories/operations, use
83 * {@link Nodeid nodeid} to uniquely identify a revision.
84 *
85 * @return index of the changeset revision
86 */
87 public int getRevisionIndex() {
88 return revNumber;
89 }
90
91 /**
92 * @deprecated use {@link #getRevisionIndex()}
93 */
94 @Deprecated
81 public int getRevision() { 95 public int getRevision() {
82 return revNumber; 96 return revNumber;
83 } 97 }
98
99 /**
100 * Unique identity of this changeset revision
101 * @return revision identifier, never <code>null</code>
102 */
84 public Nodeid getNodeid() { 103 public Nodeid getNodeid() {
85 return nodeid; 104 return nodeid;
86 } 105 }
106
107 /**
108 * Name of the user who made this commit
109 * @return author of the commit, never <code>null</code>
110 */
87 public String getUser() { 111 public String getUser() {
88 return changeset.user(); 112 return changeset.user();
89 } 113 }
114
115 /**
116 * Commit description
117 * @return content of the corresponding field in changeset record; empty string if none specified.
118 */
90 public String getComment() { 119 public String getComment() {
91 return changeset.comment(); 120 return changeset.comment();
92 } 121 }
122
123 /**
124 * Name of the branch this commit was made in. Returns "default" for main branch.
125 * @return name of the branch, non-empty string
126 */
93 public String getBranch() { 127 public String getBranch() {
94 return changeset.branch(); 128 return changeset.branch();
95 } 129 }
96 130
97 /** 131 /**
98 * @return used to be String, now {@link HgDate}, use {@link HgDate#toString()} to get same result as before 132 * @return used to be String, now {@link HgDate}, use {@link HgDate#toString()} to get same result as before
99 */ 133 */
100 public HgDate getDate() { 134 public HgDate getDate() {
101 return new HgDate(changeset.date().getTime(), changeset.timezone()); 135 return new HgDate(changeset.date().getTime(), changeset.timezone());
102 } 136 }
137
138 /**
139 * Indicates revision of manifest that tracks state of repository at the moment of this commit.
140 * Note, may be {@link Nodeid#NULL} in certain scenarios (e.g. first changeset in an empty repository, usually by bogus tools)
141 *
142 * @return revision identifier, never <code>null</code>
143 */
103 public Nodeid getManifestRevision() { 144 public Nodeid getManifestRevision() {
104 return changeset.manifest(); 145 return changeset.manifest();
105 } 146 }
106 147
148 /**
149 * Lists names of files affected by this commit, as recorded in the changeset itself. Unlike {@link #getAddedFiles()},
150 * {@link #getModifiedFiles()} and {@link #getRemovedFiles()}, this method doesn't analyze actual changes done
151 * in the commit, rather extracts value from the changeset record.
152 *
153 * List returned by this method may be empty, while aforementioned methods may produce non-empty result.
154 *
155 * @return list of filenames, never <code>null</code>
156 */
107 public List<Path> getAffectedFiles() { 157 public List<Path> getAffectedFiles() {
108 // reports files as recorded in changelog. Note, merge revisions may have no 158 // reports files as recorded in changelog. Note, merge revisions may have no
109 // files listed, and thus this method would return empty list, while 159 // files listed, and thus this method would return empty list, while
110 // #getModifiedFiles() would return list with merged file(s) (because it uses status to get 'em, not 160 // #getModifiedFiles() would return list with merged file(s) (because it uses status to get 'em, not
111 // what #files() gives). 161 // what #files() gives).
114 rv.add(pathHelper.path(name)); 164 rv.add(pathHelper.path(name));
115 } 165 }
116 return rv; 166 return rv;
117 } 167 }
118 168
119 public List<HgFileRevision> getModifiedFiles() throws HgInvalidControlFileException { 169 /**
170 * Figures out files and specific revisions thereof that were modified in this commit
171 *
172 * @return revisions of files modified in this commit
173 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
174 * @throws HgException in case of some other library issue
175 */
176 public List<HgFileRevision> getModifiedFiles() throws HgException {
120 if (modifiedFiles == null) { 177 if (modifiedFiles == null) {
121 initFileChanges(); 178 initFileChanges();
122 } 179 }
123 return modifiedFiles; 180 return modifiedFiles;
124 } 181 }
125 182
126 public List<HgFileRevision> getAddedFiles() throws HgInvalidControlFileException { 183 /**
184 * Figures out files added in this commit
185 *
186 * @return revisions of files added in this commit
187 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
188 * @throws HgException in case of some other library issue
189 */
190 public List<HgFileRevision> getAddedFiles() throws HgException {
127 if (addedFiles == null) { 191 if (addedFiles == null) {
128 initFileChanges(); 192 initFileChanges();
129 } 193 }
130 return addedFiles; 194 return addedFiles;
131 } 195 }
132 196
133 public List<Path> getRemovedFiles() throws HgInvalidControlFileException { 197 /**
198 * Figures out files that were deleted as part of this commit
199 *
200 * @return revisions of files deleted in this commit
201 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
202 * @throws HgException in case of some other library issue
203 */
204 public List<Path> getRemovedFiles() throws HgException {
134 if (deletedFiles == null) { 205 if (deletedFiles == null) {
135 initFileChanges(); 206 initFileChanges();
136 } 207 }
137 return deletedFiles; 208 return deletedFiles;
138 } 209 }
173 statusHelper.getRepo().getChangelog().parents(revNumber, new int[2], parent1, parent2); 244 statusHelper.getRepo().getChangelog().parents(revNumber, new int[2], parent1, parent2);
174 } 245 }
175 return Nodeid.fromBinary(parent2, 0); 246 return Nodeid.fromBinary(parent2, 0);
176 } 247 }
177 248
249 /**
250 * Create a copy of this changeset
251 */
178 @Override 252 @Override
179 public HgChangeset clone() { 253 public HgChangeset clone() {
180 try { 254 try {
181 HgChangeset copy = (HgChangeset) super.clone(); 255 HgChangeset copy = (HgChangeset) super.clone();
182 // copy.changeset references this.changeset, doesn't need own copy 256 // copy.changeset references this.changeset, doesn't need own copy
184 } catch (CloneNotSupportedException ex) { 258 } catch (CloneNotSupportedException ex) {
185 throw new InternalError(ex.toString()); 259 throw new InternalError(ex.toString());
186 } 260 }
187 } 261 }
188 262
189 private /*synchronized*/ void initFileChanges() throws HgInvalidControlFileException { 263 private /*synchronized*/ void initFileChanges() throws HgException {
190 ArrayList<Path> deleted = new ArrayList<Path>(); 264 ArrayList<Path> deleted = new ArrayList<Path>();
191 ArrayList<HgFileRevision> modified = new ArrayList<HgFileRevision>(); 265 ArrayList<HgFileRevision> modified = new ArrayList<HgFileRevision>();
192 ArrayList<HgFileRevision> added = new ArrayList<HgFileRevision>(); 266 ArrayList<HgFileRevision> added = new ArrayList<HgFileRevision>();
193 HgStatusCollector.Record r = new HgStatusCollector.Record(); 267 HgStatusCollector.Record r = new HgStatusCollector.Record();
194 statusHelper.change(revNumber, r); 268 statusHelper.change(revNumber, r);
195 final HgRepository repo = statusHelper.getRepo(); 269 final HgRepository repo = statusHelper.getRepo();
196 for (Path s : r.getModified()) { 270 for (Path s : r.getModified()) {
197 Nodeid nid = r.nodeidAfterChange(s); 271 Nodeid nid = r.nodeidAfterChange(s);
198 if (nid == null) { 272 if (nid == null) {
199 throw new HgBadStateException(); 273 throw new HgException(String.format("For the file %s recorded as modified couldn't find revision after change", s));
200 } 274 }
201 modified.add(new HgFileRevision(repo, nid, s, null)); 275 modified.add(new HgFileRevision(repo, nid, s, null));
202 } 276 }
203 final Map<Path, Path> copied = r.getCopied(); 277 final Map<Path, Path> copied = r.getCopied();
204 for (Path s : r.getAdded()) { 278 for (Path s : r.getAdded()) {
205 Nodeid nid = r.nodeidAfterChange(s); 279 Nodeid nid = r.nodeidAfterChange(s);
206 if (nid == null) { 280 if (nid == null) {
207 throw new HgBadStateException(); 281 throw new HgException(String.format("For the file %s recorded as added couldn't find revision after change", s));
208 } 282 }
209 added.add(new HgFileRevision(repo, nid, s, copied.get(s))); 283 added.add(new HgFileRevision(repo, nid, s, copied.get(s)));
210 } 284 }
211 for (Path s : r.getRemoved()) { 285 for (Path s : r.getRemoved()) {
212 // with Path from getRemoved, may just copy 286 // with Path from getRemoved, may just copy