comparison src/org/tmatesoft/hg/core/HgFileRevision.java @ 364:ac8e1ce67730

Expose errors dealign with Mercurial internals with Exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 09 Dec 2011 02:09:22 +0100
parents 5f9073eabf06
children 2fadf8695f8a
comparison
equal deleted inserted replaced
363:d9dfa9fe9cec 364:ac8e1ce67730
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import org.tmatesoft.hg.repo.HgDataFile; 19 import org.tmatesoft.hg.repo.HgDataFile;
20 import org.tmatesoft.hg.repo.HgInternals;
21 import org.tmatesoft.hg.repo.HgRepository; 20 import org.tmatesoft.hg.repo.HgRepository;
22 import org.tmatesoft.hg.util.ByteChannel; 21 import org.tmatesoft.hg.util.ByteChannel;
23 import org.tmatesoft.hg.util.CancelledException; 22 import org.tmatesoft.hg.util.CancelledException;
24 import org.tmatesoft.hg.util.Pair; 23 import org.tmatesoft.hg.util.Pair;
25 import org.tmatesoft.hg.util.Path; 24 import org.tmatesoft.hg.util.Path;
56 } 55 }
57 56
58 public Path getPath() { 57 public Path getPath() {
59 return path; 58 return path;
60 } 59 }
60
61 public Nodeid getRevision() { 61 public Nodeid getRevision() {
62 return revision; 62 return revision;
63 } 63 }
64 public boolean wasCopied() { 64
65 public boolean wasCopied() throws HgException {
65 if (isCopy == null) { 66 if (isCopy == null) {
66 checkCopy(); 67 checkCopy();
67 } 68 }
68 return isCopy.booleanValue(); 69 return isCopy.booleanValue();
69 } 70 }
70 /** 71 /**
71 * @return <code>null</code> if {@link #wasCopied()} is <code>false</code>, name of the copy source otherwise. 72 * @return <code>null</code> if {@link #wasCopied()} is <code>false</code>, name of the copy source otherwise.
72 */ 73 */
73 public Path getOriginIfCopy() { 74 public Path getOriginIfCopy() throws HgException {
74 if (wasCopied()) { 75 if (wasCopied()) {
75 return origin; 76 return origin;
76 } 77 }
77 return null; 78 return null;
78 } 79 }
102 HgDataFile fn = repo.getFileNode(path); 103 HgDataFile fn = repo.getFileNode(path);
103 int localRevision = fn.getLocalRevision(revision); 104 int localRevision = fn.getLocalRevision(revision);
104 fn.contentWithFilters(localRevision, sink); 105 fn.contentWithFilters(localRevision, sink);
105 } 106 }
106 107
107 private void checkCopy() { 108 private void checkCopy() throws HgInvalidControlFileException, HgDataStreamException {
108 HgDataFile fn = repo.getFileNode(path); 109 HgDataFile fn = repo.getFileNode(path);
109 try { 110 if (fn.isCopy()) {
110 if (fn.isCopy()) { 111 if (fn.getRevision(0).equals(revision)) {
111 if (fn.getRevision(0).equals(revision)) { 112 // this HgFileRevision represents first revision of the copy
112 // this HgFileRevision represents first revision of the copy 113 isCopy = Boolean.TRUE;
113 isCopy = Boolean.TRUE; 114 origin = fn.getCopySourceName();
114 origin = fn.getCopySourceName(); 115 return;
115 return;
116 }
117 } 116 }
118 } catch (HgDataStreamException ex) {
119 // FIXME rather throw an exception than log silently
120 HgInternals.getContext(repo).getLog().error(getClass(), ex, null);
121 } catch (HgInvalidControlFileException ex) {
122 HgInternals.getContext(repo).getLog().error(getClass(), ex, null);
123 } 117 }
124 isCopy = Boolean.FALSE; 118 isCopy = Boolean.FALSE;
125 } 119 }
126 } 120 }