PackWriter: Declare preparePack object sets as @NonNull
Require callers to pass in valid sets for both want and have collections. Offer PackWriter.NONE as a handy constant for an empty collection for the have part of preparePack instead of null. Change-Id: Ifda4450f5e488cbfefd728382b7d30797e229217
This commit is contained in:
parent
40051505d7
commit
4e650c0d76
|
@ -866,7 +866,7 @@ public void packAndPrune() throws Exception {
|
||||||
Set<ObjectId> all = new HashSet<ObjectId>();
|
Set<ObjectId> all = new HashSet<ObjectId>();
|
||||||
for (Ref r : db.getAllRefs().values())
|
for (Ref r : db.getAllRefs().values())
|
||||||
all.add(r.getObjectId());
|
all.add(r.getObjectId());
|
||||||
pw.preparePack(m, all, Collections.<ObjectId> emptySet());
|
pw.preparePack(m, all, PackWriter.NONE);
|
||||||
|
|
||||||
final ObjectId name = pw.computeName();
|
final ObjectId name = pw.computeName();
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.eclipse.jgit.internal.storage.pack.PackWriter.NONE;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -88,9 +89,6 @@
|
||||||
|
|
||||||
public class PackWriterTest extends SampleDataRepositoryTestCase {
|
public class PackWriterTest extends SampleDataRepositoryTestCase {
|
||||||
|
|
||||||
private static final Set<ObjectId> EMPTY_SET_OBJECT = Collections
|
|
||||||
.<ObjectId> emptySet();
|
|
||||||
|
|
||||||
private static final List<RevObject> EMPTY_LIST_REVS = Collections
|
private static final List<RevObject> EMPTY_LIST_REVS = Collections
|
||||||
.<RevObject> emptyList();
|
.<RevObject> emptyList();
|
||||||
|
|
||||||
|
@ -171,7 +169,7 @@ public void testModifySettings() {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteEmptyPack1() throws IOException {
|
public void testWriteEmptyPack1() throws IOException {
|
||||||
createVerifyOpenPack(EMPTY_SET_OBJECT, EMPTY_SET_OBJECT, false, false);
|
createVerifyOpenPack(NONE, NONE, false, false);
|
||||||
|
|
||||||
assertEquals(0, writer.getObjectCount());
|
assertEquals(0, writer.getObjectCount());
|
||||||
assertEquals(0, pack.getObjectCount());
|
assertEquals(0, pack.getObjectCount());
|
||||||
|
@ -204,8 +202,8 @@ public void testNotIgnoreNonExistingObjects() throws IOException {
|
||||||
final ObjectId nonExisting = ObjectId
|
final ObjectId nonExisting = ObjectId
|
||||||
.fromString("0000000000000000000000000000000000000001");
|
.fromString("0000000000000000000000000000000000000001");
|
||||||
try {
|
try {
|
||||||
createVerifyOpenPack(EMPTY_SET_OBJECT, Collections.singleton(
|
createVerifyOpenPack(NONE, Collections.singleton(nonExisting),
|
||||||
nonExisting), false, false);
|
false, false);
|
||||||
fail("Should have thrown MissingObjectException");
|
fail("Should have thrown MissingObjectException");
|
||||||
} catch (MissingObjectException x) {
|
} catch (MissingObjectException x) {
|
||||||
// expected
|
// expected
|
||||||
|
@ -221,8 +219,8 @@ public void testNotIgnoreNonExistingObjects() throws IOException {
|
||||||
public void testIgnoreNonExistingObjects() throws IOException {
|
public void testIgnoreNonExistingObjects() throws IOException {
|
||||||
final ObjectId nonExisting = ObjectId
|
final ObjectId nonExisting = ObjectId
|
||||||
.fromString("0000000000000000000000000000000000000001");
|
.fromString("0000000000000000000000000000000000000001");
|
||||||
createVerifyOpenPack(EMPTY_SET_OBJECT, Collections.singleton(
|
createVerifyOpenPack(NONE, Collections.singleton(nonExisting),
|
||||||
nonExisting), false, true);
|
false, true);
|
||||||
// shouldn't throw anything
|
// shouldn't throw anything
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,8 +238,8 @@ public void testIgnoreNonExistingObjectsWithBitmaps() throws IOException,
|
||||||
final ObjectId nonExisting = ObjectId
|
final ObjectId nonExisting = ObjectId
|
||||||
.fromString("0000000000000000000000000000000000000001");
|
.fromString("0000000000000000000000000000000000000001");
|
||||||
new GC(db).gc();
|
new GC(db).gc();
|
||||||
createVerifyOpenPack(EMPTY_SET_OBJECT,
|
createVerifyOpenPack(NONE, Collections.singleton(nonExisting), false,
|
||||||
Collections.singleton(nonExisting), false, true, true);
|
true, true);
|
||||||
// shouldn't throw anything
|
// shouldn't throw anything
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,8 +550,7 @@ private static PackIndex writePack(FileRepository repo,
|
||||||
pw.setReuseDeltaCommits(false);
|
pw.setReuseDeltaCommits(false);
|
||||||
for (ObjectIdSet idx : excludeObjects)
|
for (ObjectIdSet idx : excludeObjects)
|
||||||
pw.excludeObjects(idx);
|
pw.excludeObjects(idx);
|
||||||
pw.preparePack(NullProgressMonitor.INSTANCE, want,
|
pw.preparePack(NullProgressMonitor.INSTANCE, want, NONE);
|
||||||
Collections.<ObjectId> emptySet());
|
|
||||||
String id = pw.computeName().getName();
|
String id = pw.computeName().getName();
|
||||||
File packdir = new File(repo.getObjectsDirectory(), "pack");
|
File packdir = new File(repo.getObjectsDirectory(), "pack");
|
||||||
File packFile = new File(packdir, "pack-" + id + ".pack");
|
File packFile = new File(packdir, "pack-" + id + ".pack");
|
||||||
|
@ -576,7 +573,7 @@ private void writeVerifyPack1() throws IOException {
|
||||||
final HashSet<ObjectId> interestings = new HashSet<ObjectId>();
|
final HashSet<ObjectId> interestings = new HashSet<ObjectId>();
|
||||||
interestings.add(ObjectId
|
interestings.add(ObjectId
|
||||||
.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"));
|
.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"));
|
||||||
createVerifyOpenPack(interestings, EMPTY_SET_OBJECT, false, false);
|
createVerifyOpenPack(interestings, NONE, false, false);
|
||||||
|
|
||||||
final ObjectId expectedOrder[] = new ObjectId[] {
|
final ObjectId expectedOrder[] = new ObjectId[] {
|
||||||
ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"),
|
ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7"),
|
||||||
|
|
|
@ -53,7 +53,6 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -278,7 +277,7 @@ private void packHeads(ProgressMonitor pm) throws IOException {
|
||||||
|
|
||||||
try (PackWriter pw = newPackWriter()) {
|
try (PackWriter pw = newPackWriter()) {
|
||||||
pw.setTagTargets(tagTargets);
|
pw.setTagTargets(tagTargets);
|
||||||
pw.preparePack(pm, allHeads, none());
|
pw.preparePack(pm, allHeads, PackWriter.NONE);
|
||||||
if (0 < pw.getObjectCount())
|
if (0 < pw.getObjectCount())
|
||||||
writePack(GC, pw, pm);
|
writePack(GC, pw, pm);
|
||||||
}
|
}
|
||||||
|
@ -303,16 +302,12 @@ private void packRefTreeGraph(ProgressMonitor pm) throws IOException {
|
||||||
try (PackWriter pw = newPackWriter()) {
|
try (PackWriter pw = newPackWriter()) {
|
||||||
for (ObjectIdSet packedObjs : newPackObj)
|
for (ObjectIdSet packedObjs : newPackObj)
|
||||||
pw.excludeObjects(packedObjs);
|
pw.excludeObjects(packedObjs);
|
||||||
pw.preparePack(pm, txnHeads, none());
|
pw.preparePack(pm, txnHeads, PackWriter.NONE);
|
||||||
if (0 < pw.getObjectCount())
|
if (0 < pw.getObjectCount())
|
||||||
writePack(GC_TXN, pw, pm);
|
writePack(GC_TXN, pw, pm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<ObjectId> none() {
|
|
||||||
return Collections.<ObjectId> emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void packGarbage(ProgressMonitor pm) throws IOException {
|
private void packGarbage(ProgressMonitor pm) throws IOException {
|
||||||
// TODO(sop) This is ugly. The garbage pack needs to be deleted.
|
// TODO(sop) This is ugly. The garbage pack needs to be deleted.
|
||||||
PackConfig cfg = new PackConfig(packConfig);
|
PackConfig cfg = new PackConfig(packConfig);
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.annotations.NonNull;
|
||||||
import org.eclipse.jgit.dircache.DirCacheIterator;
|
import org.eclipse.jgit.dircache.DirCacheIterator;
|
||||||
import org.eclipse.jgit.errors.CorruptObjectException;
|
import org.eclipse.jgit.errors.CorruptObjectException;
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
|
@ -578,7 +579,7 @@ else if (RefTreeNames.isRefTree(refdb, ref.getName()))
|
||||||
ret.add(rest);
|
ret.add(rest);
|
||||||
}
|
}
|
||||||
if (!txnHeads.isEmpty()) {
|
if (!txnHeads.isEmpty()) {
|
||||||
PackFile txn = writePack(txnHeads, null, null, excluded);
|
PackFile txn = writePack(txnHeads, PackWriter.NONE, null, excluded);
|
||||||
if (txn != null)
|
if (txn != null)
|
||||||
ret.add(txn);
|
ret.add(txn);
|
||||||
}
|
}
|
||||||
|
@ -698,8 +699,8 @@ private Set<ObjectId> listNonHEADIndexObjects()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PackFile writePack(Set<? extends ObjectId> want,
|
private PackFile writePack(@NonNull Set<? extends ObjectId> want,
|
||||||
Set<? extends ObjectId> have, Set<ObjectId> tagTargets,
|
@NonNull Set<? extends ObjectId> have, Set<ObjectId> tagTargets,
|
||||||
List<ObjectIdSet> excludeObjects) throws IOException {
|
List<ObjectIdSet> excludeObjects) throws IOException {
|
||||||
File tmpPack = null;
|
File tmpPack = null;
|
||||||
Map<PackExt, File> tmpExts = new TreeMap<PackExt, File>(
|
Map<PackExt, File> tmpExts = new TreeMap<PackExt, File>(
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
import java.util.zip.DeflaterOutputStream;
|
import java.util.zip.DeflaterOutputStream;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.annotations.NonNull;
|
||||||
import org.eclipse.jgit.errors.CorruptObjectException;
|
import org.eclipse.jgit.errors.CorruptObjectException;
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.LargeObjectException;
|
import org.eclipse.jgit.errors.LargeObjectException;
|
||||||
|
@ -162,6 +163,9 @@
|
||||||
public class PackWriter implements AutoCloseable {
|
public class PackWriter implements AutoCloseable {
|
||||||
private static final int PACK_VERSION_GENERATED = 2;
|
private static final int PACK_VERSION_GENERATED = 2;
|
||||||
|
|
||||||
|
/** Empty set of objects for {@code preparePack()}. */
|
||||||
|
public static Set<ObjectId> NONE = Collections.emptySet();
|
||||||
|
|
||||||
private static final Map<WeakReference<PackWriter>, Boolean> instances =
|
private static final Map<WeakReference<PackWriter>, Boolean> instances =
|
||||||
new ConcurrentHashMap<WeakReference<PackWriter>, Boolean>();
|
new ConcurrentHashMap<WeakReference<PackWriter>, Boolean>();
|
||||||
|
|
||||||
|
@ -670,7 +674,7 @@ public void excludeObjects(ObjectIdSet idx) {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* when some I/O problem occur during reading objects.
|
* when some I/O problem occur during reading objects.
|
||||||
*/
|
*/
|
||||||
public void preparePack(final Iterator<RevObject> objectsSource)
|
public void preparePack(@NonNull Iterator<RevObject> objectsSource)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
while (objectsSource.hasNext()) {
|
while (objectsSource.hasNext()) {
|
||||||
addObject(objectsSource.next());
|
addObject(objectsSource.next());
|
||||||
|
@ -693,16 +697,18 @@ public void preparePack(final Iterator<RevObject> objectsSource)
|
||||||
* progress during object enumeration.
|
* progress during object enumeration.
|
||||||
* @param want
|
* @param want
|
||||||
* collection of objects to be marked as interesting (start
|
* collection of objects to be marked as interesting (start
|
||||||
* points of graph traversal).
|
* points of graph traversal). Must not be {@code null}.
|
||||||
* @param have
|
* @param have
|
||||||
* collection of objects to be marked as uninteresting (end
|
* collection of objects to be marked as uninteresting (end
|
||||||
* points of graph traversal).
|
* points of graph traversal). Pass {@link #NONE} if all objects
|
||||||
|
* reachable from {@code want} are desired, such as when serving
|
||||||
|
* a clone.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* when some I/O problem occur during reading objects.
|
* when some I/O problem occur during reading objects.
|
||||||
*/
|
*/
|
||||||
public void preparePack(ProgressMonitor countingMonitor,
|
public void preparePack(ProgressMonitor countingMonitor,
|
||||||
Set<? extends ObjectId> want,
|
@NonNull Set<? extends ObjectId> want,
|
||||||
Set<? extends ObjectId> have) throws IOException {
|
@NonNull Set<? extends ObjectId> have) throws IOException {
|
||||||
ObjectWalk ow;
|
ObjectWalk ow;
|
||||||
if (shallowPack)
|
if (shallowPack)
|
||||||
ow = new DepthWalk.ObjectWalk(reader, depth);
|
ow = new DepthWalk.ObjectWalk(reader, depth);
|
||||||
|
@ -729,17 +735,19 @@ public void preparePack(ProgressMonitor countingMonitor,
|
||||||
* ObjectWalk to perform enumeration.
|
* ObjectWalk to perform enumeration.
|
||||||
* @param interestingObjects
|
* @param interestingObjects
|
||||||
* collection of objects to be marked as interesting (start
|
* collection of objects to be marked as interesting (start
|
||||||
* points of graph traversal).
|
* points of graph traversal). Must not be {@code null}.
|
||||||
* @param uninterestingObjects
|
* @param uninterestingObjects
|
||||||
* collection of objects to be marked as uninteresting (end
|
* collection of objects to be marked as uninteresting (end
|
||||||
* points of graph traversal).
|
* points of graph traversal). Pass {@link #NONE} if all objects
|
||||||
|
* reachable from {@code want} are desired, such as when serving
|
||||||
|
* a clone.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* when some I/O problem occur during reading objects.
|
* when some I/O problem occur during reading objects.
|
||||||
*/
|
*/
|
||||||
public void preparePack(ProgressMonitor countingMonitor,
|
public void preparePack(ProgressMonitor countingMonitor,
|
||||||
ObjectWalk walk,
|
@NonNull ObjectWalk walk,
|
||||||
final Set<? extends ObjectId> interestingObjects,
|
@NonNull Set<? extends ObjectId> interestingObjects,
|
||||||
final Set<? extends ObjectId> uninterestingObjects)
|
@NonNull Set<? extends ObjectId> uninterestingObjects)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (countingMonitor == null)
|
if (countingMonitor == null)
|
||||||
countingMonitor = NullProgressMonitor.INSTANCE;
|
countingMonitor = NullProgressMonitor.INSTANCE;
|
||||||
|
@ -1597,17 +1605,12 @@ private void writeChecksum(PackOutputStream out) throws IOException {
|
||||||
out.write(packcsum);
|
out.write(packcsum);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findObjectsToPack(final ProgressMonitor countingMonitor,
|
private void findObjectsToPack(@NonNull ProgressMonitor countingMonitor,
|
||||||
final ObjectWalk walker, final Set<? extends ObjectId> want,
|
@NonNull ObjectWalk walker, @NonNull Set<? extends ObjectId> want,
|
||||||
Set<? extends ObjectId> have)
|
@NonNull Set<? extends ObjectId> have) throws IOException {
|
||||||
throws MissingObjectException, IOException,
|
|
||||||
IncorrectObjectTypeException {
|
|
||||||
final long countingStart = System.currentTimeMillis();
|
final long countingStart = System.currentTimeMillis();
|
||||||
beginPhase(PackingPhase.COUNTING, countingMonitor, ProgressMonitor.UNKNOWN);
|
beginPhase(PackingPhase.COUNTING, countingMonitor, ProgressMonitor.UNKNOWN);
|
||||||
|
|
||||||
if (have == null)
|
|
||||||
have = Collections.emptySet();
|
|
||||||
|
|
||||||
stats.interestingObjects = Collections.unmodifiableSet(new HashSet<ObjectId>(want));
|
stats.interestingObjects = Collections.unmodifiableSet(new HashSet<ObjectId>(want));
|
||||||
stats.uninterestingObjects = Collections.unmodifiableSet(new HashSet<ObjectId>(have));
|
stats.uninterestingObjects = Collections.unmodifiableSet(new HashSet<ObjectId>(have));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue