comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 495:abfbe81154b5

Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 19 Oct 2012 16:03:21 +0200
parents b3c16d1aede0
children e4ee4bf4c7d0
comparison
equal deleted inserted replaced
494:2743641f2f12 495:abfbe81154b5
43 import org.tmatesoft.hg.util.CancelledException; 43 import org.tmatesoft.hg.util.CancelledException;
44 import org.tmatesoft.hg.util.LogFacility; 44 import org.tmatesoft.hg.util.LogFacility;
45 import org.tmatesoft.hg.util.Pair; 45 import org.tmatesoft.hg.util.Pair;
46 import org.tmatesoft.hg.util.Path; 46 import org.tmatesoft.hg.util.Path;
47 import org.tmatesoft.hg.util.ProgressSupport; 47 import org.tmatesoft.hg.util.ProgressSupport;
48
49 48
50 49
51 /** 50 /**
52 * Regular user data file stored in the repository. 51 * Regular user data file stored in the repository.
53 * 52 *
438 sb.append(')'); 437 sb.append(')');
439 return sb.toString(); 438 return sb.toString();
440 } 439 }
441 440
442 private void checkAndRecordMetadata(int localRev) throws HgInvalidControlFileException { 441 private void checkAndRecordMetadata(int localRev) throws HgInvalidControlFileException {
443 // content() always initializes metadata. 442 if (metadata == null) {
444 // TODO [post-1.0] this is expensive way to find out metadata, distinct RevlogStream.Iterator would be better. 443 metadata = new Metadata();
445 // Alternatively, may parameterize MetadataContentPipe to do prepare only. 444 }
446 // For reference, when throwing CancelledException, hg status -A --rev 3:80 takes 70 ms 445 // use MetadataInspector without delegate to process metadata only
447 // however, if we just consume buffer instead (buffer.position(buffer.limit()), same command takes ~320ms 446 RevlogStream.Inspector insp = new MetadataInspector(metadata, getRepo().getSessionContext().getLog(), null);
448 // (compared to command-line counterpart of 190ms) 447 super.content.iterate(localRev, localRev, true, insp);
449 try {
450 content(localRev, new ByteChannel() { // No-op channel
451 public int write(ByteBuffer buffer) throws IOException, CancelledException {
452 throw new CancelledException();
453 }
454 });
455 } catch (CancelledException ex) {
456 // it's ok, we did that
457 } catch (HgInvalidControlFileException ex) {
458 throw ex.isRevisionIndexSet() ? ex : ex.setRevisionIndex(localRev);
459 }
460 } 448 }
461 449
462 private static final class MetadataEntry { 450 private static final class MetadataEntry {
463 private final String entry; 451 private final String entry;
464 private final int valueStart; 452 private final int valueStart;
551 private static class MetadataInspector extends ErrorHandlingInspector implements RevlogStream.Inspector { 539 private static class MetadataInspector extends ErrorHandlingInspector implements RevlogStream.Inspector {
552 private final Metadata metadata; 540 private final Metadata metadata;
553 private final RevlogStream.Inspector delegate; 541 private final RevlogStream.Inspector delegate;
554 private final LogFacility log; 542 private final LogFacility log;
555 543
544 /**
545 * @param _metadata never <code>null</code>
546 * @param logFacility log facility from the session context
547 * @param chain <code>null</code> if no further data processing other than metadata is desired
548 */
556 public MetadataInspector(Metadata _metadata, LogFacility logFacility, RevlogStream.Inspector chain) { 549 public MetadataInspector(Metadata _metadata, LogFacility logFacility, RevlogStream.Inspector chain) {
557 metadata = _metadata; 550 metadata = _metadata;
558 log = logFacility; 551 log = logFacility;
559 delegate = chain; 552 delegate = chain;
560 setCancelSupport(CancelSupport.Factory.get(chain)); 553 setCancelSupport(CancelSupport.Factory.get(chain));