Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 354:5f9073eabf06
Propagate errors with exceptions up to a end client
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 01 Dec 2011 05:21:40 +0100 |
parents | 8da7ade36c57 |
children | f2c11fe7f3e9 |
comparison
equal
deleted
inserted
replaced
353:0f3687e79f5a | 354:5f9073eabf06 |
---|---|
31 import java.util.Collections; | 31 import java.util.Collections; |
32 import java.util.List; | 32 import java.util.List; |
33 | 33 |
34 import org.tmatesoft.hg.core.HgDataStreamException; | 34 import org.tmatesoft.hg.core.HgDataStreamException; |
35 import org.tmatesoft.hg.core.HgException; | 35 import org.tmatesoft.hg.core.HgException; |
36 import org.tmatesoft.hg.core.HgInvalidControlFileException; | |
36 import org.tmatesoft.hg.core.HgInvalidRevisionException; | 37 import org.tmatesoft.hg.core.HgInvalidRevisionException; |
37 import org.tmatesoft.hg.core.HgLogCommand; | 38 import org.tmatesoft.hg.core.HgLogCommand; |
38 import org.tmatesoft.hg.core.Nodeid; | 39 import org.tmatesoft.hg.core.Nodeid; |
39 import org.tmatesoft.hg.internal.DataAccess; | 40 import org.tmatesoft.hg.internal.DataAccess; |
40 import org.tmatesoft.hg.internal.FilterByteChannel; | 41 import org.tmatesoft.hg.internal.FilterByteChannel; |
84 public Path getPath() { | 85 public Path getPath() { |
85 return path; // hgRepo.backresolve(this) -> name? In this case, what about hashed long names? | 86 return path; // hgRepo.backresolve(this) -> name? In this case, what about hashed long names? |
86 } | 87 } |
87 | 88 |
88 /** | 89 /** |
90 * Handy shorthand for {@link #length(int) length(getLocalRevision(nodeid))} | |
91 * | |
92 * @param nodeid revision of the file | |
93 * | |
89 * @return size of the file content at the given revision | 94 * @return size of the file content at the given revision |
90 */ | 95 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog |
91 public int length(Nodeid nodeid) throws HgDataStreamException { | 96 * @throws HgDataStreamException if attempt to access file metadata failed |
97 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
98 */ | |
99 public int length(Nodeid nodeid) throws HgDataStreamException, HgInvalidControlFileException, HgInvalidRevisionException { | |
92 return length(getLocalRevision(nodeid)); | 100 return length(getLocalRevision(nodeid)); |
93 | |
94 } | 101 } |
95 | 102 |
96 /** | 103 /** |
97 * @return size of the file content at the revision identified by local revision number. | 104 * @return size of the file content at the revision identified by local revision number. |
98 */ | 105 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog |
99 public int length(int localRev) throws HgDataStreamException { | 106 * @throws HgDataStreamException if attempt to access file metadata failed |
107 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
108 */ | |
109 public int length(int localRev) throws HgDataStreamException, HgInvalidControlFileException, HgInvalidRevisionException { | |
100 if (metadata == null || !metadata.checked(localRev)) { | 110 if (metadata == null || !metadata.checked(localRev)) { |
101 checkAndRecordMetadata(localRev); | 111 checkAndRecordMetadata(localRev); |
102 } | 112 } |
103 final int dataLen = content.dataLength(localRev); | 113 final int dataLen = content.dataLength(localRev); |
104 if (metadata.known(localRev)) { | 114 if (metadata.known(localRev)) { |
385 Arrays.sort(commitRevisions); | 395 Arrays.sort(commitRevisions); |
386 } | 396 } |
387 changelog.rangeInternal(inspector, commitRevisions); | 397 changelog.rangeInternal(inspector, commitRevisions); |
388 } | 398 } |
389 | 399 |
390 // for a given local revision of the file, find out local revision in the changelog | 400 /** |
391 public int getChangesetLocalRevision(int revision) { | 401 * For a given local revision of the file, find out local revision in the changelog. |
402 * FIXME rename to getChangesetRevisionIndex() | |
403 * | |
404 * @return changeset revision index | |
405 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog | |
406 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
407 */ | |
408 public int getChangesetLocalRevision(int revision) throws HgInvalidControlFileException, HgInvalidRevisionException { | |
392 return content.linkRevision(revision); | 409 return content.linkRevision(revision); |
393 } | 410 } |
394 | 411 |
395 public Nodeid getChangesetRevision(Nodeid nid) { | 412 /** |
413 * Complements {@link #getChangesetLocalRevision(int)} to get changeset revision that corresponds to supplied file revision | |
414 * | |
415 * @param nid revision of the file | |
416 * @return changeset revision | |
417 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog | |
418 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
419 */ | |
420 public Nodeid getChangesetRevision(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { | |
396 int changelogRevision = getChangesetLocalRevision(getLocalRevision(nid)); | 421 int changelogRevision = getChangesetLocalRevision(getLocalRevision(nid)); |
397 return getRepo().getChangelog().getRevision(changelogRevision); | 422 return getRepo().getChangelog().getRevision(changelogRevision); |
398 } | 423 } |
399 | 424 |
425 /** | |
426 * | |
427 * @return | |
428 * @throws HgDataStreamException if attempt to access file metadata failed | |
429 */ | |
400 public boolean isCopy() throws HgDataStreamException { | 430 public boolean isCopy() throws HgDataStreamException { |
401 if (metadata == null || !metadata.checked(0)) { | 431 if (metadata == null || !metadata.checked(0)) { |
402 checkAndRecordMetadata(0); | 432 checkAndRecordMetadata(0); |
403 } | 433 } |
404 if (!metadata.known(0)) { | 434 if (!metadata.known(0)) { |
405 return false; | 435 return false; |
406 } | 436 } |
407 return metadata.find(0, "copy") != null; | 437 return metadata.find(0, "copy") != null; |
408 } | 438 } |
409 | 439 |
440 /** | |
441 * Get name of the file this one was copied from. | |
442 * | |
443 * @return name of the file origin | |
444 * @throws HgDataStreamException if attempt to access file metadata failed | |
445 * @throws UnsupportedOperationException if this file doesn't represent a copy ({@link #isCopy()} was false) | |
446 */ | |
410 public Path getCopySourceName() throws HgDataStreamException { | 447 public Path getCopySourceName() throws HgDataStreamException { |
411 if (isCopy()) { | 448 if (isCopy()) { |
412 return Path.create(metadata.find(0, "copy")); | 449 return Path.create(metadata.find(0, "copy")); |
413 } | 450 } |
414 throw new UnsupportedOperationException(); // XXX REVISIT, think over if Exception is good (clients would check isCopy() anyway, perhaps null is sufficient?) | 451 throw new UnsupportedOperationException(); // XXX REVISIT, think over if Exception is good (clients would check isCopy() anyway, perhaps null is sufficient?) |