Allow to perform PackedBatchRefUpdate without locking loose refs
Add another newBatchUpdate method in the RefDirectory where we can control if the created PackedBatchRefUpdate will lock the loose refs or not. This can be useful in cases when we run programs which have exclusive access to a Git repository and we know that locking loose refs is unnecessary and just a performance loss. Change-Id: I7d0932eb1598a3871a2281b1a049021380234df9
This commit is contained in:
parent
d01376106a
commit
cb90ed0852
|
@ -86,10 +86,16 @@
|
|||
*/
|
||||
class PackedBatchRefUpdate extends BatchRefUpdate {
|
||||
private RefDirectory refdb;
|
||||
private boolean shouldLockLooseRefs;
|
||||
|
||||
PackedBatchRefUpdate(RefDirectory refdb) {
|
||||
super(refdb);
|
||||
this.refdb = refdb;
|
||||
this(refdb, true);
|
||||
}
|
||||
|
||||
PackedBatchRefUpdate(RefDirectory refdb, boolean shouldLockLooseRefs) {
|
||||
super(refdb);
|
||||
this.refdb = refdb;
|
||||
this.shouldLockLooseRefs = shouldLockLooseRefs;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -155,7 +161,7 @@ public void execute(RevWalk walk, ProgressMonitor monitor,
|
|||
refdb.inProcessPackedRefsLock.lock();
|
||||
try {
|
||||
PackedRefList oldPackedList;
|
||||
if (!refdb.isInClone()) {
|
||||
if (!refdb.isInClone() && shouldLockLooseRefs) {
|
||||
locks = lockLooseRefs(pending);
|
||||
if (locks == null) {
|
||||
return;
|
||||
|
|
|
@ -587,6 +587,21 @@ public PackedBatchRefUpdate newBatchUpdate() {
|
|||
return new PackedBatchRefUpdate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new batch update to attempt on this database.
|
||||
*
|
||||
* @param shouldLockLooseRefs
|
||||
* whether loose refs should be locked during the batch ref
|
||||
* update. Note that this should only be set to {@code false} if
|
||||
* the application using this ensures that no other ref updates
|
||||
* run concurrently to avoid lost updates caused by a race. In
|
||||
* such cases it can improve performance.
|
||||
* @return a new batch update object
|
||||
*/
|
||||
public PackedBatchRefUpdate newBatchUpdate(boolean shouldLockLooseRefs) {
|
||||
return new PackedBatchRefUpdate(this, shouldLockLooseRefs);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean performsAtomicTransactions() {
|
||||
|
|
Loading…
Reference in New Issue