@ -89,6 +89,9 @@ public class BatchRefUpdate {
/** Push certificate associated with this update. */
/** Push certificate associated with this update. */
private PushCertificate pushCert ;
private PushCertificate pushCert ;
/** Whether updates should be atomic. */
private boolean atomic ;
/ * *
/ * *
* Initialize a new batch update .
* Initialize a new batch update .
*
*
@ -98,6 +101,7 @@ public class BatchRefUpdate {
protected BatchRefUpdate ( RefDatabase refdb ) {
protected BatchRefUpdate ( RefDatabase refdb ) {
this . refdb = refdb ;
this . refdb = refdb ;
this . commands = new ArrayList < ReceiveCommand > ( ) ;
this . commands = new ArrayList < ReceiveCommand > ( ) ;
this . atomic = refdb . performsAtomicTransactions ( ) ;
}
}
/ * *
/ * *
@ -199,6 +203,36 @@ public class BatchRefUpdate {
return refLogMessage = = null ;
return refLogMessage = = null ;
}
}
/ * *
* Request that all updates in this batch be performed atomically .
* < p >
* When atomic updates are used , either all commands apply successfully , or
* none do . Commands that might have otherwise succeeded are rejected with
* { @code REJECTED_OTHER_REASON } .
* < p >
* This method only works if the underlying ref database supports atomic
* transactions , i . e . { @link RefDatabase # performsAtomicTransactions ( ) } returns
* true . Calling this method with true if the underlying ref database does not
* support atomic transactions will cause all commands to fail with { @code
* REJECTED_OTHER_REASON } .
*
* @param atomic whether updates should be atomic .
* @return { @code this }
* @since 4 . 4
* /
public BatchRefUpdate setAtomic ( boolean atomic ) {
this . atomic = atomic ;
return this ;
}
/ * *
* @return atomic whether updates should be atomic .
* @since 4 . 4
* /
public boolean isAtomic ( ) {
return atomic ;
}
/ * *
/ * *
* Set a push certificate associated with this update .
* Set a push certificate associated with this update .
* < p >
* < p >
@ -271,6 +305,10 @@ public class BatchRefUpdate {
* < p >
* < p >
* The default implementation of this method performs a sequential reference
* The default implementation of this method performs a sequential reference
* update over each reference .
* update over each reference .
* < p >
* Implementations must respect the atomicity requirements of the underlying
* database as described in { @link # setAtomic ( boolean ) } and { @link
* RefDatabase # performsAtomicTransactions ( ) } .
*
*
* @param walk
* @param walk
* a RevWalk to parse tags in case the storage system wants to
* a RevWalk to parse tags in case the storage system wants to
@ -284,6 +322,17 @@ public class BatchRefUpdate {
* /
* /
public void execute ( RevWalk walk , ProgressMonitor monitor )
public void execute ( RevWalk walk , ProgressMonitor monitor )
throws IOException {
throws IOException {
if ( atomic & & ! refdb . performsAtomicTransactions ( ) ) {
for ( ReceiveCommand c : commands ) {
if ( c . getResult ( ) = = NOT_ATTEMPTED ) {
c . setResult ( REJECTED_OTHER_REASON ,
JGitText . get ( ) . atomicRefUpdatesNotSupported ) ;
}
}
return ;
}
monitor . beginTask ( JGitText . get ( ) . updatingReferences , commands . size ( ) ) ;
monitor . beginTask ( JGitText . get ( ) . updatingReferences , commands . size ( ) ) ;
List < ReceiveCommand > commands2 = new ArrayList < ReceiveCommand > (
List < ReceiveCommand > commands2 = new ArrayList < ReceiveCommand > (
commands . size ( ) ) ;
commands . size ( ) ) ;