tikhomirov@21: /* tikhomirov@21: * Copyright (c) 2010, 2011 Artem Tikhomirov tikhomirov@0: */ tikhomirov@0: package com.tmate.hgkit.ll; tikhomirov@0: tikhomirov@2: import java.util.ArrayList; tikhomirov@3: import java.util.Arrays; tikhomirov@2: import java.util.List; tikhomirov@2: tikhomirov@0: /** tikhomirov@0: * Representation of the Mercurial changelog file (list of ChangeSets) tikhomirov@0: * @author artem tikhomirov@0: */ tikhomirov@2: public class Changelog extends Revlog { tikhomirov@0: tikhomirov@3: /*package-local*/ Changelog(HgRepository hgRepo, RevlogStream content) { tikhomirov@21: super(hgRepo, content); tikhomirov@2: } tikhomirov@2: tikhomirov@3: public void all(final Changeset.Inspector inspector) { tikhomirov@3: Revlog.Inspector i = new Revlog.Inspector() { tikhomirov@3: tikhomirov@3: public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { tikhomirov@3: Changeset cset = Changeset.parse(data, 0, data.length); tikhomirov@3: // XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse tikhomirov@47: inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); tikhomirov@3: } tikhomirov@3: }; tikhomirov@3: content.iterate(0, content.revisionCount() - 1, true, i); tikhomirov@2: } tikhomirov@2: tikhomirov@2: public List range(int start, int end) { tikhomirov@2: final ArrayList rv = new ArrayList(end - start + 1); tikhomirov@2: Revlog.Inspector i = new Revlog.Inspector() { tikhomirov@2: tikhomirov@3: public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { tikhomirov@3: Changeset cset = Changeset.parse(data, 0, data.length); tikhomirov@3: rv.add(cset); tikhomirov@2: } tikhomirov@2: }; tikhomirov@2: content.iterate(start, end, true, i); tikhomirov@2: return rv; tikhomirov@2: } tikhomirov@3: tikhomirov@3: public void range(final Changeset.Inspector inspector, final int... revisions) { tikhomirov@3: if (revisions == null || revisions.length == 0) { tikhomirov@3: return; tikhomirov@3: } tikhomirov@3: Revlog.Inspector i = new Revlog.Inspector() { tikhomirov@3: tikhomirov@3: public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) { tikhomirov@3: if (Arrays.binarySearch(revisions, revisionNumber) >= 0) { tikhomirov@3: Changeset cset = Changeset.parse(data, 0, data.length); tikhomirov@47: inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset); tikhomirov@3: } tikhomirov@3: } tikhomirov@3: }; tikhomirov@3: Arrays.sort(revisions); tikhomirov@3: content.iterate(revisions[0], revisions[revisions.length - 1], true, i); tikhomirov@3: } tikhomirov@0: }