Mercurial > hg4j
diff 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 |
line wrap: on
line diff
--- 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 <code>null</code> + * @param logFacility log facility from the session context + * @param chain <code>null</code> if no further data processing other than metadata is desired + */ public MetadataInspector(Metadata _metadata, LogFacility logFacility, RevlogStream.Inspector chain) { metadata = _metadata; log = logFacility;