aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-06-13 23:54:06 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-06-13 23:54:06 +0200
commit0c7b1013290f66450b3b14c4836a5495cefeb1e7 (patch)
treeb8a74bd6313799b5595d02f49ad5fdfc0da04e7d /org.eclipse.jgit/src/org/eclipse
parentadc1fc645f9643c5bda6a8ae3c602f6d42aaa70b (diff)
parente68c381917f8271fa2314f9d3104cf1f7b1fdfde (diff)
downloadjgit-0c7b1013290f66450b3b14c4836a5495cefeb1e7.tar.gz
jgit-0c7b1013290f66450b3b14c4836a5495cefeb1e7.zip
Merge branch 'stable-5.7' into stable-5.8
* stable-5.7: 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: I1ee0d01c14fb7dca151b4e7ae1b989da5a3a01e3
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.
*