changeset 670:52af7f62e731

AIOOBE in BundleGenerator.ChunkGenerator.iterate when there are no outgoing changes on push
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 12 Jul 2013 15:27:43 +0200
parents b1a3a056d7e6
children 002ed1b2baad
files src/org/tmatesoft/hg/core/HgPushCommand.java src/org/tmatesoft/hg/internal/BundleGenerator.java
diffstat 2 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgPushCommand.java	Thu Jul 11 20:49:33 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgPushCommand.java	Fri Jul 12 15:27:43 2013 +0200
@@ -87,15 +87,17 @@
 			} else {
 				outgoing = new RevisionSet(l);
 			}
-			//
-			// prepare bundle
-			BundleGenerator bg = new BundleGenerator(implRepo);
-			File bundleFile = bg.create(outgoing.asList());
-			progress.worked(20);
-			HgBundle b = new HgLookup(repo.getSessionContext()).loadBundle(bundleFile);
-			//
-			// send changes
-			remoteRepo.unbundle(b, comparator.getRemoteHeads());
+			if (!outgoing.isEmpty()) {
+				//
+				// prepare bundle
+				BundleGenerator bg = new BundleGenerator(implRepo);
+				File bundleFile = bg.create(outgoing.asList());
+				progress.worked(20);
+				HgBundle b = new HgLookup(repo.getSessionContext()).loadBundle(bundleFile);
+				//
+				// send changes
+				remoteRepo.unbundle(b, comparator.getRemoteHeads());
+			} // update phase information nevertheless
 			progress.worked(20);
 			//
 			// update phase information
--- a/src/org/tmatesoft/hg/internal/BundleGenerator.java	Thu Jul 11 20:49:33 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/BundleGenerator.java	Fri Jul 12 15:27:43 2013 +0200
@@ -55,6 +55,9 @@
 		repo = hgRepo;
 	}
 	
+	/**
+	 * @return never <code>null</code>. empty file if no changesets were written
+	 */
 	public File create(List<Nodeid> changesets) throws HgIOException, IOException {
 		final HgChangelog clog = repo.getRepo().getChangelog();
 		final HgManifest manifest = repo.getRepo().getManifest();
@@ -85,6 +88,10 @@
 		manifestRevs.sort(true);
 		//
 		final File bundleFile = File.createTempFile("hg4j-", ".bundle");
+		if (clogRevs.length == 0) {
+			// nothing to write
+			return bundleFile;
+		}
 		final FileOutputStream osBundle = new FileOutputStream(bundleFile);
 		final OutputStreamSerializer outRaw = new OutputStreamSerializer(osBundle);
 		outRaw.write("HG10UN".getBytes(), 0, 6);