@ -302,9 +302,6 @@ public class UploadPack {
/** Shallow commits the client already has. */
private Set < ObjectId > clientShallowCommits = new HashSet < > ( ) ;
/** Desired depth from the client on a shallow request. */
private int depth ;
/** Commit time of the oldest common commit, in seconds. */
private int oldestTime ;
@ -338,6 +335,15 @@ public class UploadPack {
private PackStatistics statistics ;
/ * *
* Request this instance is handling .
*
* We need to keep a reference to it for { @link PreUploadHook pre upload
* hooks } . They receive a reference this instance and invoke methods like
* getDepth ( ) to get information about the request .
* /
private FetchRequest currentRequest ;
/ * *
* Create a new pack upload for an open repository .
*
@ -809,11 +815,11 @@ public class UploadPack {
ProtocolV0Parser parser = new ProtocolV0Parser ( transferConfig ) ;
req = parser . recvWants ( pckIn ) ;
currentRequest = req ;
wantIds = req . getWantIds ( ) ;
clientShallowCommits = req . getClientShallowCommits ( ) ;
options = req . getClientCapabilities ( ) ;
depth = req . getDepth ( ) ;
if ( req . getWantIds ( ) . isEmpty ( ) ) {
preUploadHook . onBeginNegotiateRound ( this , req . getWantIds ( ) , 0 ) ;
@ -833,7 +839,7 @@ public class UploadPack {
if ( ! clientShallowCommits . isEmpty ( ) )
verifyClientShallow ( clientShallowCommits ) ;
if ( depth ! = 0 | | req . getDeepenSince ( ) ! = 0 ) {
if ( req . getDepth ( ) ! = 0 | | req . getDeepenSince ( ) ! = 0 ) {
computeShallowsAndUnshallows ( req , shallow - > {
pckOut . writeString ( "shallow " + shallow . name ( ) + '\n' ) ; //$NON-NLS-1$
} , unshallow - > {
@ -844,7 +850,7 @@ public class UploadPack {
}
if ( ! clientShallowCommits . isEmpty ( ) )
walk . assumeShallow ( clientShallowCommits ) ;
sendPack = negotiate ( accumulator ) ;
sendPack = negotiate ( req , accumulator ) ;
accumulator . timeNegotiating + = System . currentTimeMillis ( )
- negotiateStart ;
@ -944,6 +950,7 @@ public class UploadPack {
ProtocolV2Parser parser = new ProtocolV2Parser ( transferConfig ) ;
FetchV2Request req = parser . parseFetchRequest ( pckIn ,
db . getRefDatabase ( ) ) ;
currentRequest = req ;
rawOut . stopBuffering ( ) ;
protocolV2Hook . onFetch ( req ) ;
@ -953,7 +960,6 @@ public class UploadPack {
options = req . getClientCapabilities ( ) ;
wantIds = req . getWantIds ( ) ;
clientShallowCommits = req . getClientShallowCommits ( ) ;
depth = req . getDepth ( ) ;
boolean sectionSent = false ;
boolean mayHaveShallow = req . getDepth ( ) ! = 0
@ -1343,9 +1349,9 @@ public class UploadPack {
* @since 4 . 0
* /
public int getDepth ( ) {
if ( options = = null )
if ( currentRequest = = null )
throw new RequestNotYetReadException ( ) ;
return depth ;
return currentRequest . getDepth ( ) ;
}
/ * *
@ -1367,7 +1373,8 @@ public class UploadPack {
return UserAgent . getAgent ( options , userAgent ) ;
}
private boolean negotiate ( PackStatistics . Accumulator accumulator )
private boolean negotiate ( FetchRequest req ,
PackStatistics . Accumulator accumulator )
throws IOException {
okToGiveUp = Boolean . FALSE ;
@ -1383,7 +1390,7 @@ public class UploadPack {
// disconnected, and will try another request with actual want/have.
// Don't report the EOF here, its a bug in the protocol that the client
// just disconnects without sending an END.
if ( ! biDirectionalPipe & & depth > 0 )
if ( ! biDirectionalPipe & & req . getDepth ( ) > 0 )
return false ;
throw eof ;
}
@ -1899,7 +1906,8 @@ public class UploadPack {
} else {
pw . setUseCachedPacks ( true ) ;
}
pw . setUseBitmaps ( depth = = 0 & & clientShallowCommits . isEmpty ( ) ) ;
pw . setUseBitmaps (
req . getDepth ( ) = = 0 & & clientShallowCommits . isEmpty ( ) ) ;
pw . setClientShallowCommits ( clientShallowCommits ) ;
pw . setReuseDeltaCommits ( true ) ;
pw . setDeltaBaseAsOffset ( options . contains ( OPTION_OFS_DELTA ) ) ;
@ -1922,9 +1930,10 @@ public class UploadPack {
}
RevWalk rw = walk ;
if ( depth > 0 | | req . getDeepenSince ( ) ! = 0 ) {
int walkDepth = depth = = 0 ? Integer . MAX_VALUE : depth - 1 ;
pw . setShallowPack ( depth , unshallowCommits ) ;
if ( req . getDepth ( ) > 0 | | req . getDeepenSince ( ) ! = 0 ) {
int walkDepth = req . getDepth ( ) = = 0 ? Integer . MAX_VALUE
: req . getDepth ( ) - 1 ;
pw . setShallowPack ( req . getDepth ( ) , unshallowCommits ) ;
rw = new DepthWalk . RevWalk ( walk . getObjectReader ( ) , walkDepth ) ;
( ( DepthWalk . RevWalk ) rw ) . setDeepenSince ( req . getDeepenSince ( ) ) ;
rw . assumeShallow ( clientShallowCommits ) ;