comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 362:4937e35b805b

Report dirstate access error with Exception
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 09 Dec 2011 01:14:41 +0100
parents 150500515714
children 189dc6dc1c3e
comparison
equal deleted inserted replaced
361:8099939af5fa 362:4937e35b805b
63 private HgDirstate dirstate; 63 private HgDirstate dirstate;
64 private HgStatusCollector baseRevisionCollector; 64 private HgStatusCollector baseRevisionCollector;
65 private PathPool pathPool; 65 private PathPool pathPool;
66 private ManifestRevision dirstateParentManifest; 66 private ManifestRevision dirstateParentManifest;
67 67
68 /**
69 * Collector that iterates over complete working copy
70 */
68 public HgWorkingCopyStatusCollector(HgRepository hgRepo) { 71 public HgWorkingCopyStatusCollector(HgRepository hgRepo) {
69 this(hgRepo, new HgInternals(hgRepo).createWorkingDirWalker(null)); 72 this(hgRepo, new HgInternals(hgRepo).createWorkingDirWalker(null));
70 } 73 }
71 74
72 // FIXME document cons 75 /**
73 public HgWorkingCopyStatusCollector(HgRepository hgRepo, FileIterator hgRepoWalker) { 76 * Collector may analyze and report status for any arbitrary sub-tree of the working copy.
77 * File iterator shall return names of the files relative to the repository root.
78 *
79 * @param hgRepo status target repository
80 * @param workingCopyWalker iterator over files in the working copy
81 */
82 public HgWorkingCopyStatusCollector(HgRepository hgRepo, FileIterator workingCopyWalker) {
74 repo = hgRepo; 83 repo = hgRepo;
75 repoWalker = hgRepoWalker; 84 repoWalker = workingCopyWalker;
76 } 85 }
77 86
78 /** 87 /**
79 * Optionally, supply a collector instance that may cache (or have already cached) base revision 88 * Optionally, supply a collector instance that may cache (or have already cached) base revision
80 * @param sc may be null 89 * @param sc may be null
141 return dirstateParentManifest; 150 return dirstateParentManifest;
142 } 151 }
143 152
144 // may be invoked few times, TIP or WORKING_COPY indicate comparison shall be run against working copy parent 153 // may be invoked few times, TIP or WORKING_COPY indicate comparison shall be run against working copy parent
145 // NOTE, use of TIP constant requires certain care. TIP here doesn't mean latest cset, but actual working copy parent. 154 // NOTE, use of TIP constant requires certain care. TIP here doesn't mean latest cset, but actual working copy parent.
146 public void walk(int baseRevision, HgStatusInspector inspector) throws IOException { 155 public void walk(int baseRevision, HgStatusInspector inspector) throws HgInvalidControlFileException, IOException {
147 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) { 156 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) {
148 throw new IllegalArgumentException(String.valueOf(baseRevision)); 157 throw new IllegalArgumentException(String.valueOf(baseRevision));
149 } 158 }
150 try { 159 if (getDirstateImpl() == null) {
151 if (getDirstateImpl() == null) { 160 getDirstate();
152 // FIXME this is a hack to avoid declaring throws for the #walk() at the moment 161 }
153 // once I decide whether to have mediator that collects errors or to use exceptions here 162 if (getDirstateParentManifest() == null) {
154 // this hack shall be removed in favor of either severe error in mediator or a re-thrown exception. 163 initDirstateParentManifest();
155 getDirstate();
156 }
157 if (getDirstateParentManifest() == null) {
158 initDirstateParentManifest();
159 }
160 } catch (HgInvalidControlFileException ex) {
161 repo.getContext().getLog().error(getClass(), ex, "Failed to initialize with dirstate information");
162 return;
163 } 164 }
164 ManifestRevision collect = null; // non null indicates we compare against base revision 165 ManifestRevision collect = null; // non null indicates we compare against base revision
165 Set<Path> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation 166 Set<Path> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation
166 if (baseRevision != TIP && baseRevision != WORKING_COPY) { 167 if (baseRevision != TIP && baseRevision != WORKING_COPY) {
167 collect = getManifest(baseRevision); 168 collect = getManifest(baseRevision);
269 } 270 }
270 } 271 }
271 } 272 }
272 } 273 }
273 274
274 public HgStatusCollector.Record status(int baseRevision) throws IOException { 275 public HgStatusCollector.Record status(int baseRevision) throws HgInvalidControlFileException, IOException {
275 HgStatusCollector.Record rv = new HgStatusCollector.Record(); 276 HgStatusCollector.Record rv = new HgStatusCollector.Record();
276 walk(baseRevision, rv); 277 walk(baseRevision, rv);
277 return rv; 278 return rv;
278 } 279 }
279 280