comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 285:6dbbc53fc46d

Use Path instead of plain String for manifest file names
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 03 Sep 2011 21:46:13 +0200
parents 7232b94f2ae3
children ed6b74a58c66
comparison
equal deleted inserted replaced
284:7232b94f2ae3 285:6dbbc53fc46d
134 public void walk(int baseRevision, HgStatusInspector inspector) { 134 public void walk(int baseRevision, HgStatusInspector inspector) {
135 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) { 135 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) {
136 throw new IllegalArgumentException(String.valueOf(baseRevision)); 136 throw new IllegalArgumentException(String.valueOf(baseRevision));
137 } 137 }
138 ManifestRevision collect = null; // non null indicates we compare against base revision 138 ManifestRevision collect = null; // non null indicates we compare against base revision
139 Set<String> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation 139 Set<Path> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation
140 if (baseRevision != TIP && baseRevision != WORKING_COPY) { 140 if (baseRevision != TIP && baseRevision != WORKING_COPY) {
141 collect = getManifest(baseRevision); 141 collect = getManifest(baseRevision);
142 baseRevFiles = new TreeSet<String>(collect.files()); 142 baseRevFiles = new TreeSet<Path>(collect.files());
143 } 143 }
144 if (inspector instanceof HgStatusCollector.Record) { 144 if (inspector instanceof HgStatusCollector.Record) {
145 HgStatusCollector sc = baseRevisionCollector == null ? new HgStatusCollector(repo) : baseRevisionCollector; 145 HgStatusCollector sc = baseRevisionCollector == null ? new HgStatusCollector(repo) : baseRevisionCollector;
146 // nodeidAfterChange(dirstate's parent) doesn't make too much sense, 146 // nodeidAfterChange(dirstate's parent) doesn't make too much sense,
147 // because the change might be actually in working copy. Nevertheless, 147 // because the change might be actually in working copy. Nevertheless,
171 } else { 171 } else {
172 inspector.removed(fname); 172 inspector.removed(fname);
173 } 173 }
174 // do not report it as removed later 174 // do not report it as removed later
175 if (collect != null) { 175 if (collect != null) {
176 baseRevFiles.remove(fname.toString()); 176 baseRevFiles.remove(fname);
177 } 177 }
178 } else { 178 } else {
179 // chances are it was known in baseRevision. We may rely 179 // chances are it was known in baseRevision. We may rely
180 // that later iteration over baseRevFiles leftovers would yield correct Removed, 180 // that later iteration over baseRevFiles leftovers would yield correct Removed,
181 // but it doesn't hurt to be explicit (provided we know fname *is* inScope of the FileIterator 181 // but it doesn't hurt to be explicit (provided we know fname *is* inScope of the FileIterator
182 if (collect != null && baseRevFiles.remove(fname.toString())) { 182 if (collect != null && baseRevFiles.remove(fname)) {
183 inspector.removed(fname); 183 inspector.removed(fname);
184 } else { 184 } else {
185 // not sure I shall report such files (i.e. arbitrary name coming from FileIterator) 185 // not sure I shall report such files (i.e. arbitrary name coming from FileIterator)
186 // as unknown. Command-line HG aborts "system can't find the file specified" 186 // as unknown. Command-line HG aborts "system can't find the file specified"
187 // in similar case (against wc), or just gives nothing if --change <rev> is specified. 187 // in similar case (against wc), or just gives nothing if --change <rev> is specified.
212 // from baseRevFiles, it might need to be reported as removed as well (cmdline client does 212 // from baseRevFiles, it might need to be reported as removed as well (cmdline client does
213 // yield two statuses for the same file) 213 // yield two statuses for the same file)
214 } 214 }
215 } 215 }
216 if (collect != null) { 216 if (collect != null) {
217 for (String r : baseRevFiles) { 217 for (Path fromBase : baseRevFiles) {
218 final Path fromBase = getPathPool().path(r);
219 if (repoWalker.inScope(fromBase)) { 218 if (repoWalker.inScope(fromBase)) {
220 inspector.removed(fromBase); 219 inspector.removed(fromBase);
221 } 220 }
222 } 221 }
223 } 222 }
231 // not removed from the repository = 'deleted' 230 // not removed from the repository = 'deleted'
232 inspector.missing(m); 231 inspector.missing(m);
233 } else { 232 } else {
234 // removed from the repo 233 // removed from the repo
235 // if we check against non-tip revision, do not report files that were added past that revision and now removed. 234 // if we check against non-tip revision, do not report files that were added past that revision and now removed.
236 if (collect == null || baseRevFiles.contains(m.toString())) { 235 if (collect == null || baseRevFiles.contains(m)) {
237 inspector.removed(m); 236 inspector.removed(m);
238 } 237 }
239 } 238 }
240 } 239 }
241 } 240 }
260 inspector.modified(fname); 259 inspector.modified(fname);
261 } else { 260 } else {
262 // size is the same or unknown, and, perhaps, different timestamp 261 // size is the same or unknown, and, perhaps, different timestamp
263 // check actual content to avoid false modified files 262 // check actual content to avoid false modified files
264 HgDataFile df = repo.getFileNode(fname); 263 HgDataFile df = repo.getFileNode(fname);
265 Nodeid rev = getDirstateParentManifest().nodeid(fname.toString()); 264 Nodeid rev = getDirstateParentManifest().nodeid(fname);
266 if (!areTheSame(f, df, rev)) { 265 if (!areTheSame(f, df, rev)) {
267 inspector.modified(df.getPath()); 266 inspector.modified(df.getPath());
268 } else { 267 } else {
269 inspector.clean(df.getPath()); 268 inspector.clean(df.getPath());
270 } 269 }
286 private static int getFileModificationTime(File f) { 285 private static int getFileModificationTime(File f) {
287 return (int) (f.lastModified() / 1000); 286 return (int) (f.lastModified() / 1000);
288 } 287 }
289 288
290 // XXX refactor checkLocalStatus methods in more OO way 289 // XXX refactor checkLocalStatus methods in more OO way
291 private void checkLocalStatusAgainstBaseRevision(Set<String> baseRevNames, ManifestRevision collect, int baseRevision, Path fname, File f, HgStatusInspector inspector) { 290 private void checkLocalStatusAgainstBaseRevision(Set<Path> baseRevNames, ManifestRevision collect, int baseRevision, Path fname, File f, HgStatusInspector inspector) {
292 // fname is in the dirstate, either Normal, Added, Removed or Merged 291 // fname is in the dirstate, either Normal, Added, Removed or Merged
293 Nodeid nid1 = collect.nodeid(fname.toString()); 292 Nodeid nid1 = collect.nodeid(fname);
294 String flags = collect.flags(fname.toString()); 293 HgManifest.Flags flags = collect.flags(fname);
295 HgDirstate.Record r; 294 HgDirstate.Record r;
296 if (nid1 == null) { 295 if (nid1 == null) {
297 // normal: added? 296 // normal: added?
298 // added: not known at the time of baseRevision, shall report 297 // added: not known at the time of baseRevision, shall report
299 // merged: was not known, report as added? 298 // merged: was not known, report as added?
309 // FIXME report to a mediator, continue status collection 308 // FIXME report to a mediator, continue status collection
310 } 309 }
311 } else if ((r = getDirstate().checkAdded(fname)) != null) { 310 } else if ((r = getDirstate().checkAdded(fname)) != null) {
312 if (r.name2 != null && baseRevNames.contains(r.name2)) { 311 if (r.name2 != null && baseRevNames.contains(r.name2)) {
313 baseRevNames.remove(r.name2); // XXX surely I shall not report rename source as Removed? 312 baseRevNames.remove(r.name2); // XXX surely I shall not report rename source as Removed?
314 inspector.copied(getPathPool().path(r.name2), fname); 313 inspector.copied(r.name2, fname);
315 return; 314 return;
316 } 315 }
317 // fall-through, report as added 316 // fall-through, report as added
318 } else if (getDirstate().checkRemoved(fname) != null) { 317 } else if (getDirstate().checkRemoved(fname) != null) {
319 // removed: removed file was not known at the time of baseRevision, and we should not report it as removed 318 // removed: removed file was not known at the time of baseRevision, and we should not report it as removed
320 return; 319 return;
321 } 320 }
322 inspector.added(fname); 321 inspector.added(fname);
323 } else { 322 } else {
324 // was known; check whether clean or modified 323 // was known; check whether clean or modified
325 Nodeid nidFromDirstate = getDirstateParentManifest().nodeid(fname.toString()); 324 Nodeid nidFromDirstate = getDirstateParentManifest().nodeid(fname);
326 if ((r = getDirstate().checkNormal(fname)) != null && nid1.equals(nidFromDirstate)) { 325 if ((r = getDirstate().checkNormal(fname)) != null && nid1.equals(nidFromDirstate)) {
327 // regular file, was the same up to WC initialization. Check if was modified since, and, if not, report right away 326 // regular file, was the same up to WC initialization. Check if was modified since, and, if not, report right away
328 // same code as in #checkLocalStatusAgainstFile 327 // same code as in #checkLocalStatusAgainstFile
329 final boolean timestampEqual = getFileModificationTime(f) == r.time, sizeEqual = r.size == f.length(); 328 final boolean timestampEqual = getFileModificationTime(f) == r.time, sizeEqual = r.size == f.length();
330 boolean handled = false; 329 boolean handled = false;
338 // seems like flags have changed, no reason to check content further 337 // seems like flags have changed, no reason to check content further
339 inspector.modified(fname); 338 inspector.modified(fname);
340 handled = true; 339 handled = true;
341 } 340 }
342 if (handled) { 341 if (handled) {
343 baseRevNames.remove(fname.toString()); // consumed, processed, handled. 342 baseRevNames.remove(fname); // consumed, processed, handled.
344 return; 343 return;
345 } 344 }
346 // otherwise, shall check actual content (size not the same, or unknown (-1 or -2), or timestamp is different, 345 // otherwise, shall check actual content (size not the same, or unknown (-1 or -2), or timestamp is different,
347 // or nodeid in dirstate is different, but local change might have brought it back to baseRevision state) 346 // or nodeid in dirstate is different, but local change might have brought it back to baseRevision state)
348 // FALL THROUGH 347 // FALL THROUGH
355 if (areTheSame(f, fileNode, nid1)) { 354 if (areTheSame(f, fileNode, nid1)) {
356 inspector.clean(fname); 355 inspector.clean(fname);
357 } else { 356 } else {
358 inspector.modified(fname); 357 inspector.modified(fname);
359 } 358 }
360 baseRevNames.remove(fname.toString()); // consumed, processed, handled. 359 baseRevNames.remove(fname); // consumed, processed, handled.
361 } else if (getDirstate().checkRemoved(fname) != null) { 360 } else if (getDirstate().checkRemoved(fname) != null) {
362 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later 361 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later
363 inspector.removed(fname); 362 inspector.removed(fname);
364 baseRevNames.remove(fname.toString()); // consumed, processed, handled. 363 baseRevNames.remove(fname); // consumed, processed, handled.
365 } 364 }
366 // only those left in baseRevNames after processing are reported as removed 365 // only those left in baseRevNames after processing are reported as removed
367 } 366 }
368 367
369 // TODO think over if content comparison may be done more effectively by e.g. calculating nodeid for a local file and comparing it with nodeid from manifest 368 // TODO think over if content comparison may be done more effectively by e.g. calculating nodeid for a local file and comparing it with nodeid from manifest
449 ex.printStackTrace(); 448 ex.printStackTrace();
450 } 449 }
451 return false; 450 return false;
452 } 451 }
453 452
454 private static boolean todoCheckFlagsEqual(File f, String manifestFlags) { 453 private static boolean todoCheckFlagsEqual(File f, HgManifest.Flags originalManifestFlags) {
455 // FIXME implement 454 // FIXME implement
456 return true; 455 return true;
457 } 456 }
458 457
459 /** 458 /**