changeset 358:fc8bc2f1edbe v0.7.0

Clean internal classes from public API
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 06 Dec 2011 20:02:48 +0100
parents dfb8405d996f
children 1d9bcab9c50f
files src/org/tmatesoft/hg/core/HgCloneCommand.java src/org/tmatesoft/hg/repo/HgBundle.java
diffstat 2 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgCloneCommand.java	Tue Dec 06 19:47:01 2011 +0100
+++ b/src/org/tmatesoft/hg/core/HgCloneCommand.java	Tue Dec 06 20:02:48 2011 +0100
@@ -254,7 +254,7 @@
 					prevRevContent = new ByteArrayDataAccess(new byte[0]);
 					writeComplete = true;
 				}
-				byte[] content = ge.apply(prevRevContent);
+				byte[] content = ge.apply(prevRevContent.byteArray());
 				byte[] calculated = dh.sha1(p1, p2, content).asBinary();
 				final Nodeid node = ge.node();
 				if (!node.equalsTo(calculated)) {
@@ -272,12 +272,12 @@
 					link = csRev.intValue();
 				}
 				final int p1Rev = knownRevision(p1), p2Rev = knownRevision(p2);
-				DataAccess patchContent = ge.rawData();
-				writeComplete = writeComplete || patchContent.length() >= (/* 3/4 of actual */content.length - (content.length >>> 2));
+				byte[] patchContent = ge.rawDataByteArray();
+				writeComplete = writeComplete || patchContent.length >= (/* 3/4 of actual */content.length - (content.length >>> 2));
 				if (writeComplete) {
 					base = revisionSequence.size();
 				}
-				final byte[] sourceData = writeComplete ? content : patchContent.byteArray();
+				final byte[] sourceData = writeComplete ? content : patchContent;
 				final byte[] data;
 				ByteArrayOutputStream bos = new ByteArrayOutputStream(content.length);
 				DeflaterOutputStream dos = new DeflaterOutputStream(bos);
--- a/src/org/tmatesoft/hg/repo/HgBundle.java	Tue Dec 06 19:47:01 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/HgBundle.java	Tue Dec 06 20:02:48 2011 +0100
@@ -29,6 +29,7 @@
 import org.tmatesoft.hg.internal.DataAccess;
 import org.tmatesoft.hg.internal.DataAccessProvider;
 import org.tmatesoft.hg.internal.DigestHelper;
+import org.tmatesoft.hg.internal.Experimental;
 import org.tmatesoft.hg.internal.InflaterDataAccess;
 import org.tmatesoft.hg.internal.Patch;
 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
@@ -358,7 +359,7 @@
 		}
 	}
 
-	// FIXME GroupElement exposes some internal API!!! (DataAccess)
+	@Experimental(reason="Cumbersome API, rawData and apply with byte[] perhaps need replacement with ByteChannel/ByteBuffer, and better Exceptions. Perhaps, shall split into interface and impl")
 	public static class GroupElement {
 		private final byte[] header; // byte[80] takes 120 bytes, 4 Nodeids - 192
 		private final DataAccess dataAccess;
@@ -370,27 +371,47 @@
 			dataAccess = rawDataAccess;
 		}
 
-		// non-null
+		/**
+		 * <b>node</b> field of the group element
+		 * @return node revision, never <code>null</code>
+		 */
 		public Nodeid node() {
 			return Nodeid.fromBinary(header, 0);
 		}
 
-		// non-null
+		/**
+		 * <b>p1</b> <i>(parent 1)</i> field of the group element
+		 * @return revision of parent 1, never <code>null</code>
+		 */
 		public Nodeid firstParent() {
 			return Nodeid.fromBinary(header, 20);
 		}
 
-		// non-null
+		/**
+		 * <b>p2</b> <i>(parent 2)</i> field of the group element
+		 * @return revision of parent 2, never <code>null</code>
+		 */
 		public Nodeid secondParent() {
 			return Nodeid.fromBinary(header, 40);
 		}
 
-		// non-null
-		public Nodeid cset() { // cs seems to be changeset
+		/**
+		 * <b>cs</b> <i>(changeset link)</i> field of the group element
+		 * @return changeset revision, never <code>null</code>
+		 */
+		public Nodeid cset() {
 			return Nodeid.fromBinary(header, 60);
 		}
+		
+		public byte[] rawDataByteArray() throws IOException { // XXX IOException or HgInvalidFileException?
+			return rawData().byteArray();
+		}
+		
+		public byte[] apply(byte[] baseContent) throws IOException {
+			return apply(new ByteArrayDataAccess(baseContent));
+		}
 
-		public DataAccess rawData() {
+		/*package-local*/ DataAccess rawData() {
 			return dataAccess;
 		}
 		
@@ -403,7 +424,7 @@
 			return patches;
 		}
 
-		public byte[] apply(DataAccess baseContent) throws IOException {
+		/*package-local*/ byte[] apply(DataAccess baseContent) throws IOException {
 			return patch().apply(baseContent, -1);
 		}