Browse Source

Fix dumb transport push

PackWriter incorrectly returned 0 from getObjectsNumber() when the
pack has not been written yet. This caused dumb transports like
amazon-s3:// and sftp:// to abort early and never write out a pack,
under the assumption that the pack had no objects.

Until the pack header is written to the output stream, compute the
current object count each time it is requested. Once the header is
started, use the object count from the stats object.

Change-Id: I041a2368ae0cfe6f649ec28658d41a6355933900
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
65f9a6e58b
  1. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
  2. 19
      org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java

@ -58,7 +58,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -125,9 +124,11 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
/**
* Test constructor for exceptions, default settings, initialization.
*
* @throws IOException
*/
@Test
public void testContructor() {
public void testContructor() throws IOException {
writer = new PackWriter(config, db.newObjectReader());
assertEquals(false, writer.isDeltaBaseAsOffset());
assertEquals(true, config.isReuseDeltas());
@ -177,7 +178,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
*/
@Test
public void testWriteEmptyPack2() throws IOException {
createVerifyOpenPack(EMPTY_LIST_REVS.iterator());
createVerifyOpenPack(EMPTY_LIST_REVS);
assertEquals(0, writer.getObjectsNumber());
assertEquals(0, pack.getObjectCount());
@ -320,7 +321,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
for (int i = 0; i < forcedOrder.length; i++)
forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);
createVerifyOpenPack(Arrays.asList(forcedOrderRevs).iterator());
createVerifyOpenPack(Arrays.asList(forcedOrderRevs));
assertEquals(forcedOrder.length, writer.getObjectsNumber());
verifyObjectsOrder(forcedOrder);
@ -544,11 +545,12 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
verifyOpenPack(thin);
}
private void createVerifyOpenPack(final Iterator<RevObject> objectSource)
private void createVerifyOpenPack(final List<RevObject> objectSource)
throws MissingObjectException, IOException {
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
writer = new PackWriter(config, db.newObjectReader());
writer.preparePack(objectSource);
writer.preparePack(objectSource.iterator());
assertEquals(objectSource.size(), writer.getObjectsNumber());
writer.writePack(m, m, os);
writer.release();
verifyOpenPack(false);

19
org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

@ -402,8 +402,18 @@ public class PackWriter {
* Returns objects number in a pack file that was created by this writer.
*
* @return number of objects in pack.
* @throws IOException
* a cached pack cannot supply its object count.
*/
public long getObjectsNumber() {
public long getObjectsNumber() throws IOException {
if (stats.totalObjects == 0) {
long objCnt = 0;
for (List<ObjectToPack> list : objectsLists)
objCnt += list.size();
for (CachedPack pack : cachedPacks)
objCnt += pack.getObjectCount();
return objCnt;
}
return stats.totalObjects;
}
@ -635,13 +645,8 @@ public class PackWriter {
final PackOutputStream out = new PackOutputStream(writeMonitor,
packStream, this);
long objCnt = 0;
for (List<ObjectToPack> list : objectsLists)
objCnt += list.size();
for (CachedPack pack : cachedPacks)
objCnt += pack.getObjectCount();
long objCnt = getObjectsNumber();
stats.totalObjects = objCnt;
writeMonitor.beginTask(JGitText.get().writingObjects, (int) objCnt);
long writeStart = System.currentTimeMillis();

Loading…
Cancel
Save