PackedBatchRefUpdate: hold inProcessPackedRefsLock across pack step

refdb.pack() acquires inProcessPackedRefsLock internally, so in a high
contention environment the thread would wait for the lock once inside
pack(), release it, then rejoin the back of the queue waiting for it
again before updating packed-refs.

Signed-off-by: Adithya Chakilam <achakilam@nvidia.com>
Change-Id: I83a9477484cb6da9dcaa807d7e1b0d4f1fd08661
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
index f33fe0b..cd03600 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
@@ -146,20 +146,15 @@ public void execute(RevWalk walk, ProgressMonitor monitor,
 			return;
 		}
 
-		// Pack refs normally, so we can create lock files even in the case where
-		// refs/x is deleted and refs/x/y is created in this batch.
-		try {
-			refdb.pack(
-					pending.stream().map(ReceiveCommand::getRefName).collect(toList()));
-		} catch (LockFailedException e) {
-			lockFailure(pending.get(0), pending);
-			return;
-		}
-
 		Map<String, LockFile> locks = null;
 		LockFile packedRefsLock = null;
 		refdb.inProcessPackedRefsLock.lock();
 		try {
+			// Pack refs normally, so we can create lock files even in the case
+			// where refs/x is deleted and refs/x/y is created in this batch.
+			refdb.pack(pending.stream().map(ReceiveCommand::getRefName)
+					.collect(toList()));
+
 			// During clone locking isn't needed since no refs exist yet.
 			// This also helps to avoid problems with refs only differing in
 			// case on a case insensitive filesystem (bug 528497)