@ -96,8 +96,8 @@ import org.eclipse.jgit.storage.file.PackIndexWriter;
* Typical usage consists of creating instance intended for some pack ,
* Typical usage consists of creating instance intended for some pack ,
* configuring options , preparing the list of objects by calling
* configuring options , preparing the list of objects by calling
* { @link # preparePack ( Iterator ) } or
* { @link # preparePack ( Iterator ) } or
* { @link # preparePack ( Collection , Collection ) } , and finally
* { @link # preparePack ( ProgressMonitor , Collection , Collection ) } , and finally
* producing the stream with { @link # writePack ( OutputStream ) } .
* producing the stream with { @link # writePack ( ProgressMonitor , ProgressMonitor , OutputStream ) } .
* < / p >
* < / p >
* < p >
* < p >
* Class provide set of configurable options and { @link ProgressMonitor }
* Class provide set of configurable options and { @link ProgressMonitor }
@ -116,7 +116,7 @@ public class PackWriter {
* Title of { @link ProgressMonitor } task used during counting objects to
* Title of { @link ProgressMonitor } task used during counting objects to
* pack .
* pack .
*
*
* @see # preparePack ( Collection , Collection )
* @see # preparePack ( ProgressMonitor , Collection , Collection )
* /
* /
public static final String COUNTING_OBJECTS_PROGRESS = JGitText . get ( ) . countingObjects ;
public static final String COUNTING_OBJECTS_PROGRESS = JGitText . get ( ) . countingObjects ;
@ -124,7 +124,7 @@ public class PackWriter {
* Title of { @link ProgressMonitor } task used during searching for objects
* Title of { @link ProgressMonitor } task used during searching for objects
* reuse or delta reuse .
* reuse or delta reuse .
*
*
* @see # writePack ( OutputStream )
* @see # writePack ( ProgressMonitor , ProgressMonitor , OutputStream )
* /
* /
public static final String SEARCHING_REUSE_PROGRESS = JGitText . get ( ) . compressingObjects ;
public static final String SEARCHING_REUSE_PROGRESS = JGitText . get ( ) . compressingObjects ;
@ -132,7 +132,7 @@ public class PackWriter {
* Title of { @link ProgressMonitor } task used during writing out pack
* Title of { @link ProgressMonitor } task used during writing out pack
* ( objects )
* ( objects )
*
*
* @see # writePack ( OutputStream )
* @see # writePack ( ProgressMonitor , ProgressMonitor , OutputStream )
* /
* /
public static final String WRITING_OBJECTS_PROGRESS = JGitText . get ( ) . writingObjects ;
public static final String WRITING_OBJECTS_PROGRESS = JGitText . get ( ) . writingObjects ;
@ -185,10 +185,6 @@ public class PackWriter {
private final Deflater deflater ;
private final Deflater deflater ;
private ProgressMonitor initMonitor ;
private ProgressMonitor writeMonitor ;
private final ObjectReader reader ;
private final ObjectReader reader ;
/** {@link #reader} recast to the reuse interface, if it supports it. */
/** {@link #reader} recast to the reuse interface, if it supports it. */
@ -216,38 +212,12 @@ public class PackWriter {
* Create writer for specified repository .
* Create writer for specified repository .
* < p >
* < p >
* Objects for packing are specified in { @link # preparePack ( Iterator ) } or
* Objects for packing are specified in { @link # preparePack ( Iterator ) } or
* { @link # preparePack ( Collection , Collection ) } .
* { @link # preparePack ( ProgressMonitor , Collection , Collection ) } .
*
*
* @param repo
* @param repo
* repository where objects are stored .
* repository where objects are stored .
* @param monitor
* operations progress monitor , used within
* { @link # preparePack ( Iterator ) } ,
* { @link # preparePack ( Collection , Collection ) }
* , or { @link # writePack ( OutputStream ) } .
* /
* /
public PackWriter ( final Repository repo , final ProgressMonitor monitor ) {
public PackWriter ( final Repository repo ) {
this ( repo , monitor , monitor ) ;
}
/ * *
* Create writer for specified repository .
* < p >
* Objects for packing are specified in { @link # preparePack ( Iterator ) } or
* { @link # preparePack ( Collection , Collection ) } .
*
* @param repo
* repository where objects are stored .
* @param imonitor
* operations progress monitor , used within
* { @link # preparePack ( Iterator ) } ,
* { @link # preparePack ( Collection , Collection ) }
* @param wmonitor
* operations progress monitor , used within
* { @link # writePack ( OutputStream ) } .
* /
public PackWriter ( final Repository repo , final ProgressMonitor imonitor ,
final ProgressMonitor wmonitor ) {
this . db = repo ;
this . db = repo ;
reader = db . newObjectReader ( ) ;
reader = db . newObjectReader ( ) ;
@ -256,9 +226,6 @@ public class PackWriter {
else
else
reuseSupport = null ;
reuseSupport = null ;
initMonitor = imonitor = = null ? NullProgressMonitor . INSTANCE : imonitor ;
writeMonitor = wmonitor = = null ? NullProgressMonitor . INSTANCE : wmonitor ;
final CoreConfig coreConfig = db . getConfig ( ) . get ( CoreConfig . KEY ) ;
final CoreConfig coreConfig = db . getConfig ( ) . get ( CoreConfig . KEY ) ;
this . deflater = new Deflater ( coreConfig . getCompression ( ) ) ;
this . deflater = new Deflater ( coreConfig . getCompression ( ) ) ;
outputVersion = coreConfig . getPackIndexVersion ( ) ;
outputVersion = coreConfig . getPackIndexVersion ( ) ;
@ -283,7 +250,7 @@ public class PackWriter {
* use it if possible . Normally , only deltas with base to another object
* use it if possible . Normally , only deltas with base to another object
* existing in set of objects to pack will be used . Exception is however
* existing in set of objects to pack will be used . Exception is however
* thin - pack ( see
* thin - pack ( see
* { @link # preparePack ( Collection , Collection ) } and
* { @link # preparePack ( ProgressMonitor , Collection , Collection ) } and
* { @link # preparePack ( Iterator ) } ) where base object must exist on other
* { @link # preparePack ( Iterator ) } ) where base object must exist on other
* side machine .
* side machine .
* < p >
* < p >
@ -411,7 +378,7 @@ public class PackWriter {
/ * *
/ * *
* @return true to ignore objects that are uninteresting and also not found
* @return true to ignore objects that are uninteresting and also not found
* on local disk ; false to throw a { @link MissingObjectException }
* on local disk ; false to throw a { @link MissingObjectException }
* out of { @link # preparePack ( Collection , Collection ) } if an
* out of { @link # preparePack ( ProgressMonitor , Collection , Collection ) } if an
* uninteresting object is not in the source repository . By default ,
* uninteresting object is not in the source repository . By default ,
* true , permitting gracefully ignoring of uninteresting objects .
* true , permitting gracefully ignoring of uninteresting objects .
* /
* /
@ -504,6 +471,8 @@ public class PackWriter {
* recency , path and delta - base first .
* recency , path and delta - base first .
* < / p >
* < / p >
*
*
* @param countingMonitor
* progress during object 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 ) .
@ -513,13 +482,15 @@ public class PackWriter {
* @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 (
public void preparePack ( ProgressMonitor countingMonitor ,
final Collection < ? extends ObjectId > interestingObjects ,
final Collection < ? extends ObjectId > interestingObjects ,
final Collection < ? extends ObjectId > uninterestingObjects )
final Collection < ? extends ObjectId > uninterestingObjects )
throws IOException {
throws IOException {
if ( countingMonitor = = null )
countingMonitor = NullProgressMonitor . INSTANCE ;
ObjectWalk walker = setUpWalker ( interestingObjects ,
ObjectWalk walker = setUpWalker ( interestingObjects ,
uninterestingObjects ) ;
uninterestingObjects ) ;
findObjectsToPack ( walker ) ;
findObjectsToPack ( countingMonitor , walker ) ;
}
}
/ * *
/ * *
@ -553,7 +524,7 @@ public class PackWriter {
* Create an index file to match the pack file just written .
* Create an index file to match the pack file just written .
* < p >
* < p >
* This method can only be invoked after { @link # preparePack ( Iterator ) } or
* This method can only be invoked after { @link # preparePack ( Iterator ) } or
* { @link # preparePack ( Collection , Collection ) } has been
* { @link # preparePack ( ProgressMonitor , Collection , Collection ) } has been
* invoked and completed successfully . Writing a corresponding index is an
* invoked and completed successfully . Writing a corresponding index is an
* optional feature that not all pack users may require .
* optional feature that not all pack users may require .
*
*
@ -599,6 +570,10 @@ public class PackWriter {
* validated against existing checksum .
* validated against existing checksum .
* < / p >
* < / p >
*
*
* @param compressMonitor
* progress monitor to report object compression work .
* @param writeMonitor
* progress monitor to report the number of objects written .
* @param packStream
* @param packStream
* output stream of pack data . The stream should be buffered by
* output stream of pack data . The stream should be buffered by
* the caller . The caller is responsible for closing the stream .
* the caller . The caller is responsible for closing the stream .
@ -607,16 +582,23 @@ public class PackWriter {
* the pack , or writing compressed object data to the output
* the pack , or writing compressed object data to the output
* stream .
* stream .
* /
* /
public void writePack ( OutputStream packStream ) throws IOException {
public void writePack ( ProgressMonitor compressMonitor ,
ProgressMonitor writeMonitor , OutputStream packStream )
throws IOException {
if ( compressMonitor = = null )
compressMonitor = NullProgressMonitor . INSTANCE ;
if ( writeMonitor = = null )
writeMonitor = NullProgressMonitor . INSTANCE ;
if ( ( reuseDeltas | | reuseObjects ) & & reuseSupport ! = null )
if ( ( reuseDeltas | | reuseObjects ) & & reuseSupport ! = null )
searchForReuse ( ) ;
searchForReuse ( compressMonitor ) ;
final PackOutputStream out = new PackOutputStream ( packStream ,
final PackOutputStream out = new PackOutputStream ( writeMonitor ,
isDeltaBaseAsOffset ( ) ) ;
packStream , isDeltaBaseAsOffset ( ) ) ;
writeMonitor . beginTask ( WRITING_OBJECTS_PROGRESS , getObjectsNumber ( ) ) ;
writeMonitor . beginTask ( WRITING_OBJECTS_PROGRESS , getObjectsNumber ( ) ) ;
out . writeFileHeader ( PACK_VERSION_GENERATED , getObjectsNumber ( ) ) ;
out . writeFileHeader ( PACK_VERSION_GENERATED , getObjectsNumber ( ) ) ;
writeObjects ( out ) ;
writeObjects ( writeMonitor , out ) ;
writeChecksum ( out ) ;
writeChecksum ( out ) ;
reader . release ( ) ;
reader . release ( ) ;
@ -628,21 +610,23 @@ public class PackWriter {
reader . release ( ) ;
reader . release ( ) ;
}
}
private void searchForReuse ( ) throws IOException {
private void searchForReuse ( ProgressMonitor compressMonitor )
initMonitor . beginTask ( SEARCHING_REUSE_PROGRESS , getObjectsNumber ( ) ) ;
throws IOException {
compressMonitor . beginTask ( SEARCHING_REUSE_PROGRESS , getObjectsNumber ( ) ) ;
for ( List < ObjectToPack > list : objectsLists ) {
for ( List < ObjectToPack > list : objectsLists ) {
for ( ObjectToPack otp : list ) {
for ( ObjectToPack otp : list ) {
if ( init Monitor. isCancelled ( ) )
if ( compress Monitor. isCancelled ( ) )
throw new IOException (
throw new IOException (
JGitText . get ( ) . packingCancelledDuringObjectsWriting ) ;
JGitText . get ( ) . packingCancelledDuringObjectsWriting ) ;
reuseSupport . selectObjectRepresentation ( this , otp ) ;
reuseSupport . selectObjectRepresentation ( this , otp ) ;
init Monitor. update ( 1 ) ;
compress Monitor. update ( 1 ) ;
}
}
}
}
init Monitor. endTask ( ) ;
compress Monitor. endTask ( ) ;
}
}
private void writeObjects ( PackOutputStream out ) throws IOException {
private void writeObjects ( ProgressMonitor writeMonitor , PackOutputStream out )
throws IOException {
for ( List < ObjectToPack > list : objectsLists ) {
for ( List < ObjectToPack > list : objectsLists ) {
for ( ObjectToPack otp : list ) {
for ( ObjectToPack otp : list ) {
if ( writeMonitor . isCancelled ( ) )
if ( writeMonitor . isCancelled ( ) )
@ -669,8 +653,8 @@ public class PackWriter {
while ( otp . isReuseAsIs ( ) ) {
while ( otp . isReuseAsIs ( ) ) {
try {
try {
reuseSupport . copyObjectAsIs ( out , otp ) ;
reuseSupport . copyObjectAsIs ( out , otp ) ;
out . endObject ( ) ;
otp . setCRC ( out . getCRC32 ( ) ) ;
otp . setCRC ( out . getCRC32 ( ) ) ;
writeMonitor . update ( 1 ) ;
return ;
return ;
} catch ( StoredObjectRepresentationNotAvailableException gone ) {
} catch ( StoredObjectRepresentationNotAvailableException gone ) {
if ( otp . getOffset ( ) = = out . length ( ) ) {
if ( otp . getOffset ( ) = = out . length ( ) ) {
@ -690,8 +674,8 @@ public class PackWriter {
// If we reached here, reuse wasn't possible.
// If we reached here, reuse wasn't possible.
//
//
writeWholeObjectDeflate ( out , otp ) ;
writeWholeObjectDeflate ( out , otp ) ;
out . endObject ( ) ;
otp . setCRC ( out . getCRC32 ( ) ) ;
otp . setCRC ( out . getCRC32 ( ) ) ;
writeMonitor . update ( 1 ) ;
}
}
private void writeBaseFirst ( PackOutputStream out , final ObjectToPack otp )
private void writeBaseFirst ( PackOutputStream out , final ObjectToPack otp )
@ -781,22 +765,22 @@ public class PackWriter {
return walker ;
return walker ;
}
}
private void findObjectsToPack ( final ObjectWalk walker )
private void findObjectsToPack ( final ProgressMonitor countingMonitor ,
throws MissingObjectException , IncorrectObjectType Exception,
final ObjectWalk walker ) throws MissingObject Exception,
IOException {
IncorrectObjectTypeException , I OException {
init Monitor. beginTask ( COUNTING_OBJECTS_PROGRESS ,
counting Monitor. beginTask ( COUNTING_OBJECTS_PROGRESS ,
ProgressMonitor . UNKNOWN ) ;
ProgressMonitor . UNKNOWN ) ;
RevObject o ;
RevObject o ;
while ( ( o = walker . next ( ) ) ! = null ) {
while ( ( o = walker . next ( ) ) ! = null ) {
addObject ( o ) ;
addObject ( o ) ;
init Monitor. update ( 1 ) ;
counting Monitor. update ( 1 ) ;
}
}
while ( ( o = walker . nextObject ( ) ) ! = null ) {
while ( ( o = walker . nextObject ( ) ) ! = null ) {
addObject ( o ) ;
addObject ( o ) ;
init Monitor. update ( 1 ) ;
counting Monitor. update ( 1 ) ;
}
}
init Monitor. endTask ( ) ;
counting Monitor. endTask ( ) ;
}
}
/ * *
/ * *