changeset 377:86f049e6bcae

Issue 22: Test for subsequent empty manifest entries case for separate .i and .d repository control files
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 02 Feb 2012 16:16:19 +0100
parents d45ad07dc94c
children 9fb990c8a724
files src/org/tmatesoft/hg/internal/RevlogStream.java test-data/test-repos.jar test/org/tmatesoft/hg/test/TestStatus.java
diffstat 3 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RevlogStream.java	Thu Feb 02 16:10:50 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/RevlogStream.java	Thu Feb 02 16:16:19 2012 +0100
@@ -480,7 +480,7 @@
 						}
 					}
 					// XXX 
-					if (patchToPrevious && !userDataAccess.isEmpty()) {
+					if (patchToPrevious && !userDataAccess.isEmpty() /* Issue 22, empty patch to an empty base revision*/) {
 						// this is a patch
 						patch.read(userDataAccess);
 						userDataAccess.done();
Binary file test-data/test-repos.jar has changed
--- a/test/org/tmatesoft/hg/test/TestStatus.java	Thu Feb 02 16:10:50 2012 +0100
+++ b/test/org/tmatesoft/hg/test/TestStatus.java	Thu Feb 02 16:16:19 2012 +0100
@@ -475,6 +475,46 @@
 		}
 	}
 	
+	/**
+	 * Issue 22, two subsequent commits that remove all repository files, each in a different branch.
+	 * Here's excerpt from my RevlogWriter utility:
+	 * <pre>
+	 * 		final List<String> filesList = Collections.singletonList("file1");
+	 *	//
+	 *	file1.writeUncompressed(-1, -1, 0, 0, "garbage".getBytes());
+	 *	//
+	 *	ManifestBuilder mb = new ManifestBuilder();
+	 *	mb.reset().add("file1", file1.getRevision(0));
+	 *	manifest.writeUncompressed(-1, -1, 0, 0, mb.build()); // manifest revision 0
+	 *	final byte[] cset1 = buildChangelogEntry(manifest.getRevision(0), Collections.<String, String>emptyMap(), filesList, "Add a file");
+	 *	changelog.writeUncompressed(-1, -1, 0, 0, cset1);
+	 *	//
+	 *	// pretend we delete all files in a branch 1
+	 *	manifest.writeUncompressed(0, -1, 1, 1, new byte[0]); // manifest revision 1
+	 *	final byte[] cset2 = buildChangelogEntry(manifest.getRevision(1), Collections.singletonMap("branch", "delete-all-1"), filesList, "Delete all files in a first branch");
+	 *	 changelog.writeUncompressed(0, -1, 1, 1, cset2);
+	 *	//
+	 *	// pretend we delete all files in a branch 2 (which is based on revision 0, same as branch 1)
+	 *	manifest.writeUncompressed(1, -1, 1 /*!!! here comes baseRevision != index * /, 2, new byte[0]); // manifest revision 2
+	 *	final byte[] cset3 = buildChangelogEntry(manifest.getRevision(2), Collections.singletonMap("branch", "delete-all-2"), filesList, "Again delete all files but in another branch");
+	 *	changelog.writeUncompressed(0, -1, 2, 2, cset3);
+	 * </pre> 
+	 */
+	@Test
+	public void testOnEmptyRepositoryWithAllFilesDeletedInBranch() throws Exception {
+		repo = Configuration.get().find("status-3");
+		HgStatusCommand cmd = new HgStatusCommand(repo);
+		cmd.all();
+		StatusCollector sc = new StatusCollector();
+		cmd.execute(sc);
+		// shall pass without exception
+		assertTrue(sc.getErrors().isEmpty());
+		for (HgStatus.Kind k : HgStatus.Kind.values()) {
+			assertTrue("Kind " + k.name() + " shall be empty",sc.get(k).isEmpty());
+		}
+	}
+
+	
 	/*
 	 * With warm-up of previous tests, 10 runs, time in milliseconds
 	 * 'hg status -A': Native client total 953 (95 per run), Java client 94 (9)