Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 141:8248aae33f7d
Adopt FileIterator moving towards WCStatusCollector parameterizing. Improved path handling, move 'em around
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 17 Feb 2011 04:08:34 +0100 |
parents | 4a948ec83980 |
children | 37a34044e6bd |
comparison
equal
deleted
inserted
replaced
140:1c1891ad1c73 | 141:8248aae33f7d |
---|---|
32 | 32 |
33 import org.tmatesoft.hg.core.Nodeid; | 33 import org.tmatesoft.hg.core.Nodeid; |
34 import org.tmatesoft.hg.internal.FilterByteChannel; | 34 import org.tmatesoft.hg.internal.FilterByteChannel; |
35 import org.tmatesoft.hg.repo.HgStatusCollector.ManifestRevisionInspector; | 35 import org.tmatesoft.hg.repo.HgStatusCollector.ManifestRevisionInspector; |
36 import org.tmatesoft.hg.util.ByteChannel; | 36 import org.tmatesoft.hg.util.ByteChannel; |
37 import org.tmatesoft.hg.util.FileWalker; | 37 import org.tmatesoft.hg.util.FileIterator; |
38 import org.tmatesoft.hg.util.Path; | 38 import org.tmatesoft.hg.util.Path; |
39 import org.tmatesoft.hg.util.PathPool; | 39 import org.tmatesoft.hg.util.PathPool; |
40 import org.tmatesoft.hg.util.PathRewrite; | 40 import org.tmatesoft.hg.util.PathRewrite; |
41 | 41 |
42 /** | 42 /** |
45 * @author TMate Software Ltd. | 45 * @author TMate Software Ltd. |
46 */ | 46 */ |
47 public class HgWorkingCopyStatusCollector { | 47 public class HgWorkingCopyStatusCollector { |
48 | 48 |
49 private final HgRepository repo; | 49 private final HgRepository repo; |
50 private final FileWalker repoWalker; | 50 private final FileIterator repoWalker; |
51 private HgDirstate dirstate; | 51 private HgDirstate dirstate; |
52 private HgStatusCollector baseRevisionCollector; | 52 private HgStatusCollector baseRevisionCollector; |
53 private PathPool pathPool; | 53 private PathPool pathPool; |
54 | 54 |
55 public HgWorkingCopyStatusCollector(HgRepository hgRepo) { | 55 public HgWorkingCopyStatusCollector(HgRepository hgRepo) { |
56 this(hgRepo, hgRepo.createWorkingDirWalker()); | 56 this(hgRepo, hgRepo.createWorkingDirWalker()); |
57 } | 57 } |
58 | 58 |
59 HgWorkingCopyStatusCollector(HgRepository hgRepo, FileWalker hgRepoWalker) { | 59 HgWorkingCopyStatusCollector(HgRepository hgRepo, FileIterator hgRepoWalker) { |
60 this.repo = hgRepo; | 60 this.repo = hgRepo; |
61 this.repoWalker = hgRepoWalker; | 61 this.repoWalker = hgRepoWalker; |
62 } | 62 } |
63 | 63 |
64 /** | 64 /** |
120 } | 120 } |
121 repoWalker.reset(); | 121 repoWalker.reset(); |
122 final PathPool pp = getPathPool(); | 122 final PathPool pp = getPathPool(); |
123 while (repoWalker.hasNext()) { | 123 while (repoWalker.hasNext()) { |
124 repoWalker.next(); | 124 repoWalker.next(); |
125 String fname = repoWalker.name(); | 125 Path fname = repoWalker.name(); |
126 File f = repoWalker.file(); | 126 File f = repoWalker.file(); |
127 if (hgIgnore.isIgnored(fname)) { | 127 if (hgIgnore.isIgnored(fname)) { |
128 inspector.ignored(pp.path(fname)); | 128 inspector.ignored(pp.path(fname)); |
129 } else if (knownEntries.remove(fname)) { | 129 } else if (knownEntries.remove(fname.toString())) { |
130 // modified, added, removed, clean | 130 // modified, added, removed, clean |
131 if (collect != null) { // need to check against base revision, not FS file | 131 if (collect != null) { // need to check against base revision, not FS file |
132 checkLocalStatusAgainstBaseRevision(baseRevFiles, collect, baseRevision, fname, f, inspector); | 132 checkLocalStatusAgainstBaseRevision(baseRevFiles, collect, baseRevision, fname, f, inspector); |
133 baseRevFiles.remove(fname); | 133 baseRevFiles.remove(fname); |
134 } else { | 134 } else { |
165 } | 165 } |
166 | 166 |
167 //******************************************** | 167 //******************************************** |
168 | 168 |
169 | 169 |
170 private void checkLocalStatusAgainstFile(String fname, File f, HgStatusInspector inspector) { | 170 private void checkLocalStatusAgainstFile(Path fname, File f, HgStatusInspector inspector) { |
171 HgDirstate.Record r; | 171 HgDirstate.Record r; |
172 if ((r = getDirstate().checkNormal(fname)) != null) { | 172 if ((r = getDirstate().checkNormal(fname)) != null) { |
173 // either clean or modified | 173 // either clean or modified |
174 if (f.lastModified() / 1000 == r.time && r.size == f.length()) { | 174 if (f.lastModified() / 1000 == r.time && r.size == f.length()) { |
175 inspector.clean(getPathPool().path(fname)); | 175 inspector.clean(getPathPool().path(fname)); |
192 inspector.modified(getPathPool().path(fname)); | 192 inspector.modified(getPathPool().path(fname)); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 // XXX refactor checkLocalStatus methods in more OO way | 196 // XXX refactor checkLocalStatus methods in more OO way |
197 private void checkLocalStatusAgainstBaseRevision(Set<String> baseRevNames, ManifestRevisionInspector collect, int baseRevision, String fname, File f, HgStatusInspector inspector) { | 197 private void checkLocalStatusAgainstBaseRevision(Set<String> baseRevNames, ManifestRevisionInspector collect, int baseRevision, Path fname, File f, HgStatusInspector inspector) { |
198 // fname is in the dirstate, either Normal, Added, Removed or Merged | 198 // fname is in the dirstate, either Normal, Added, Removed or Merged |
199 Nodeid nid1 = collect.nodeid(fname); | 199 Nodeid nid1 = collect.nodeid(fname.toString()); |
200 String flags = collect.flags(fname); | 200 String flags = collect.flags(fname.toString()); |
201 HgDirstate.Record r; | 201 HgDirstate.Record r; |
202 if (nid1 == null) { | 202 if (nid1 == null) { |
203 // normal: added? | 203 // normal: added? |
204 // added: not known at the time of baseRevision, shall report | 204 // added: not known at the time of baseRevision, shall report |
205 // merged: was not known, report as added? | 205 // merged: was not known, report as added? |
206 if ((r = getDirstate().checkNormal(fname)) != null) { | 206 if ((r = getDirstate().checkNormal(fname)) != null) { |
207 String origin = HgStatusCollector.getOriginIfCopy(repo, fname, baseRevNames, baseRevision); | 207 Path origin = HgStatusCollector.getOriginIfCopy(repo, fname, baseRevNames, baseRevision); |
208 if (origin != null) { | 208 if (origin != null) { |
209 inspector.copied(getPathPool().path(origin), getPathPool().path(fname)); | 209 inspector.copied(getPathPool().path(origin), getPathPool().path(fname)); |
210 return; | 210 return; |
211 } | 211 } |
212 } else if ((r = getDirstate().checkAdded(fname)) != null) { | 212 } else if ((r = getDirstate().checkAdded(fname)) != null) { |
299 ex.printStackTrace(); | 299 ex.printStackTrace(); |
300 } | 300 } |
301 return false; | 301 return false; |
302 } | 302 } |
303 | 303 |
304 private static String todoGenerateFlags(String fname) { | 304 private static String todoGenerateFlags(Path fname) { |
305 // FIXME implement | 305 // FIXME implement |
306 return null; | 306 return null; |
307 } | 307 } |
308 | 308 |
309 } | 309 } |