diff src/com/tmate/hgkit/ll/Changeset.java @ 5:fc265ddeab26

File content and non-effective, although working, patch application
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 21 Dec 2010 05:11:06 +0100
parents 24bb4f365164
children 50dfc69c108e
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/Changeset.java	Mon Dec 20 04:20:52 2010 +0100
+++ b/src/com/tmate/hgkit/ll/Changeset.java	Tue Dec 21 05:11:06 2010 +0100
@@ -44,30 +44,35 @@
 
 	public static Changeset parse(byte[] data, int offset, int length) {
 		Changeset rv = new Changeset();
+		rv.init(data, offset, length);
+		return rv;
+	}
+
+	/*package-local*/ void init(byte[] data, int offset, int length) {
 		final int bufferEndIndex = offset + length;
 		final byte lineBreak = (byte) '\n';
 		int breakIndex1 = indexOf(data, lineBreak, offset, bufferEndIndex);
 		if (breakIndex1 == -1) {
 			throw new IllegalArgumentException("Bad Changeset data");
 		}
-		rv.nodeid = Nodeid.fromAscii(data, 0, breakIndex1);
+		Nodeid _nodeid = Nodeid.fromAscii(data, 0, breakIndex1);
 		int breakIndex2 = indexOf(data, lineBreak, breakIndex1+1, bufferEndIndex);
 		if (breakIndex2 == -1) {
 			throw new IllegalArgumentException("Bad Changeset data");
 		}
-		rv.user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1);
+		String _user = new String(data, breakIndex1+1, breakIndex2 - breakIndex1 - 1);
 		int breakIndex3 = indexOf(data, lineBreak, breakIndex2+1, bufferEndIndex);
 		if (breakIndex3 == -1) {
 			throw new IllegalArgumentException("Bad Changeset data");
 		}
-		rv.timezone = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1);
+		String _timezone = new String(data, breakIndex2+1, breakIndex3 - breakIndex2 - 1);
 		
 		//
 		int lastStart = breakIndex3 + 1;
 		int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
-		rv.files = new ArrayList<String>(5);
+		ArrayList<String> _files = new ArrayList<String>(5);
 		while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
-			rv.files.add(new String(data, lastStart, breakIndex4 - lastStart));
+			_files.add(new String(data, lastStart, breakIndex4 - lastStart));
 			lastStart = breakIndex4 + 1;
 			if (data[breakIndex4 + 1] == lineBreak) {
 				// found \n\n
@@ -79,13 +84,19 @@
 		if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
 			throw new IllegalArgumentException("Bad Changeset data");
 		}
+		String _comment;
 		try {
-			rv.comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8");
+			_comment = new String(data, breakIndex4+2, bufferEndIndex - breakIndex4 - 2, "UTF-8");
 		} catch (UnsupportedEncodingException ex) {
-			rv.comment = "";
+			_comment = "";
 			throw new IllegalStateException("Could hardly happen");
 		}
-		return rv;
+		// change this instance at once, don't leave it partially changes in case of error
+		this.nodeid = _nodeid;
+		this.user = _user;
+		this.timezone = _timezone;
+		this.files = _files;
+		this.comment = _comment;
 	}
 
 	private static int indexOf(byte[] src, byte what, int startOffset, int endIndex) {