Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 628:6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 22 May 2013 15:52:31 +0200 |
parents | f41dd9a3b8af |
children | 12a4f60ea972 |
comparison
equal
deleted
inserted
replaced
627:5153eb73b18d | 628:6526d8adbc0f |
---|---|
32 import java.util.TreeSet; | 32 import java.util.TreeSet; |
33 | 33 |
34 import org.tmatesoft.hg.core.Nodeid; | 34 import org.tmatesoft.hg.core.Nodeid; |
35 import org.tmatesoft.hg.core.SessionContext; | 35 import org.tmatesoft.hg.core.SessionContext; |
36 import org.tmatesoft.hg.internal.ByteArrayChannel; | 36 import org.tmatesoft.hg.internal.ByteArrayChannel; |
37 import org.tmatesoft.hg.internal.FileUtils; | |
37 import org.tmatesoft.hg.internal.FilterByteChannel; | 38 import org.tmatesoft.hg.internal.FilterByteChannel; |
38 import org.tmatesoft.hg.internal.Internals; | 39 import org.tmatesoft.hg.internal.Internals; |
39 import org.tmatesoft.hg.internal.ManifestRevision; | 40 import org.tmatesoft.hg.internal.ManifestRevision; |
40 import org.tmatesoft.hg.internal.PathPool; | 41 import org.tmatesoft.hg.internal.PathPool; |
41 import org.tmatesoft.hg.internal.PathScope; | 42 import org.tmatesoft.hg.internal.PathScope; |
128 | 129 |
129 private HgDirstate getDirstateImpl() { | 130 private HgDirstate getDirstateImpl() { |
130 return dirstate; | 131 return dirstate; |
131 } | 132 } |
132 | 133 |
133 private ManifestRevision getManifest(int changelogLocalRev) throws HgInvalidControlFileException { | 134 private ManifestRevision getManifest(int changelogLocalRev) throws HgRuntimeException { |
134 assert changelogLocalRev >= 0; | 135 assert changelogLocalRev >= 0; |
135 ManifestRevision mr; | 136 ManifestRevision mr; |
136 if (baseRevisionCollector != null) { | 137 if (baseRevisionCollector != null) { |
137 mr = baseRevisionCollector.raw(changelogLocalRev); | 138 mr = baseRevisionCollector.raw(changelogLocalRev); |
138 } else { | 139 } else { |
140 repo.getManifest().walk(changelogLocalRev, changelogLocalRev, mr); | 141 repo.getManifest().walk(changelogLocalRev, changelogLocalRev, mr); |
141 } | 142 } |
142 return mr; | 143 return mr; |
143 } | 144 } |
144 | 145 |
145 private void initDirstateParentManifest() throws HgInvalidControlFileException { | 146 private void initDirstateParentManifest() throws HgRuntimeException { |
146 Nodeid dirstateParent = getDirstateImpl().parents().first(); | 147 Nodeid dirstateParent = getDirstateImpl().parents().first(); |
147 if (dirstateParent.isNull()) { | 148 if (dirstateParent.isNull()) { |
148 dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(NO_REVISION) : HgStatusCollector.createEmptyManifestRevision(); | 149 dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(NO_REVISION) : HgStatusCollector.createEmptyManifestRevision(); |
149 } else { | 150 } else { |
150 int changeloRevIndex = repo.getChangelog().getRevisionIndex(dirstateParent); | 151 int changeloRevIndex = repo.getChangelog().getRevisionIndex(dirstateParent); |
405 inspector.modified(fname); | 406 inspector.modified(fname); |
406 } | 407 } |
407 } | 408 } |
408 | 409 |
409 // XXX refactor checkLocalStatus methods in more OO way | 410 // XXX refactor checkLocalStatus methods in more OO way |
410 private void checkLocalStatusAgainstBaseRevision(Set<Path> baseRevNames, ManifestRevision collect, int baseRevision, Path fname, FileInfo f, HgStatusInspector inspector) { | 411 private void checkLocalStatusAgainstBaseRevision(Set<Path> baseRevNames, ManifestRevision collect, int baseRevision, Path fname, FileInfo f, HgStatusInspector inspector) throws HgRuntimeException { |
411 // fname is in the dirstate, either Normal, Added, Removed or Merged | 412 // fname is in the dirstate, either Normal, Added, Removed or Merged |
412 Nodeid nid1 = collect.nodeid(fname); | 413 Nodeid nid1 = collect.nodeid(fname); |
413 HgManifest.Flags flags = collect.flags(fname); | 414 HgManifest.Flags flags = collect.flags(fname); |
414 HgDirstate.Record r; | 415 HgDirstate.Record r; |
415 final HgDirstate ds = getDirstateImpl(); | 416 final HgDirstate ds = getDirstateImpl(); |
499 // changeset nodeid + hash(actual content) => entry (Nodeid) in the next Manifest | 500 // changeset nodeid + hash(actual content) => entry (Nodeid) in the next Manifest |
500 // then it's sufficient to check parents from dirstate, and if they do not match parents from file's baseRevision (non matching parents means different nodeids). | 501 // then it's sufficient to check parents from dirstate, and if they do not match parents from file's baseRevision (non matching parents means different nodeids). |
501 // The question is whether original Hg treats this case (same content, different parents and hence nodeids) as 'modified' or 'clean' | 502 // The question is whether original Hg treats this case (same content, different parents and hence nodeids) as 'modified' or 'clean' |
502 } | 503 } |
503 | 504 |
504 private boolean areTheSame(FileInfo f, HgDataFile dataFile, Nodeid revision) throws HgInvalidFileException { | 505 private boolean areTheSame(FileInfo f, HgDataFile dataFile, Nodeid revision) throws HgRuntimeException { |
505 // XXX consider adding HgDataDile.compare(File/byte[]/whatever) operation to optimize comparison | 506 // XXX consider adding HgDataDile.compare(File/byte[]/whatever) operation to optimize comparison |
506 ByteArrayChannel bac = new ByteArrayChannel(); | 507 ByteArrayChannel bac = new ByteArrayChannel(); |
507 try { | 508 try { |
508 int fileRevisionIndex = dataFile.getRevisionIndex(revision); | 509 int fileRevisionIndex = dataFile.getRevisionIndex(revision); |
509 // need content with metadata striped off - although theoretically chances are metadata may be different, | 510 // need content with metadata striped off - although theoretically chances are metadata may be different, |
586 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation"); | 587 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation"); |
587 return check.ultimatelyTheSame(); | 588 return check.ultimatelyTheSame(); |
588 } catch (IOException ex) { | 589 } catch (IOException ex) { |
589 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p); | 590 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p); |
590 } finally { | 591 } finally { |
591 if (is != null) { | 592 new FileUtils(repo.getSessionContext().getLog()).closeQuietly(is); |
592 try { | |
593 is.close(); | |
594 } catch (IOException ex) { | |
595 repo.getSessionContext().getLog().dump(getClass(), Info, ex, null); | |
596 } | |
597 } | |
598 } | 593 } |
599 } | 594 } |
600 | 595 |
601 /** | 596 /** |
602 * @return <code>true</code> if flags are the same | 597 * @return <code>true</code> if flags are the same |