aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-06-13 23:55:46 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-06-13 23:55:46 +0200
commite2dc4b9c6445f91da73437e2ccc9729d86f776e2 (patch)
tree957235f6173e035b314b05229336a46ac29ed3f8 /org.eclipse.jgit/src/org/eclipse
parent3d156790e9b9ac095bd9abd100b79d4fecbe7ecf (diff)
parent84063386b5bd65ded738d227cc9dd6abdbb97b88 (diff)
downloadjgit-e2dc4b9c6445f91da73437e2ccc9729d86f776e2.tar.gz
jgit-e2dc4b9c6445f91da73437e2ccc9729d86f776e2.zip
Merge branch 'stable-5.9' into stable-5.10
* stable-5.9: Prepare 5.1.17-SNAPSHOT builds JGit v5.1.16.202106041830-r BatchRefUpdate: Skip saving conflicting ref names and prefixes in memory BatchRefUpdateTest: Accurately assert RefsChangedEvent(s) fired Optimize RefDirectory.isNameConflicting() Update bazlets and bazel version Change-Id: Ib1299564a4cfb9c01f422d7ada05fcfac29700f8
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java35
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java54
2 files changed, 16 insertions, 73 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index 7d108feae9..17a910008c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -244,47 +244,18 @@ public class RefDirectory extends RefDatabase {
/** {@inheritDoc} */
@Override
public boolean isNameConflicting(String name) throws IOException {
- RefList<Ref> packed = getPackedRefs();
- RefList<LooseRef> loose = getLooseRefs();
-
// Cannot be nested within an existing reference.
int lastSlash = name.lastIndexOf('/');
while (0 < lastSlash) {
String needle = name.substring(0, lastSlash);
- if (loose.contains(needle) || packed.contains(needle))
+ if (exactRef(needle) != null) {
return true;
+ }
lastSlash = name.lastIndexOf('/', lastSlash - 1);
}
// Cannot be the container of an existing reference.
- String prefix = name + '/';
- int idx;
-
- idx = -(packed.find(prefix) + 1);
- if (idx < packed.size() && packed.get(idx).getName().startsWith(prefix))
- return true;
-
- idx = -(loose.find(prefix) + 1);
- if (idx < loose.size() && loose.get(idx).getName().startsWith(prefix))
- return true;
-
- return false;
- }
-
- private RefList<LooseRef> getLooseRefs() {
- final RefList<LooseRef> oldLoose = looseRefs.get();
-
- LooseScanner scan = new LooseScanner(oldLoose);
- scan.scan(ALL);
-
- RefList<LooseRef> loose;
- if (scan.newLoose != null) {
- loose = scan.newLoose.toRefList();
- if (looseRefs.compareAndSet(oldLoose, loose))
- modCnt.incrementAndGet();
- } else
- loose = oldLoose;
- return loose;
+ return !getRefsByPrefix(name + '/').isEmpty();
}
@Nullable
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java
index 06009f885d..ef1379a238 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java
@@ -13,7 +13,6 @@ package org.eclipse.jgit.lib;
import static org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED;
import static org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_OTHER_REASON;
-import static java.util.stream.Collectors.toCollection;
import java.io.IOException;
import java.text.MessageFormat;
@@ -29,7 +28,6 @@ import java.util.concurrent.TimeoutException;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.JGitText;
-import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.PushCertificate;
import org.eclipse.jgit.transport.ReceiveCommand;
@@ -495,42 +493,24 @@ public class BatchRefUpdate {
}
}
if (!commands2.isEmpty()) {
- // What part of the name space is already taken
- Collection<String> takenNames = refdb.getRefs().stream()
- .map(Ref::getName)
- .collect(toCollection(HashSet::new));
- Collection<String> takenPrefixes = getTakenPrefixes(takenNames);
-
- // Now to the update that may require more room in the name space
+ // Perform updates that may require more room in the name space
for (ReceiveCommand cmd : commands2) {
try {
if (cmd.getResult() == NOT_ATTEMPTED) {
cmd.updateType(walk);
RefUpdate ru = newUpdate(cmd);
- SWITCH: switch (cmd.getType()) {
- case DELETE:
- // Performed in the first phase
- break;
- case UPDATE:
- case UPDATE_NONFASTFORWARD:
- RefUpdate ruu = newUpdate(cmd);
- cmd.setResult(ruu.update(walk));
- break;
- case CREATE:
- for (String prefix : getPrefixes(cmd.getRefName())) {
- if (takenNames.contains(prefix)) {
- cmd.setResult(Result.LOCK_FAILURE);
- break SWITCH;
- }
- }
- if (takenPrefixes.contains(cmd.getRefName())) {
- cmd.setResult(Result.LOCK_FAILURE);
- break SWITCH;
- }
- ru.setCheckConflicting(false);
- takenPrefixes.addAll(getPrefixes(cmd.getRefName()));
- takenNames.add(cmd.getRefName());
- cmd.setResult(ru.update(walk));
+ switch (cmd.getType()) {
+ case DELETE:
+ // Performed in the first phase
+ break;
+ case UPDATE:
+ case UPDATE_NONFASTFORWARD:
+ RefUpdate ruu = newUpdate(cmd);
+ cmd.setResult(ruu.update(walk));
+ break;
+ case CREATE:
+ cmd.setResult(ru.update(walk));
+ break;
}
}
} catch (IOException err) {
@@ -602,14 +582,6 @@ public class BatchRefUpdate {
execute(walk, monitor, null);
}
- private static Collection<String> getTakenPrefixes(Collection<String> names) {
- Collection<String> ref = new HashSet<>();
- for (String name : names) {
- addPrefixesTo(name, ref);
- }
- return ref;
- }
-
/**
* Get all path prefixes of a ref name.
*