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