comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 490:b3c16d1aede0

Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 16 Aug 2012 17:08:34 +0200
parents 5c09a9f2e073
children ba36f66c32b4
comparison
equal deleted inserted replaced
489:9c0138cda59a 490:b3c16d1aede0
363 } else { 363 } else {
364 inspector.clean(df.getPath()); 364 inspector.clean(df.getPath());
365 } 365 }
366 } 366 }
367 } catch (HgRuntimeException ex) { 367 } catch (HgRuntimeException ex) {
368 repo.getContext().getLog().dump(getClass(), Warn, ex, null); 368 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null);
369 inspector.invalid(fname, ex); 369 inspector.invalid(fname, ex);
370 } 370 }
371 } 371 }
372 } else if ((r = getDirstateImpl().checkAdded(fname)) != null) { 372 } else if ((r = getDirstateImpl().checkAdded(fname)) != null) {
373 if (r.copySource() == null) { 373 if (r.copySource() == null) {
455 inspector.clean(fname); 455 inspector.clean(fname);
456 } else { 456 } else {
457 inspector.modified(fname); 457 inspector.modified(fname);
458 } 458 }
459 } catch (HgRuntimeException ex) { 459 } catch (HgRuntimeException ex) {
460 repo.getContext().getLog().dump(getClass(), Warn, ex, null); 460 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null);
461 inspector.invalid(fname, ex); 461 inspector.invalid(fname, ex);
462 } 462 }
463 baseRevNames.remove(fname); // consumed, processed, handled. 463 baseRevNames.remove(fname); // consumed, processed, handled.
464 } else if (getDirstateImpl().checkRemoved(fname) != null) { 464 } else if (getDirstateImpl().checkRemoved(fname) != null) {
465 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later 465 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later
492 } 492 }
493 493
494 private boolean areTheSame(FileInfo f, final byte[] data, Path p) throws HgInvalidFileException { 494 private boolean areTheSame(FileInfo f, final byte[] data, Path p) throws HgInvalidFileException {
495 ReadableByteChannel is = null; 495 ReadableByteChannel is = null;
496 class Check implements ByteChannel { 496 class Check implements ByteChannel {
497 final boolean debug = repo.getContext().getLog().isDebug(); 497 final boolean debug = repo.getSessionContext().getLog().isDebug();
498 boolean sameSoFar = true; 498 boolean sameSoFar = true;
499 int x = 0; 499 int x = 0;
500 500
501 public int write(ByteBuffer buffer) { 501 public int write(ByteBuffer buffer) {
502 for (int i = buffer.remaining(); i > 0; i--, x++) { 502 for (int i = buffer.remaining(); i > 0; i--, x++) {
512 exp = new String(data, max(0, x - 4), min(data.length - x, 20)); 512 exp = new String(data, max(0, x - 4), min(data.length - x, 20));
513 } else { 513 } else {
514 int offset = max(0, x - 4); 514 int offset = max(0, x - 4);
515 exp = new String(data, offset, min(data.length - offset, 20)); 515 exp = new String(data, offset, min(data.length - offset, 20));
516 } 516 }
517 repo.getContext().getLog().dump(getClass(), Debug, "expected >>%s<< but got >>%s<<", exp, new String(xx)); 517 repo.getSessionContext().getLog().dump(getClass(), Debug, "expected >>%s<< but got >>%s<<", exp, new String(xx));
518 } 518 }
519 sameSoFar = false; 519 sameSoFar = false;
520 break; 520 break;
521 } 521 }
522 } 522 }
545 } 545 }
546 // reset channel to read once again 546 // reset channel to read once again
547 try { 547 try {
548 is.close(); 548 is.close();
549 } catch (IOException ex) { 549 } catch (IOException ex) {
550 repo.getContext().getLog().dump(getClass(), Info, ex, null); 550 repo.getSessionContext().getLog().dump(getClass(), Info, ex, null);
551 } 551 }
552 is = f.newInputChannel(); 552 is = f.newInputChannel();
553 fb.clear(); 553 fb.clear();
554 } 554 }
555 while (is.read(fb) != -1 && check.sameSoFar()) { 555 while (is.read(fb) != -1 && check.sameSoFar()) {
557 filters.write(fb); 557 filters.write(fb);
558 fb.compact(); 558 fb.compact();
559 } 559 }
560 return check.ultimatelyTheSame(); 560 return check.ultimatelyTheSame();
561 } catch (CancelledException ex) { 561 } catch (CancelledException ex) {
562 repo.getContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation"); 562 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation");
563 return check.ultimatelyTheSame(); 563 return check.ultimatelyTheSame();
564 } catch (IOException ex) { 564 } catch (IOException ex) {
565 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p); 565 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p);
566 } finally { 566 } finally {
567 if (is != null) { 567 if (is != null) {
568 try { 568 try {
569 is.close(); 569 is.close();
570 } catch (IOException ex) { 570 } catch (IOException ex) {
571 repo.getContext().getLog().dump(getClass(), Info, ex, null); 571 repo.getSessionContext().getLog().dump(getClass(), Info, ex, null);
572 } 572 }
573 } 573 }
574 } 574 }
575 } 575 }
576 576
629 } 629 }
630 } 630 }
631 // final Path[] dirs = f.toArray(new Path[d.size()]); 631 // final Path[] dirs = f.toArray(new Path[d.size()]);
632 if (d.isEmpty()) { 632 if (d.isEmpty()) {
633 final Path[] files = f.toArray(new Path[f.size()]); 633 final Path[] files = f.toArray(new Path[f.size()]);
634 FileIterator fi = new FileListIterator(hgRepo.getContext(), hgRepo.getWorkingDir(), files); 634 FileIterator fi = new FileListIterator(hgRepo.getSessionContext(), hgRepo.getWorkingDir(), files);
635 return new HgWorkingCopyStatusCollector(hgRepo, fi); 635 return new HgWorkingCopyStatusCollector(hgRepo, fi);
636 } 636 }
637 // 637 //
638 638
639 //FileIterator fi = file.isDirectory() ? new DirFileIterator(hgRepo, file) : new FileListIterator(, file); 639 //FileIterator fi = file.isDirectory() ? new DirFileIterator(hgRepo, file) : new FileListIterator(, file);