comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.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 33eaed1ad130
children f2c11fe7f3e9
comparison
equal deleted inserted replaced
353:0f3687e79f5a 354:5f9073eabf06
29 import java.util.NoSuchElementException; 29 import java.util.NoSuchElementException;
30 import java.util.Set; 30 import java.util.Set;
31 import java.util.TreeSet; 31 import java.util.TreeSet;
32 32
33 import org.tmatesoft.hg.core.HgBadStateException; 33 import org.tmatesoft.hg.core.HgBadStateException;
34 import org.tmatesoft.hg.core.HgDataStreamException;
35 import org.tmatesoft.hg.core.HgException; 34 import org.tmatesoft.hg.core.HgException;
36 import org.tmatesoft.hg.core.HgInvalidControlFileException; 35 import org.tmatesoft.hg.core.HgInvalidControlFileException;
37 import org.tmatesoft.hg.core.Nodeid; 36 import org.tmatesoft.hg.core.Nodeid;
38 import org.tmatesoft.hg.internal.ByteArrayChannel; 37 import org.tmatesoft.hg.internal.ByteArrayChannel;
39 import org.tmatesoft.hg.internal.Experimental; 38 import org.tmatesoft.hg.internal.Experimental;
121 mr = new ManifestRevision(null, null); 120 mr = new ManifestRevision(null, null);
122 repo.getManifest().walk(changelogLocalRev, changelogLocalRev, mr); 121 repo.getManifest().walk(changelogLocalRev, changelogLocalRev, mr);
123 } 122 }
124 return mr; 123 return mr;
125 } 124 }
126 125
126 private void initDirstateParentManifest() throws HgInvalidControlFileException {
127 Nodeid dirstateParent = getDirstateImpl().parents().first();
128 if (dirstateParent.isNull()) {
129 dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(-1) : HgStatusCollector.createEmptyManifestRevision();
130 } else {
131 int changelogLocalRev = repo.getChangelog().getLocalRevision(dirstateParent);
132 dirstateParentManifest = getManifest(changelogLocalRev);
133 }
134 }
135
136 // WC not necessarily points to TIP, but may be result of update to any previous revision.
137 // In such case, we need to compare local files not to their TIP content, but to specific version at the time of selected revision
127 private ManifestRevision getDirstateParentManifest() { 138 private ManifestRevision getDirstateParentManifest() {
128 // WC not necessarily points to TIP, but may be result of update to any previous revision.
129 // In such case, we need to compare local files not to their TIP content, but to specific version at the time of selected revision
130 if (dirstateParentManifest == null) {
131 Nodeid dirstateParent = getDirstateImpl().parents().first();
132 if (dirstateParent.isNull()) {
133 dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(-1) : HgStatusCollector.createEmptyManifestRevision();
134 } else {
135 int changelogLocalRev = repo.getChangelog().getLocalRevision(dirstateParent);
136 dirstateParentManifest = getManifest(changelogLocalRev);
137 }
138 }
139 return dirstateParentManifest; 139 return dirstateParentManifest;
140 } 140 }
141 141
142 // may be invoked few times, TIP or WORKING_COPY indicate comparison shall be run against working copy parent 142 // may be invoked few times, TIP or WORKING_COPY indicate comparison shall be run against working copy parent
143 // NOTE, use of TIP constant requires certain care. TIP here doesn't mean latest cset, but actual working copy parent. 143 // NOTE, use of TIP constant requires certain care. TIP here doesn't mean latest cset, but actual working copy parent.
144 public void walk(int baseRevision, HgStatusInspector inspector) throws IOException { 144 public void walk(int baseRevision, HgStatusInspector inspector) throws IOException {
145 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) { 145 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) {
146 throw new IllegalArgumentException(String.valueOf(baseRevision)); 146 throw new IllegalArgumentException(String.valueOf(baseRevision));
147 } 147 }
148 if (getDirstateImpl() == null) { 148 try {
149 // XXX this is a hack to avoid declaring throws for the #walk() at the moment 149 if (getDirstateImpl() == null) {
150 // once I decide whether to have mediator that collects errors or to use exceptions here 150 // XXX this is a hack to avoid declaring throws for the #walk() at the moment
151 // this hack shall be removed in favor of either severe error in mediator or a re-thrown exception. 151 // once I decide whether to have mediator that collects errors or to use exceptions here
152 try { 152 // this hack shall be removed in favor of either severe error in mediator or a re-thrown exception.
153 getDirstate(); 153 getDirstate();
154 } catch (HgInvalidControlFileException ex) { 154 }
155 repo.getContext().getLog().error(getClass(), ex, "Can't read dirstate"); 155 if (getDirstateParentManifest() == null) {
156 return; 156 initDirstateParentManifest();
157 } 157 }
158 } catch (HgInvalidControlFileException ex) {
159 repo.getContext().getLog().error(getClass(), ex, "Failed to initialize with dirstate information");
160 return;
158 } 161 }
159 ManifestRevision collect = null; // non null indicates we compare against base revision 162 ManifestRevision collect = null; // non null indicates we compare against base revision
160 Set<Path> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation 163 Set<Path> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation
161 if (baseRevision != TIP && baseRevision != WORKING_COPY) { 164 if (baseRevision != TIP && baseRevision != WORKING_COPY) {
162 collect = getManifest(baseRevision); 165 collect = getManifest(baseRevision);
331 Path origin = HgStatusCollector.getOriginIfCopy(repo, fname, baseRevNames, baseRevision); 334 Path origin = HgStatusCollector.getOriginIfCopy(repo, fname, baseRevNames, baseRevision);
332 if (origin != null) { 335 if (origin != null) {
333 inspector.copied(getPathPool().path(origin), fname); 336 inspector.copied(getPathPool().path(origin), fname);
334 return; 337 return;
335 } 338 }
336 } catch (HgDataStreamException ex) { 339 } catch (HgException ex) {
337 ex.printStackTrace(); 340 ex.printStackTrace();
338 // FIXME report to a mediator, continue status collection 341 // FIXME report to a mediator, continue status collection
339 } 342 }
340 } else if ((r = getDirstateImpl().checkAdded(fname)) != null) { 343 } else if ((r = getDirstateImpl().checkAdded(fname)) != null) {
341 if (r.copySource() != null && baseRevNames.contains(r.copySource())) { 344 if (r.copySource() != null && baseRevNames.contains(r.copySource())) {