# HG changeset patch # User Artem Tikhomirov # Date 1350655401 -7200 # Node ID abfbe81154b5180c975d25b83636535212c545fa # Parent 2743641f2f126f9b2fc63bcdd5bac4f31f0b7932 Do not use exception when only metadata processing is needed. For hg4j repo, status 0:-1 changed from 500 to 60 ms diff -r 2743641f2f12 -r abfbe81154b5 src/org/tmatesoft/hg/repo/HgDataFile.java --- a/src/org/tmatesoft/hg/repo/HgDataFile.java Thu Oct 18 19:51:07 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Fri Oct 19 16:03:21 2012 +0200 @@ -47,7 +47,6 @@ import org.tmatesoft.hg.util.ProgressSupport; - /** * Regular user data file stored in the repository. * @@ -440,23 +439,12 @@ } private void checkAndRecordMetadata(int localRev) throws HgInvalidControlFileException { - // content() always initializes metadata. - // TODO [post-1.0] this is expensive way to find out metadata, distinct RevlogStream.Iterator would be better. - // Alternatively, may parameterize MetadataContentPipe to do prepare only. - // For reference, when throwing CancelledException, hg status -A --rev 3:80 takes 70 ms - // however, if we just consume buffer instead (buffer.position(buffer.limit()), same command takes ~320ms - // (compared to command-line counterpart of 190ms) - try { - content(localRev, new ByteChannel() { // No-op channel - public int write(ByteBuffer buffer) throws IOException, CancelledException { - throw new CancelledException(); - } - }); - } catch (CancelledException ex) { - // it's ok, we did that - } catch (HgInvalidControlFileException ex) { - throw ex.isRevisionIndexSet() ? ex : ex.setRevisionIndex(localRev); + if (metadata == null) { + metadata = new Metadata(); } + // use MetadataInspector without delegate to process metadata only + RevlogStream.Inspector insp = new MetadataInspector(metadata, getRepo().getSessionContext().getLog(), null); + super.content.iterate(localRev, localRev, true, insp); } private static final class MetadataEntry { @@ -553,6 +541,11 @@ private final RevlogStream.Inspector delegate; private final LogFacility log; + /** + * @param _metadata never null + * @param logFacility log facility from the session context + * @param chain null if no further data processing other than metadata is desired + */ public MetadataInspector(Metadata _metadata, LogFacility logFacility, RevlogStream.Inspector chain) { metadata = _metadata; log = logFacility;