diff src/com/tmate/hgkit/ll/Changelog.java @ 3:24bb4f365164

Rudimentary log functionality with basic infrastructure is in place
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 Dec 2010 02:50:36 +0100
parents 08db726a0fb7
children e929cecae4e1
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/Changelog.java	Sun Dec 19 05:41:31 2010 +0100
+++ b/src/com/tmate/hgkit/ll/Changelog.java	Mon Dec 20 02:50:36 2010 +0100
@@ -3,11 +3,8 @@
  */
 package com.tmate.hgkit.ll;
 
-import java.io.DataInput;
-import java.io.EOFException;
-import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -16,35 +13,52 @@
  */
 public class Changelog extends Revlog {
 
-	private RevlogStream content;
+	private final RevlogStream content;
 
-	/*package-local*/ Changelog(HgRepository hgRepo) {
+	/*package-local*/ Changelog(HgRepository hgRepo, RevlogStream content) {
 		super(hgRepo);
-		content = hgRepo.resolve(".hg/store/00changelog.i");
+		this.content = content;
 	}
 
-	public List<Changeset> all() {
-		throw HgRepository.notImplemented();
-	}
-	
-	public void all(Changeset.Callback callback) {
-		throw HgRepository.notImplemented();
+	public void all(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(cset);
+			}
+		};
+		content.iterate(0, content.revisionCount() - 1, true, i);
 	}
 
 	public List<Changeset> range(int start, int end) {
-		//read from outline[start].start .. (outline[end].start + outline[end].length)
-		// parse changesets
 		final ArrayList<Changeset> rv = new ArrayList<Changeset>(end - start + 1);
 		Revlog.Inspector i = new Revlog.Inspector() {
 			
-			public void next(int compressedLen, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
-				// TODO Auto-generated method stub
-				Changeset.parse(data);
-				i.add();
-				throw HgRepository.notImplemented();
+			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(cset);
+				}
+			}
+		};
+		Arrays.sort(revisions);
+		content.iterate(revisions[0], revisions[revisions.length - 1], true, i);
+	}
 }