Merge "Move reachability checker generation into the ObjectReader object"
This commit is contained in:
commit
59420886e9
|
@ -34,6 +34,7 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
|
|||
org.eclipse.jgit.ignore.internal;version="[5.11.0,5.12.0)",
|
||||
org.eclipse.jgit.internal;version="[5.11.0,5.12.0)",
|
||||
org.eclipse.jgit.internal.fsck;version="[5.11.0,5.12.0)",
|
||||
org.eclipse.jgit.internal.revwalk;version="[5.11.0,5.12.0)",
|
||||
org.eclipse.jgit.internal.storage.dfs;version="[5.11.0,5.12.0)",
|
||||
org.eclipse.jgit.internal.storage.file;version="[5.11.0,5.12.0)",
|
||||
org.eclipse.jgit.internal.storage.io;version="[5.11.0,5.12.0)",
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.internal.storage.file.GC;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
|
||||
|
||||
public class BitmappedObjectReachabilityTest
|
||||
extends ObjectReachabilityTestCase {
|
|
@ -7,13 +7,14 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.internal.storage.file.GC;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.ReachabilityChecker;
|
||||
|
||||
public class BitmappedReachabilityCheckerTest
|
||||
extends ReachabilityCheckerTestCase {
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -20,6 +20,10 @@
|
|||
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
|
||||
import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.RevBlob;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -7,10 +7,11 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
|
||||
|
||||
public class PedestrianObjectReachabilityTest
|
||||
extends ObjectReachabilityTestCase {
|
|
@ -7,10 +7,11 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.ReachabilityChecker;
|
||||
|
||||
public class PedestrianReachabilityCheckerTest
|
||||
extends ReachabilityCheckerTestCase {
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -19,6 +19,8 @@
|
|||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.ReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -8,4 +8,20 @@
|
|||
</message_arguments>
|
||||
</filter>
|
||||
</resource>
|
||||
<resource path="src/org/eclipse/jgit/revwalk/ObjectWalk.java" type="org.eclipse.jgit.revwalk.ObjectWalk">
|
||||
<filter id="421654647">
|
||||
<message_arguments>
|
||||
<message_argument value="org.eclipse.jgit.revwalk.ObjectWalk"/>
|
||||
<message_argument value="createObjectReachabilityChecker()"/>
|
||||
</message_arguments>
|
||||
</filter>
|
||||
</resource>
|
||||
<resource path="src/org/eclipse/jgit/revwalk/RevWalk.java" type="org.eclipse.jgit.revwalk.RevWalk">
|
||||
<filter id="421654647">
|
||||
<message_arguments>
|
||||
<message_argument value="org.eclipse.jgit.revwalk.RevWalk"/>
|
||||
<message_argument value="createReachabilityChecker()"/>
|
||||
</message_arguments>
|
||||
</filter>
|
||||
</resource>
|
||||
</component>
|
||||
|
|
|
@ -72,7 +72,8 @@ Export-Package: org.eclipse.jgit.annotations;version="5.11.0",
|
|||
org.eclipse.jgit.http.test",
|
||||
org.eclipse.jgit.internal.fsck;version="5.11.0";
|
||||
x-friends:="org.eclipse.jgit.test",
|
||||
org.eclipse.jgit.internal.revwalk;version="5.11.0";x-internal:=true,
|
||||
org.eclipse.jgit.internal.revwalk;version="5.11.0";
|
||||
x-friends:="org.eclipse.jgit.test",
|
||||
org.eclipse.jgit.internal.storage.dfs;version="5.11.0";
|
||||
x-friends:="org.eclipse.jgit.test,
|
||||
org.eclipse.jgit.http.server,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -21,12 +21,16 @@
|
|||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
|
||||
import org.eclipse.jgit.revwalk.BitmapWalker;
|
||||
import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.ObjectWalk;
|
||||
import org.eclipse.jgit.revwalk.RevObject;
|
||||
|
||||
/**
|
||||
* Checks if all objects are reachable from certain starting points using
|
||||
* bitmaps.
|
||||
*/
|
||||
class BitmappedObjectReachabilityChecker
|
||||
public class BitmappedObjectReachabilityChecker
|
||||
implements ObjectReachabilityChecker {
|
||||
|
||||
private final ObjectWalk walk;
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -23,12 +23,17 @@
|
|||
import org.eclipse.jgit.lib.BitmapIndex.Bitmap;
|
||||
import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.revwalk.ReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevFlag;
|
||||
import org.eclipse.jgit.revwalk.RevSort;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.revwalk.filter.RevFilter;
|
||||
|
||||
/**
|
||||
* Checks the reachability using bitmaps.
|
||||
*/
|
||||
class BitmappedReachabilityChecker implements ReachabilityChecker {
|
||||
public class BitmappedReachabilityChecker implements ReachabilityChecker {
|
||||
|
||||
private final RevWalk walk;
|
||||
|
||||
|
@ -42,7 +47,7 @@ class BitmappedReachabilityChecker implements ReachabilityChecker {
|
|||
* @throws IOException
|
||||
* if the index or the object reader cannot be opened.
|
||||
*/
|
||||
BitmappedReachabilityChecker(RevWalk walk)
|
||||
public BitmappedReachabilityChecker(RevWalk walk)
|
||||
throws IOException {
|
||||
this.walk = walk;
|
||||
if (walk.getObjectReader().getBitmapIndex() == null) {
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
|
@ -17,12 +17,18 @@
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.ObjectWalk;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevObject;
|
||||
import org.eclipse.jgit.revwalk.RevSort;
|
||||
|
||||
/**
|
||||
* Checks if all objects are reachable from certain starting points doing a
|
||||
* walk.
|
||||
*/
|
||||
class PedestrianObjectReachabilityChecker implements ObjectReachabilityChecker {
|
||||
public class PedestrianObjectReachabilityChecker
|
||||
implements ObjectReachabilityChecker {
|
||||
private final ObjectWalk walk;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +37,7 @@ class PedestrianObjectReachabilityChecker implements ObjectReachabilityChecker {
|
|||
* @param walk
|
||||
* ObjectWalk instance to reuse. Caller retains ownership.
|
||||
*/
|
||||
PedestrianObjectReachabilityChecker(ObjectWalk walk) {
|
||||
public PedestrianObjectReachabilityChecker(ObjectWalk walk) {
|
||||
this.walk = walk;
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
package org.eclipse.jgit.revwalk;
|
||||
package org.eclipse.jgit.internal.revwalk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
@ -17,12 +17,16 @@
|
|||
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.revwalk.ReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevSort;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
/**
|
||||
* Checks the reachability walking the graph from the starters towards the
|
||||
* target.
|
||||
*/
|
||||
class PedestrianReachabilityChecker implements ReachabilityChecker {
|
||||
public class PedestrianReachabilityChecker implements ReachabilityChecker {
|
||||
|
||||
private final boolean topoSort;
|
||||
|
|
@ -17,9 +17,18 @@
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jgit.annotations.NonNull;
|
||||
import org.eclipse.jgit.annotations.Nullable;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.internal.revwalk.BitmappedObjectReachabilityChecker;
|
||||
import org.eclipse.jgit.internal.revwalk.BitmappedReachabilityChecker;
|
||||
import org.eclipse.jgit.internal.revwalk.PedestrianObjectReachabilityChecker;
|
||||
import org.eclipse.jgit.internal.revwalk.PedestrianReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.ObjectWalk;
|
||||
import org.eclipse.jgit.revwalk.ReachabilityChecker;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
/**
|
||||
* Reads an {@link org.eclipse.jgit.lib.ObjectDatabase} for a single thread.
|
||||
|
@ -407,6 +416,54 @@ public BitmapIndex getBitmapIndex() throws IOException {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a reachability checker that will use bitmaps if possible.
|
||||
*
|
||||
* @param rw
|
||||
* revwalk for use by the reachability checker
|
||||
* @return the most efficient reachability checker for this repository.
|
||||
* @throws IOException
|
||||
* if it cannot open any of the underlying indices.
|
||||
*
|
||||
* @since 5.11
|
||||
*/
|
||||
@NonNull
|
||||
public ReachabilityChecker createReachabilityChecker(RevWalk rw)
|
||||
throws IOException {
|
||||
if (getBitmapIndex() != null) {
|
||||
return new BitmappedReachabilityChecker(rw);
|
||||
}
|
||||
|
||||
return new PedestrianReachabilityChecker(true, rw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an object reachability checker that will use bitmaps if possible.
|
||||
*
|
||||
* This reachability checker accepts any object as target. For checks
|
||||
* exclusively between commits, use
|
||||
* {@link #createReachabilityChecker(RevWalk)}.
|
||||
*
|
||||
* @param ow
|
||||
* objectwalk for use by the reachability checker
|
||||
* @return the most efficient object reachability checker for this
|
||||
* repository.
|
||||
*
|
||||
* @throws IOException
|
||||
* if it cannot open any of the underlying indices.
|
||||
*
|
||||
* @since 5.11
|
||||
*/
|
||||
@NonNull
|
||||
public ObjectReachabilityChecker createObjectReachabilityChecker(
|
||||
ObjectWalk ow) throws IOException {
|
||||
if (getBitmapIndex() != null) {
|
||||
return new BitmappedObjectReachabilityChecker(ow);
|
||||
}
|
||||
|
||||
return new PedestrianObjectReachabilityChecker(ow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link org.eclipse.jgit.lib.ObjectInserter} from which this
|
||||
* reader was created using {@code inserter.newReader()}
|
||||
|
|
|
@ -172,14 +172,14 @@ public ObjectWalk(ObjectReader or) {
|
|||
* when the index fails to load.
|
||||
*
|
||||
* @since 5.8
|
||||
* @deprecated use
|
||||
* {@code ObjectReader#createObjectReachabilityChecker(ObjectWalk)}
|
||||
* instead.
|
||||
*/
|
||||
public ObjectReachabilityChecker createObjectReachabilityChecker()
|
||||
@Deprecated
|
||||
public final ObjectReachabilityChecker createObjectReachabilityChecker()
|
||||
throws IOException {
|
||||
if (reader.getBitmapIndex() != null) {
|
||||
return new BitmappedObjectReachabilityChecker(this);
|
||||
}
|
||||
|
||||
return new PedestrianObjectReachabilityChecker(this);
|
||||
return reader.createObjectReachabilityChecker(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -236,13 +236,13 @@ public ObjectReader getObjectReader() {
|
|||
* if it cannot open any of the underlying indices.
|
||||
*
|
||||
* @since 5.4
|
||||
* @deprecated use {@code ObjectReader#createReachabilityChecker(RevWalk)}
|
||||
* instead.
|
||||
*/
|
||||
public ReachabilityChecker createReachabilityChecker() throws IOException {
|
||||
if (reader.getBitmapIndex() != null) {
|
||||
return new BitmappedReachabilityChecker(this);
|
||||
}
|
||||
|
||||
return new PedestrianReachabilityChecker(true, this);
|
||||
@Deprecated
|
||||
public final ReachabilityChecker createReachabilityChecker()
|
||||
throws IOException {
|
||||
return reader.createReachabilityChecker(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1959,8 +1959,8 @@ private static void checkNotAdvertisedWants(UploadPack up,
|
|||
.map(objId -> objectIdToRevObject(objWalk, objId))
|
||||
.filter(Objects::nonNull); // Ignore missing tips
|
||||
|
||||
ObjectReachabilityChecker reachabilityChecker = objWalk
|
||||
.createObjectReachabilityChecker();
|
||||
ObjectReachabilityChecker reachabilityChecker = reader
|
||||
.createObjectReachabilityChecker(objWalk);
|
||||
Optional<RevObject> unreachable = reachabilityChecker
|
||||
.areAllReachable(wantsAsObjs, startersAsObjs);
|
||||
if (unreachable.isPresent()) {
|
||||
|
@ -1971,8 +1971,8 @@ private static void checkNotAdvertisedWants(UploadPack up,
|
|||
}
|
||||
|
||||
// All wants are commits, we can use ReachabilityChecker
|
||||
ReachabilityChecker reachabilityChecker = walk
|
||||
.createReachabilityChecker();
|
||||
ReachabilityChecker reachabilityChecker = reader
|
||||
.createReachabilityChecker(walk);
|
||||
|
||||
Stream<RevCommit> reachableCommits = importantRefsFirst(visibleRefs)
|
||||
.map(UploadPack::refToObjectId)
|
||||
|
|
Loading…
Reference in New Issue