diff src/org/tmatesoft/hg/repo/Changelog.java @ 74:6f1b88693d48

Complete refactoring to org.tmatesoft
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 24 Jan 2011 03:14:45 +0100
parents src/com/tmate/hgkit/ll/Changelog.java@e34f90b9ded1
children c677e1593919
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/tmatesoft/hg/repo/Changelog.java	Mon Jan 24 03:14:45 2011 +0100
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2010-2011 TMate Software Ltd
+ *  
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * For information on how to redistribute this software under
+ * the terms of a license other than GNU General Public License
+ * contact TMate Software at support@svnkit.com
+ */
+package org.tmatesoft.hg.repo;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.tmatesoft.hg.core.Nodeid;
+
+
+/**
+ * Representation of the Mercurial changelog file (list of ChangeSets)
+ *
+ * @author Artem Tikhomirov
+ * @author TMate Software Ltd.
+ */
+public class Changelog extends Revlog {
+
+	/*package-local*/ Changelog(HgRepository hgRepo, RevlogStream content) {
+		super(hgRepo, content);
+	}
+
+	public void all(final Changeset.Inspector inspector) {
+		range(0, content.revisionCount() - 1, inspector);
+	}
+
+	public void range(int start, int end, final Changeset.Inspector inspector) {
+		Revlog.Inspector i = new Revlog.Inspector() {
+			
+			public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
+				Changeset cset = Changeset.parse(data, 0, data.length);
+				// XXX there's no guarantee for Changeset.Callback that distinct instance comes each time, consider instance reuse
+				inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset);
+			}
+		};
+		content.iterate(start, end, true, i);
+	}
+
+	public List<Changeset> range(int start, int end) {
+		final ArrayList<Changeset> rv = new ArrayList<Changeset>(end - start + 1);
+		Revlog.Inspector i = new Revlog.Inspector() {
+			
+			public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
+				Changeset cset = Changeset.parse(data, 0, data.length);
+				rv.add(cset);
+			}
+		};
+		content.iterate(start, end, true, i);
+		return rv; 
+	}
+
+	public void range(final Changeset.Inspector inspector, final int... revisions) {
+		if (revisions == null || revisions.length == 0) {
+			return;
+		}
+		Revlog.Inspector i = new Revlog.Inspector() {
+			
+			public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
+				if (Arrays.binarySearch(revisions, revisionNumber) >= 0) {
+					Changeset cset = Changeset.parse(data, 0, data.length);
+					inspector.next(revisionNumber, Nodeid.fromBinary(nodeid, 0), cset);
+				}
+			}
+		};
+		Arrays.sort(revisions);
+		content.iterate(revisions[0], revisions[revisions.length - 1], true, i);
+	}
+}