comparison src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 456:909306e412e2

Refactor LogFacility and SessionContext, better API for both
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 18 Jun 2012 16:54:00 +0200
parents 12f668401613
children 7bcfbc255f48
comparison
equal deleted inserted replaced
454:36fd1fd06492 456:909306e412e2
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import static java.lang.Math.max; 19 import static java.lang.Math.max;
20 import static java.lang.Math.min; 20 import static java.lang.Math.min;
21 import static org.tmatesoft.hg.repo.HgRepository.*; 21 import static org.tmatesoft.hg.repo.HgRepository.*;
22 import static org.tmatesoft.hg.util.LogFacility.Severity.*;
22 23
23 import java.io.File; 24 import java.io.File;
24 import java.io.IOException; 25 import java.io.IOException;
25 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
26 import java.nio.channels.ReadableByteChannel; 27 import java.nio.channels.ReadableByteChannel;
31 import java.util.TreeSet; 32 import java.util.TreeSet;
32 33
33 import org.tmatesoft.hg.core.Nodeid; 34 import org.tmatesoft.hg.core.Nodeid;
34 import org.tmatesoft.hg.core.SessionContext; 35 import org.tmatesoft.hg.core.SessionContext;
35 import org.tmatesoft.hg.internal.ByteArrayChannel; 36 import org.tmatesoft.hg.internal.ByteArrayChannel;
36 import org.tmatesoft.hg.internal.Experimental;
37 import org.tmatesoft.hg.internal.FilterByteChannel; 37 import org.tmatesoft.hg.internal.FilterByteChannel;
38 import org.tmatesoft.hg.internal.Internals; 38 import org.tmatesoft.hg.internal.Internals;
39 import org.tmatesoft.hg.internal.ManifestRevision; 39 import org.tmatesoft.hg.internal.ManifestRevision;
40 import org.tmatesoft.hg.internal.PathPool; 40 import org.tmatesoft.hg.internal.PathPool;
41 import org.tmatesoft.hg.internal.PathScope; 41 import org.tmatesoft.hg.internal.PathScope;
360 } else { 360 } else {
361 inspector.clean(df.getPath()); 361 inspector.clean(df.getPath());
362 } 362 }
363 } 363 }
364 } catch (HgRuntimeException ex) { 364 } catch (HgRuntimeException ex) {
365 repo.getContext().getLog().warn(getClass(), ex, null); 365 repo.getContext().getLog().dump(getClass(), Warn, ex, null);
366 inspector.invalid(fname, ex); 366 inspector.invalid(fname, ex);
367 } 367 }
368 } 368 }
369 } else if ((r = getDirstateImpl().checkAdded(fname)) != null) { 369 } else if ((r = getDirstateImpl().checkAdded(fname)) != null) {
370 if (r.copySource() == null) { 370 if (r.copySource() == null) {
449 inspector.clean(fname); 449 inspector.clean(fname);
450 } else { 450 } else {
451 inspector.modified(fname); 451 inspector.modified(fname);
452 } 452 }
453 } catch (HgRuntimeException ex) { 453 } catch (HgRuntimeException ex) {
454 repo.getContext().getLog().warn(getClass(), ex, null); 454 repo.getContext().getLog().dump(getClass(), Warn, ex, null);
455 inspector.invalid(fname, ex); 455 inspector.invalid(fname, ex);
456 } 456 }
457 baseRevNames.remove(fname); // consumed, processed, handled. 457 baseRevNames.remove(fname); // consumed, processed, handled.
458 } else if (getDirstateImpl().checkRemoved(fname) != null) { 458 } else if (getDirstateImpl().checkRemoved(fname) != null) {
459 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later 459 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later
506 exp = new String(data, max(0, x - 4), min(data.length - x, 20)); 506 exp = new String(data, max(0, x - 4), min(data.length - x, 20));
507 } else { 507 } else {
508 int offset = max(0, x - 4); 508 int offset = max(0, x - 4);
509 exp = new String(data, offset, min(data.length - offset, 20)); 509 exp = new String(data, offset, min(data.length - offset, 20));
510 } 510 }
511 repo.getContext().getLog().debug(getClass(), "expected >>%s<< but got >>%s<<", exp, new String(xx)); 511 repo.getContext().getLog().dump(getClass(), Debug, "expected >>%s<< but got >>%s<<", exp, new String(xx));
512 } 512 }
513 sameSoFar = false; 513 sameSoFar = false;
514 break; 514 break;
515 } 515 }
516 } 516 }
539 } 539 }
540 // reset channel to read once again 540 // reset channel to read once again
541 try { 541 try {
542 is.close(); 542 is.close();
543 } catch (IOException ex) { 543 } catch (IOException ex) {
544 repo.getContext().getLog().info(getClass(), ex, null); 544 repo.getContext().getLog().dump(getClass(), Info, ex, null);
545 } 545 }
546 is = f.newInputChannel(); 546 is = f.newInputChannel();
547 fb.clear(); 547 fb.clear();
548 } 548 }
549 while (is.read(fb) != -1 && check.sameSoFar()) { 549 while (is.read(fb) != -1 && check.sameSoFar()) {
551 filters.write(fb); 551 filters.write(fb);
552 fb.compact(); 552 fb.compact();
553 } 553 }
554 return check.ultimatelyTheSame(); 554 return check.ultimatelyTheSame();
555 } catch (CancelledException ex) { 555 } catch (CancelledException ex) {
556 repo.getContext().getLog().warn(getClass(), ex, "Unexpected cancellation"); 556 repo.getContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation");
557 return check.ultimatelyTheSame(); 557 return check.ultimatelyTheSame();
558 } catch (IOException ex) { 558 } catch (IOException ex) {
559 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p); 559 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p);
560 } finally { 560 } finally {
561 if (is != null) { 561 if (is != null) {
562 try { 562 try {
563 is.close(); 563 is.close();
564 } catch (IOException ex) { 564 } catch (IOException ex) {
565 repo.getContext().getLog().info(getClass(), ex, null); 565 repo.getContext().getLog().dump(getClass(), Info, ex, null);
566 } 566 }
567 } 567 }
568 } 568 }
569 } 569 }
570 570
610 * @param hgRepo repository 610 * @param hgRepo repository
611 * @param paths repository-relative files and/or directories. Directories are processed recursively. 611 * @param paths repository-relative files and/or directories. Directories are processed recursively.
612 * 612 *
613 * @return new instance of {@link HgWorkingCopyStatusCollector}, ready to {@link #walk(int, HgStatusInspector) walk} associated working copy 613 * @return new instance of {@link HgWorkingCopyStatusCollector}, ready to {@link #walk(int, HgStatusInspector) walk} associated working copy
614 */ 614 */
615 @Experimental(reason="Provisional API")
616 public static HgWorkingCopyStatusCollector create(HgRepository hgRepo, Path... paths) { 615 public static HgWorkingCopyStatusCollector create(HgRepository hgRepo, Path... paths) {
617 ArrayList<Path> f = new ArrayList<Path>(5); 616 ArrayList<Path> f = new ArrayList<Path>(5);
618 ArrayList<Path> d = new ArrayList<Path>(5); 617 ArrayList<Path> d = new ArrayList<Path>(5);
619 for (Path p : paths) { 618 for (Path p : paths) {
620 if (p.isDirectory()) { 619 if (p.isDirectory()) {
642 * (thus supplied matcher doesn't need to care if directories to files in question are also in scope, 641 * (thus supplied matcher doesn't need to care if directories to files in question are also in scope,
643 * see {@link FileWalker#FileWalker(File, Path.Source, Path.Matcher)}) 642 * see {@link FileWalker#FileWalker(File, Path.Source, Path.Matcher)})
644 * 643 *
645 * @return new instance of {@link HgWorkingCopyStatusCollector}, ready to {@link #walk(int, HgStatusInspector) walk} associated working copy 644 * @return new instance of {@link HgWorkingCopyStatusCollector}, ready to {@link #walk(int, HgStatusInspector) walk} associated working copy
646 */ 645 */
647 @Experimental(reason="Provisional API. May add boolean strict argument for those who write smart matchers that can be used in FileWalker")
648 public static HgWorkingCopyStatusCollector create(HgRepository hgRepo, Path.Matcher scope) { 646 public static HgWorkingCopyStatusCollector create(HgRepository hgRepo, Path.Matcher scope) {
649 FileIterator w = new HgInternals(hgRepo).createWorkingDirWalker(null); 647 FileIterator w = new HgInternals(hgRepo).createWorkingDirWalker(null);
650 FileIterator wf = (scope == null || scope instanceof Path.Matcher.Any) ? w : new FileIteratorFilter(w, scope); 648 FileIterator wf = (scope == null || scope instanceof Path.Matcher.Any) ? w : new FileIteratorFilter(w, scope);
651 // the reason I need to iterate over full repo and apply filter is that I have no idea whatsoever about 649 // the reason I need to iterate over full repo and apply filter is that I have no idea whatsoever about
652 // patterns in the scope. I.e. if scope lists a file (PathGlobMatcher("a/b/c.txt")), FileWalker won't get deep 650 // patterns in the scope. I.e. if scope lists a file (PathGlobMatcher("a/b/c.txt")), FileWalker won't get deep