changeset 87:25f2e5d1cd8b

Fix IAE when changeset has no files listed (merged revision)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 26 Jan 2011 01:07:26 +0100
parents ee4458416579
children 61eedab3eb3e
files .hgignore src/org/tmatesoft/hg/core/Cset.java src/org/tmatesoft/hg/repo/Changeset.java
diffstat 3 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Jan 26 01:06:37 2011 +0100
+++ b/.hgignore	Wed Jan 26 01:07:26 2011 +0100
@@ -3,3 +3,4 @@
 src/Extras.java
 jhg.jar
 jhg-tests.jar
+jhg-cl.jar
--- a/src/org/tmatesoft/hg/core/Cset.java	Wed Jan 26 01:06:37 2011 +0100
+++ b/src/org/tmatesoft/hg/core/Cset.java	Wed Jan 26 01:07:26 2011 +0100
@@ -85,6 +85,10 @@
 	}
 
 	public List<Path> getAffectedFiles() {
+		// reports files as recorded in changelog. Note, merge revisions may have no
+		// files listed, and thus this method would return empty list, while
+		// #getModifiedFiles() would return list with merged file(s) (because it uses status to get 'em, not
+		// what #files() gives).
 		ArrayList<Path> rv = new ArrayList<Path>(changeset.files().size());
 		for (String name : changeset.files()) {
 			rv.add(pathHelper.path(name));
--- a/src/org/tmatesoft/hg/repo/Changeset.java	Wed Jan 26 01:06:37 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/Changeset.java	Wed Jan 26 01:07:26 2011 +0100
@@ -179,19 +179,25 @@
 		//
 		int lastStart = breakIndex3 + 1;
 		int breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
-		ArrayList<String> _files = new ArrayList<String>(5);
-		while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
-			_files.add(new String(data, lastStart, breakIndex4 - lastStart));
-			lastStart = breakIndex4 + 1;
-			if (data[breakIndex4 + 1] == lineBreak) {
-				// found \n\n
-				break;
-			} else {
-				breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
+		ArrayList<String> _files = null;
+		if (breakIndex4 > lastStart) {
+			// if breakIndex4 == lastStart, we already found \n\n and hence there are no files (e.g. merge revision)
+			_files = new ArrayList<String>(5);
+			while (breakIndex4 != -1 && breakIndex4 + 1 < bufferEndIndex) {
+				_files.add(new String(data, lastStart, breakIndex4 - lastStart));
+				lastStart = breakIndex4 + 1;
+				if (data[breakIndex4 + 1] == lineBreak) {
+					// found \n\n
+					break;
+				} else {
+					breakIndex4 = indexOf(data, lineBreak, lastStart, bufferEndIndex);
+				}
 			}
-		}
-		if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
-			throw new IllegalArgumentException("Bad Changeset data");
+			if (breakIndex4 == -1 || breakIndex4 >= bufferEndIndex) {
+				throw new IllegalArgumentException("Bad Changeset data");
+			}
+		} else {
+			breakIndex4--;
 		}
 		String _comment;
 		try {
@@ -205,7 +211,7 @@
 		this.user = _user;
 		this.time = _time;
 		this.timezone = _timezone;
-		this.files = Collections.unmodifiableList(_files);
+		this.files = _files == null ? Collections.<String>emptyList() : Collections.unmodifiableList(_files);
 		this.comment = _comment;
 		this.extras = _extrasMap;
 	}