@ -103,7 +103,6 @@ import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevSort ;
import org.eclipse.jgit.revwalk.RevSort ;
import org.eclipse.jgit.revwalk.RevTag ;
import org.eclipse.jgit.revwalk.RevTag ;
import org.eclipse.jgit.revwalk.RevTree ;
import org.eclipse.jgit.revwalk.RevTree ;
import org.eclipse.jgit.storage.file.PackIndex ;
import org.eclipse.jgit.storage.file.PackIndexWriter ;
import org.eclipse.jgit.storage.file.PackIndexWriter ;
import org.eclipse.jgit.util.BlockList ;
import org.eclipse.jgit.util.BlockList ;
import org.eclipse.jgit.util.TemporaryBuffer ;
import org.eclipse.jgit.util.TemporaryBuffer ;
@ -144,6 +143,18 @@ import org.eclipse.jgit.util.TemporaryBuffer;
public class PackWriter {
public class PackWriter {
private static final int PACK_VERSION_GENERATED = 2 ;
private static final int PACK_VERSION_GENERATED = 2 ;
/** A collection of object ids. */
public interface ObjectIdSet {
/ * *
* Returns true if the objectId is contained within the collection .
*
* @param objectId
* the objectId to find
* @return whether the collection contains the objectId .
* /
boolean contains ( AnyObjectId objectId ) ;
}
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 > ( ) ;
@ -206,9 +217,9 @@ public class PackWriter {
private Set < ObjectId > tagTargets = Collections . emptySet ( ) ;
private Set < ObjectId > tagTargets = Collections . emptySet ( ) ;
private PackIndex [ ] excludeInPacks ;
private ObjectIdSet [ ] excludeInPacks ;
private PackIndex excludeInPackLast ;
private ObjectIdSet excludeInPackLast ;
private Deflater myDeflater ;
private Deflater myDeflater ;
@ -507,19 +518,40 @@ public class PackWriter {
return stats . totalObjects ;
return stats . totalObjects ;
}
}
/ * *
* Returns the object ids in the pack file that was created by this writer ,
* sorted by name .
*
* This method can only be invoked after
* { @link # writePack ( ProgressMonitor , ProgressMonitor , OutputStream ) } has
* been invoked and completed successfully .
*
* @return number of objects in pack .
* @throws IOException
* a cached pack cannot supply its object ids .
* /
public List < ObjectId > getObjectList ( ) throws IOException {
if ( ! cachedPacks . isEmpty ( ) )
throw new IOException (
JGitText . get ( ) . cachedPacksPreventsListingObjects ) ;
return Collections . unmodifiableList (
( List < ? extends ObjectId > ) sortByName ( ) ) ;
}
/ * *
/ * *
* Add a pack index whose contents should be excluded from the result .
* Add a pack index whose contents should be excluded from the result .
*
*
* @param idx
* @param idx
* objects in this index will not be in the output pack .
* objects in this index will not be in the output pack .
* /
* /
public void excludeObjects ( PackIndex idx ) {
public void excludeObjects ( ObjectIdSet idx ) {
if ( excludeInPacks = = null ) {
if ( excludeInPacks = = null ) {
excludeInPacks = new PackIndex [ ] { idx } ;
excludeInPacks = new ObjectIdSet [ ] { idx } ;
excludeInPackLast = idx ;
excludeInPackLast = idx ;
} else {
} else {
int cnt = excludeInPacks . length ;
int cnt = excludeInPacks . length ;
PackIndex [ ] newList = new PackIndex [ cnt + 1 ] ;
ObjectIdSet [ ] newList = new ObjectIdSet [ cnt + 1 ] ;
System . arraycopy ( excludeInPacks , 0 , newList , 0 , cnt ) ;
System . arraycopy ( excludeInPacks , 0 , newList , 0 , cnt ) ;
newList [ cnt ] = idx ;
newList [ cnt ] = idx ;
excludeInPacks = newList ;
excludeInPacks = newList ;
@ -1798,10 +1830,10 @@ public class PackWriter {
private boolean exclude ( AnyObjectId objectId ) {
private boolean exclude ( AnyObjectId objectId ) {
if ( excludeInPacks = = null )
if ( excludeInPacks = = null )
return false ;
return false ;
if ( excludeInPackLast . hasObject ( objectId ) )
if ( excludeInPackLast . contains ( objectId ) )
return true ;
return true ;
for ( PackIndex idx : excludeInPacks ) {
for ( ObjectIdSet idx : excludeInPacks ) {
if ( idx . hasObject ( objectId ) ) {
if ( idx . contains ( objectId ) ) {
excludeInPackLast = idx ;
excludeInPackLast = idx ;
return true ;
return true ;
}
}