@ -76,6 +76,7 @@ import java.util.List;
import java.util.Map ;
import java.util.Map ;
import java.util.Set ;
import java.util.Set ;
import org.eclipse.jgit.annotations.Nullable ;
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.MissingObjectException ;
import org.eclipse.jgit.errors.MissingObjectException ;
@ -866,7 +867,7 @@ public class UploadPack {
}
}
if ( sendPack )
if ( sendPack )
sendPack ( accumulator ) ;
sendPack ( accumulator , refs = = null ? null : refs . values ( ) ) ;
}
}
private void lsRefsV2 ( ) throws IOException {
private void lsRefsV2 ( ) throws IOException {
@ -988,7 +989,8 @@ public class UploadPack {
if ( sectionSent )
if ( sectionSent )
pckOut . writeDelim ( ) ;
pckOut . writeDelim ( ) ;
pckOut . writeString ( "packfile\n" ) ; //$NON-NLS-1$
pckOut . writeString ( "packfile\n" ) ; //$NON-NLS-1$
sendPack ( new PackStatistics . Accumulator ( ) ) ;
sendPack ( new PackStatistics . Accumulator ( ) ,
refs = = null ? null : refs . values ( ) ) ;
}
}
pckOut . end ( ) ;
pckOut . end ( ) ;
}
}
@ -1734,13 +1736,25 @@ public class UploadPack {
return false ;
return false ;
}
}
private void sendPack ( PackStatistics . Accumulator accumulator )
/ * *
throws IOException {
* Send the requested objects to the client .
*
* @param accumulator
* where to write statistics about the content of the pack .
* @param allTags
* refs to search for annotated tags to include in the pack
* if the { @link # OPTION_INCLUDE_TAG } capability was
* requested .
* @throws IOException
* if an error occured while generating or writing the pack .
* /
private void sendPack ( PackStatistics . Accumulator accumulator ,
@Nullable Collection < Ref > allTags ) throws IOException {
final boolean sideband = options . contains ( OPTION_SIDE_BAND )
final boolean sideband = options . contains ( OPTION_SIDE_BAND )
| | options . contains ( OPTION_SIDE_BAND_64K ) ;
| | options . contains ( OPTION_SIDE_BAND_64K ) ;
if ( sideband ) {
if ( sideband ) {
try {
try {
sendPack ( true , accumulator ) ;
sendPack ( true , accumulator , allTags ) ;
} catch ( ServiceMayNotContinueException noPack ) {
} catch ( ServiceMayNotContinueException noPack ) {
// This was already reported on (below).
// This was already reported on (below).
throw noPack ;
throw noPack ;
@ -1761,7 +1775,7 @@ public class UploadPack {
throw err ;
throw err ;
}
}
} else {
} else {
sendPack ( false , accumulator ) ;
sendPack ( false , accumulator , allTags ) ;
}
}
}
}
@ -1781,8 +1795,24 @@ public class UploadPack {
}
}
}
}
/ * *
* Send the requested objects to the client .
*
* @param sideband
* whether to wrap the pack in side - band pkt - lines ,
* interleaved with progress messages and errors .
* @param accumulator
* where to write statistics about the content of the pack .
* @param allTags
* refs to search for annotated tags to include in the pack
* if the { @link # OPTION_INCLUDE_TAG } capability was
* requested .
* @throws IOException
* if an error occured while generating or writing the pack .
* /
private void sendPack ( final boolean sideband ,
private void sendPack ( final boolean sideband ,
PackStatistics . Accumulator accumulator ) throws IOException {
PackStatistics . Accumulator accumulator ,
@Nullable Collection < Ref > allTags ) throws IOException {
ProgressMonitor pm = NullProgressMonitor . INSTANCE ;
ProgressMonitor pm = NullProgressMonitor . INSTANCE ;
OutputStream packOut = rawOut ;
OutputStream packOut = rawOut ;
@ -1842,6 +1872,8 @@ public class UploadPack {
pw . setThin ( options . contains ( OPTION_THIN_PACK ) ) ;
pw . setThin ( options . contains ( OPTION_THIN_PACK ) ) ;
pw . setReuseValidatingObjects ( false ) ;
pw . setReuseValidatingObjects ( false ) ;
// Objects named directly by references go at the beginning
// of the pack.
if ( commonBase . isEmpty ( ) & & refs ! = null ) {
if ( commonBase . isEmpty ( ) & & refs ! = null ) {
Set < ObjectId > tagTargets = new HashSet < > ( ) ;
Set < ObjectId > tagTargets = new HashSet < > ( ) ;
for ( Ref ref : refs . values ( ) ) {
for ( Ref ref : refs . values ( ) ) {
@ -1872,8 +1904,8 @@ public class UploadPack {
rw = ow ;
rw = ow ;
}
}
if ( options . contains ( OPTION_INCLUDE_TAG ) & & ref s ! = null ) {
if ( options . contains ( OPTION_INCLUDE_TAG ) & & allTag s ! = null ) {
for ( Ref ref : refs . values ( ) ) {
for ( Ref ref : allTags ) {
ObjectId objectId = ref . getObjectId ( ) ;
ObjectId objectId = ref . getObjectId ( ) ;
if ( objectId = = null ) {
if ( objectId = = null ) {
// skip unborn branch
// skip unborn branch