Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 482:6c67debed07e
Distinguish files in wc from files under repo root, use these constants
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 07 Aug 2012 14:27:13 +0200 |
parents | a458f9fb00ce |
children | e31e85cf4d4c |
comparison
equal
deleted
inserted
replaced
481:a458f9fb00ce | 482:6c67debed07e |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.repo; | 17 package org.tmatesoft.hg.repo; |
18 | 18 |
19 import static org.tmatesoft.hg.repo.HgRepositoryFiles.*; | |
19 import static org.tmatesoft.hg.util.LogFacility.Severity.*; | 20 import static org.tmatesoft.hg.util.LogFacility.Severity.*; |
20 | 21 |
21 import java.io.File; | 22 import java.io.File; |
22 import java.io.FileReader; | 23 import java.io.FileReader; |
23 import java.io.IOException; | 24 import java.io.IOException; |
188 manifest = new HgManifest(this, content, impl.buildFileNameEncodingHelper()); | 189 manifest = new HgManifest(this, content, impl.buildFileNameEncodingHelper()); |
189 } | 190 } |
190 return manifest; | 191 return manifest; |
191 } | 192 } |
192 | 193 |
194 /** | |
195 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> | |
196 */ | |
193 public HgTags getTags() throws HgInvalidControlFileException { | 197 public HgTags getTags() throws HgInvalidControlFileException { |
194 if (tags == null) { | 198 if (tags == null) { |
195 tags = new HgTags(this); | 199 tags = new HgTags(this); |
196 HgDataFile hgTags = getFileNode(".hgtags"); | 200 HgDataFile hgTags = getFileNode(HgTags.getPath()); |
197 if (hgTags.exists()) { | 201 if (hgTags.exists()) { |
198 for (int i = 0; i <= hgTags.getLastRevision(); i++) { // TODO post-1.0 in fact, would be handy to have walk(start,end) | 202 for (int i = 0; i <= hgTags.getLastRevision(); i++) { // TODO post-1.0 in fact, would be handy to have walk(start,end) |
199 // method for data files as well, though it looks odd. | 203 // method for data files as well, though it looks odd. |
200 try { | 204 try { |
201 ByteArrayChannel sink = new ByteArrayChannel(); | 205 ByteArrayChannel sink = new ByteArrayChannel(); |
214 } | 218 } |
215 } | 219 } |
216 } | 220 } |
217 File file2read = null; | 221 File file2read = null; |
218 try { | 222 try { |
219 file2read = new File(getWorkingDir(), ".hgtags"); | 223 file2read = new File(getWorkingDir(), HgTags.getPath()); |
220 tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy | 224 tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy |
221 file2read = new File(repoDir, "localtags"); | 225 file2read = new File(repoDir, HgLocalTags.getName()); |
222 tags.readLocal(file2read); | 226 tags.readLocal(file2read); |
223 } catch (IOException ex) { | 227 } catch (IOException ex) { |
224 getContext().getLog().dump(getClass(), Error, ex, null); | 228 getContext().getLog().dump(getClass(), Error, ex, null); |
225 throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); | 229 throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); |
226 } | 230 } |
227 } | 231 } |
228 return tags; | 232 return tags; |
229 } | 233 } |
230 | 234 |
235 /** | |
236 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> | |
237 */ | |
231 public HgBranches getBranches() throws HgInvalidControlFileException { | 238 public HgBranches getBranches() throws HgInvalidControlFileException { |
232 if (branches == null) { | 239 if (branches == null) { |
233 branches = new HgBranches(this); | 240 branches = new HgBranches(this); |
234 branches.collect(ProgressSupport.Factory.get(null)); | 241 branches.collect(ProgressSupport.Factory.get(null)); |
235 } | 242 } |
272 /** | 279 /** |
273 * @return pair of values, {@link Pair#first()} and {@link Pair#second()} are respective parents, never <code>null</code>. | 280 * @return pair of values, {@link Pair#first()} and {@link Pair#second()} are respective parents, never <code>null</code>. |
274 * @throws HgInvalidControlFileException if attempt to read information about working copy parents from dirstate failed | 281 * @throws HgInvalidControlFileException if attempt to read information about working copy parents from dirstate failed |
275 */ | 282 */ |
276 public Pair<Nodeid,Nodeid> getWorkingCopyParents() throws HgInvalidControlFileException { | 283 public Pair<Nodeid,Nodeid> getWorkingCopyParents() throws HgInvalidControlFileException { |
277 return HgDirstate.readParents(this, new File(repoDir, "dirstate")); | 284 return HgDirstate.readParents(this, new File(repoDir, Dirstate.getName())); |
278 } | 285 } |
279 | 286 |
280 /** | 287 /** |
281 * @return name of the branch associated with working directory, never <code>null</code>. | 288 * @return name of the branch associated with working directory, never <code>null</code>. |
282 * @throws HgInvalidControlFileException if attempt to read branch name failed. | 289 * @throws HgInvalidControlFileException if attempt to read branch name failed. |
297 | 304 |
298 /** | 305 /** |
299 * Provides access to sub-repositories defined in this repository. Enumerated sub-repositories are those directly | 306 * Provides access to sub-repositories defined in this repository. Enumerated sub-repositories are those directly |
300 * known, not recursive collection of all nested sub-repositories. | 307 * known, not recursive collection of all nested sub-repositories. |
301 * @return list of all known sub-repositories in this repository, or empty list if none found. | 308 * @return list of all known sub-repositories in this repository, or empty list if none found. |
309 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> | |
302 */ | 310 */ |
303 public List<HgSubrepoLocation> getSubrepositories() throws HgInvalidControlFileException { | 311 public List<HgSubrepoLocation> getSubrepositories() throws HgInvalidControlFileException { |
304 if (subRepos == null) { | 312 if (subRepos == null) { |
305 subRepos = new SubrepoManager(this); | 313 subRepos = new SubrepoManager(this); |
306 subRepos.read(); | 314 subRepos.read(); |
344 public CharSequence rewrite(CharSequence path) { | 352 public CharSequence rewrite(CharSequence path) { |
345 return path.toString().toLowerCase(); | 353 return path.toString().toLowerCase(); |
346 } | 354 } |
347 }; | 355 }; |
348 } | 356 } |
349 HgDirstate ds = new HgDirstate(this, new File(repoDir, "dirstate"), pathFactory, canonicalPath); | 357 File dirstateFile = new File(repoDir, Dirstate.getName()); |
358 HgDirstate ds = new HgDirstate(this, dirstateFile, pathFactory, canonicalPath); | |
350 ds.read(impl.buildFileNameEncodingHelper()); | 359 ds.read(impl.buildFileNameEncodingHelper()); |
351 return ds; | 360 return ds; |
352 } | 361 } |
353 | 362 |
354 /** | 363 /** |
355 * Access to configured set of ignored files. | 364 * Access to configured set of ignored files. |
356 * @see HgIgnore#isIgnored(Path) | 365 * @see HgIgnore#isIgnored(Path) |
357 */ | 366 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
358 public HgIgnore getIgnore() /*throws HgInvalidControlFileException */{ | 367 */ |
368 public HgIgnore getIgnore() throws HgInvalidControlFileException { | |
359 // TODO read config for additional locations | 369 // TODO read config for additional locations |
360 if (ignore == null) { | 370 if (ignore == null) { |
361 ignore = new HgIgnore(getToRepoPathHelper()); | 371 ignore = new HgIgnore(getToRepoPathHelper()); |
362 File ignoreFile = new File(getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath()); | 372 File ignoreFile = new File(getWorkingDir(), HgIgnore.getPath()); |
363 try { | 373 try { |
364 final List<String> errors = ignore.read(ignoreFile); | 374 final List<String> errors = ignore.read(ignoreFile); |
365 if (errors != null) { | 375 if (errors != null) { |
366 getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n")); | 376 getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n")); |
367 } | 377 } |
368 } catch (IOException ex) { | 378 } catch (IOException ex) { |
369 final String m = "Error reading .hgignore file"; | 379 final String m = String.format("Error reading %s file", ignoreFile); |
370 getContext().getLog().dump(getClass(), Warn, ex, m); | 380 throw new HgInvalidControlFileException(m, ex, ignoreFile); |
371 // throw new HgInvalidControlFileException(m, ex, ignoreFile); | |
372 } | 381 } |
373 } | 382 } |
374 return ignore; | 383 return ignore; |
375 } | 384 } |
376 | 385 |
377 /** | 386 /** |
378 * Mercurial saves message user has supplied for a commit to facilitate message re-use in case commit fails. | 387 * Mercurial saves message user has supplied for a commit to facilitate message re-use in case commit fails. |
379 * This method provides this saved message. | 388 * This method provides this saved message. |
380 * | 389 * |
381 * @return message used for last commit attempt, or <code>null</code> if none | 390 * @return message used for last commit attempt, or <code>null</code> if none |
382 */ | 391 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
383 public String getCommitLastMessage() { | 392 */ |
384 File lastMessage = new File(getRepositoryRoot(), HgRepositoryFiles.LastMessage.getPath()); | 393 public String getCommitLastMessage() throws HgInvalidControlFileException { |
394 File lastMessage = new File(repoDir, LastMessage.getPath()); | |
385 if (!lastMessage.canRead()) { | 395 if (!lastMessage.canRead()) { |
386 return null; | 396 return null; |
387 } | 397 } |
388 FileReader fr = null; | 398 FileReader fr = null; |
389 try { | 399 try { |