aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-06-04 18:21:31 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2021-06-04 18:21:31 -0400
commitf6b8589c2b6223d2e6cd770929bc4f05fb8529f7 (patch)
tree75d347065433f9a97f64add80616ca65dfaa990a
parent6f083e7cfd57b14c7048eec64fe06975ac015130 (diff)
parent8bc166b00da5fc74a659b42be779328a9508866b (diff)
downloadjgit-f6b8589c2b6223d2e6cd770929bc4f05fb8529f7.tar.gz
jgit-f6b8589c2b6223d2e6cd770929bc4f05fb8529f7.zip
Merge changes I853ac6c7,I01878116,Ie994fc18 into stable-5.1
* changes: BatchRefUpdate: Skip saving conflicting ref names and prefixes in memory BatchRefUpdateTest: Accurately assert RefsChangedEvent(s) fired Optimize RefDirectory.isNameConflicting()
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java346
-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
3 files changed, 322 insertions, 113 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java
index 2ac4a846ea..d0e3943d1e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java
@@ -205,17 +205,33 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", A,
"refs/heads/masters", B);
- assertEquals(1, refsChangedEvents);
} else {
assertResults(cmds, OK, REJECTED_NONFASTFORWARD);
assertRefs(
"refs/heads/master", B,
"refs/heads/masters", B);
- assertEquals(2, refsChangedEvents);
}
}
@Test
+ public void simpleNoForceRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ writeLooseRef("refs/heads/masters", B);
+ refdir.exactRef("refs/heads/master");
+ refdir.exactRef("refs/heads/masters");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(B, A, "refs/heads/masters",
+ UPDATE_NONFASTFORWARD));
+ execute(newBatchUpdate(cmds));
+
+ assertEquals(atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
+ @Test
public void simpleForce() throws IOException {
writeLooseRef("refs/heads/master", A);
writeLooseRef("refs/heads/masters", B);
@@ -229,7 +245,24 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", B,
"refs/heads/masters", A);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ }
+
+ @Test
+ public void simpleForceRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ writeLooseRef("refs/heads/masters", B);
+ refdir.exactRef("refs/heads/master");
+ refdir.exactRef("refs/heads/masters");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(B, A, "refs/heads/masters",
+ UPDATE_NONFASTFORWARD));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
}
@Test
@@ -251,7 +284,28 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertResults(cmds, OK);
assertRefs("refs/heads/master", A);
- assertEquals(2, refsChangedEvents);
+ }
+
+ @Test
+ public void nonFastForwardDoesNotDoExpensiveMergeCheckRefsChangedEvents()
+ throws IOException {
+ writeLooseRef("refs/heads/master", B);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(new ReceiveCommand(B, A,
+ "refs/heads/master", UPDATE_NONFASTFORWARD));
+ try (RevWalk rw = new RevWalk(diskRepo) {
+ @Override
+ public boolean isMergedInto(RevCommit base, RevCommit tip) {
+ throw new AssertionError("isMergedInto() should not be called");
+ }
+ }) {
+ newBatchUpdate(cmds).setAllowNonFastForwards(true).execute(rw,
+ new StrictWorkMonitor());
+ }
+
+ assertEquals(initialRefsChangedEvents + 1, refsChangedEvents);
}
@Test
@@ -273,7 +327,6 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", A,
"refs/heads/masters", B);
- assertEquals(1, refsChangedEvents);
} else {
// Non-atomic updates are applied in order: master succeeds, then master/x
// fails due to conflict.
@@ -281,11 +334,28 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", B,
"refs/heads/masters", B);
- assertEquals(2, refsChangedEvents);
}
}
@Test
+ public void fileDirectoryConflictRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ writeLooseRef("refs/heads/masters", B);
+ refdir.exactRef("refs/heads/master");
+ refdir.exactRef("refs/heads/masters");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), A, "refs/heads/master/x", CREATE),
+ new ReceiveCommand(zeroId(), A, "refs/heads", CREATE));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true), false);
+
+ assertEquals(atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
+ @Test
public void conflictThanksToDelete() throws IOException {
writeLooseRef("refs/heads/master", A);
writeLooseRef("refs/heads/masters", B);
@@ -300,15 +370,24 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", B,
"refs/heads/masters/x", A);
- if (atomic) {
- assertEquals(2, refsChangedEvents);
- } else {
- // The non-atomic case actually produces 5 events, but that's an
- // implementation detail. We expect at least 4 events, one for the
- // initial read due to writeLooseRef(), and then one for each
- // successful ref update.
- assertTrue(refsChangedEvents >= 4);
- }
+ }
+
+ @Test
+ public void conflictThanksToDeleteRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ writeLooseRef("refs/heads/masters", B);
+ refdir.exactRef("refs/heads/master");
+ refdir.exactRef("refs/heads/masters");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), A, "refs/heads/masters/x", CREATE),
+ new ReceiveCommand(B, zeroId(), "refs/heads/masters", DELETE));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 3, refsChangedEvents);
}
@Test
@@ -325,17 +404,32 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, REJECTED_MISSING_OBJECT, TRANSACTION_ABORTED);
assertRefs("refs/heads/master", A);
- assertEquals(1, refsChangedEvents);
} else {
assertResults(cmds, REJECTED_MISSING_OBJECT, OK);
assertRefs(
"refs/heads/master", A,
"refs/heads/foo2", B);
- assertEquals(2, refsChangedEvents);
}
}
@Test
+ public void updateToMissingObjectRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ ObjectId bad = ObjectId
+ .fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, bad, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), B, "refs/heads/foo2", CREATE));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true), false);
+
+ assertEquals(atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
+ @Test
public void addMissingObject() throws IOException {
writeLooseRef("refs/heads/master", A);
@@ -349,15 +443,30 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, TRANSACTION_ABORTED, REJECTED_MISSING_OBJECT);
assertRefs("refs/heads/master", A);
- assertEquals(1, refsChangedEvents);
} else {
assertResults(cmds, OK, REJECTED_MISSING_OBJECT);
assertRefs("refs/heads/master", B);
- assertEquals(2, refsChangedEvents);
}
}
@Test
+ public void addMissingObjectRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ ObjectId bad = ObjectId
+ .fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), bad, "refs/heads/foo2", CREATE));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true), false);
+
+ assertEquals(atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
+ @Test
public void oneNonExistentRef() throws IOException {
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, B, "refs/heads/foo1", UPDATE),
@@ -387,17 +496,30 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, LOCK_FAILURE, TRANSACTION_ABORTED);
assertRefs("refs/heads/master", A);
- assertEquals(1, refsChangedEvents);
} else {
assertResults(cmds, LOCK_FAILURE, OK);
assertRefs(
"refs/heads/master", A,
"refs/heads/foo2", B);
- assertEquals(2, refsChangedEvents);
}
}
@Test
+ public void oneRefWrongOldValueRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(B, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), B, "refs/heads/foo2", CREATE));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
+ @Test
public void nonExistentRef() throws IOException {
writeLooseRef("refs/heads/master", A);
@@ -409,17 +531,31 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, TRANSACTION_ABORTED, LOCK_FAILURE);
assertRefs("refs/heads/master", A);
- assertEquals(1, refsChangedEvents);
} else {
assertResults(cmds, OK, LOCK_FAILURE);
assertRefs("refs/heads/master", B);
- assertEquals(2, refsChangedEvents);
}
}
@Test
+ public void nonExistentRefRefsChangedEvents() throws IOException {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(A, zeroId(), "refs/heads/foo2", DELETE));
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
+ @Test
public void noRefLog() throws IOException {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
Map<String, ReflogEntry> oldLogs =
getLastReflogs("refs/heads/master", "refs/heads/branch");
@@ -434,7 +570,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", B,
"refs/heads/branch", B);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertReflogUnchanged(oldLogs, "refs/heads/master");
assertReflogUnchanged(oldLogs, "refs/heads/branch");
}
@@ -443,6 +580,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
public void reflogDefaultIdent() throws IOException {
writeRef("refs/heads/master", A);
writeRef("refs/heads/branch2", A);
+ int initialRefsChangedEvents = refsChangedEvents;
Map<String, ReflogEntry> oldLogs = getLastReflogs(
"refs/heads/master", "refs/heads/branch1", "refs/heads/branch2");
@@ -459,7 +597,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
"refs/heads/master", B,
"refs/heads/branch1", B,
"refs/heads/branch2", A);
- assertEquals(atomic ? 3 : 4, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertReflogEquals(
reflog(A, B, new PersonIdent(diskRepo), "a reflog"),
getLastReflog("refs/heads/master"));
@@ -473,6 +612,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
public void reflogAppendStatusNoMessage() throws IOException {
writeRef("refs/heads/master", A);
writeRef("refs/heads/branch1", B);
+ int initialRefsChangedEvents = refsChangedEvents;
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
@@ -488,7 +628,9 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
"refs/heads/master", B,
"refs/heads/branch1", A,
"refs/heads/branch2", A);
- assertEquals(atomic ? 3 : 5, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 3,
+ refsChangedEvents);
assertReflogEquals(
// Always forced; setAllowNonFastForwards(true) bypasses the check.
reflog(A, B, new PersonIdent(diskRepo), "forced-update"),
@@ -504,6 +646,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void reflogAppendStatusFastForward() throws IOException {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, B, "refs/heads/master", UPDATE));
@@ -511,7 +654,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertResults(cmds, OK);
assertRefs("refs/heads/master", B);
- assertEquals(2, refsChangedEvents);
+ assertEquals(initialRefsChangedEvents + 1, refsChangedEvents);
assertReflogEquals(
reflog(A, B, new PersonIdent(diskRepo), "fast-forward"),
getLastReflog("refs/heads/master"));
@@ -520,6 +663,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void reflogAppendStatusWithMessage() throws IOException {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
@@ -530,7 +674,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertRefs(
"refs/heads/master", B,
"refs/heads/branch", A);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertReflogEquals(
reflog(A, B, new PersonIdent(diskRepo), "a reflog: fast-forward"),
getLastReflog("refs/heads/master"));
@@ -542,6 +687,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void reflogCustomIdent() throws IOException {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
@@ -553,7 +699,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
.setRefLogIdent(ident));
assertResults(cmds, OK, OK);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertRefs(
"refs/heads/master", B,
"refs/heads/branch", B);
@@ -571,6 +718,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
public void reflogDelete() throws IOException {
writeRef("refs/heads/master", A);
writeRef("refs/heads/branch", A);
+ int initialRefsChangedEvents = refsChangedEvents;
+
assertEquals(
2, getLastReflogs("refs/heads/master", "refs/heads/branch").size());
@@ -581,7 +730,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertResults(cmds, OK, OK);
assertRefs("refs/heads/branch", B);
- assertEquals(atomic ? 3 : 4, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertNull(getLastReflog("refs/heads/master"));
assertReflogEquals(
reflog(A, B, new PersonIdent(diskRepo), "a reflog"),
@@ -591,6 +741,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void reflogFileDirectoryConflict() throws IOException {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, zeroId(), "refs/heads/master", DELETE),
@@ -599,7 +750,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertResults(cmds, OK, OK);
assertRefs("refs/heads/master/x", A);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertNull(getLastReflog("refs/heads/master"));
assertReflogEquals(
reflog(zeroId(), A, new PersonIdent(diskRepo), "a reflog"),
@@ -609,6 +761,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void reflogOnLockFailure() throws IOException {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
Map<String, ReflogEntry> oldLogs =
getLastReflogs("refs/heads/master", "refs/heads/branch");
@@ -620,12 +773,12 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, TRANSACTION_ABORTED, LOCK_FAILURE);
- assertEquals(1, refsChangedEvents);
+ assertEquals(initialRefsChangedEvents, refsChangedEvents);
assertReflogUnchanged(oldLogs, "refs/heads/master");
assertReflogUnchanged(oldLogs, "refs/heads/branch");
} else {
assertResults(cmds, OK, LOCK_FAILURE);
- assertEquals(2, refsChangedEvents);
+ assertEquals(initialRefsChangedEvents + 1, refsChangedEvents);
assertReflogEquals(
reflog(A, B, new PersonIdent(diskRepo), "a reflog"),
getLastReflog("refs/heads/master"));
@@ -636,6 +789,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void overrideRefLogMessage() throws Exception {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
List<ReceiveCommand> cmds = Arrays.asList(
new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
@@ -648,7 +802,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
.setRefLogMessage("a reflog", true));
assertResults(cmds, OK, OK);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertReflogEquals(
reflog(A, B, ident, "custom log"),
getLastReflog("refs/heads/master"),
@@ -662,6 +817,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
@Test
public void overrideDisableRefLog() throws Exception {
writeRef("refs/heads/master", A);
+ int initialRefsChangedEvents = refsChangedEvents;
Map<String, ReflogEntry> oldLogs =
getLastReflogs("refs/heads/master", "refs/heads/branch");
@@ -673,7 +829,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
execute(newBatchUpdate(cmds).setRefLogMessage("a reflog", true));
assertResults(cmds, OK, OK);
- assertEquals(atomic ? 2 : 3, refsChangedEvents);
+ assertEquals(atomic ? initialRefsChangedEvents + 1
+ : initialRefsChangedEvents + 2, refsChangedEvents);
assertReflogUnchanged(oldLogs, "refs/heads/master");
assertReflogEquals(
reflog(zeroId(), B, new PersonIdent(diskRepo), "a reflog: created"),
@@ -763,14 +920,12 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, LOCK_FAILURE, TRANSACTION_ABORTED);
assertRefs("refs/heads/master", A);
- assertEquals(1, refsChangedEvents);
} else {
// Only operates on loose refs, doesn't care that packed-refs is locked.
assertResults(cmds, OK, OK);
assertRefs(
"refs/heads/master", B,
"refs/heads/branch", B);
- assertEquals(3, refsChangedEvents);
}
} finally {
myLock.unlock();
@@ -778,6 +933,29 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
}
@Test
+ public void packedRefsLockFailureRefsChangedEvents() throws Exception {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), B, "refs/heads/branch", CREATE));
+
+ LockFile myLock = refdir.lockPackedRefs();
+ try {
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(
+ atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 2,
+ refsChangedEvents);
+ } finally {
+ myLock.unlock();
+ }
+ }
+
+ @Test
public void oneRefLockFailure() throws Exception {
writeLooseRef("refs/heads/master", A);
@@ -796,13 +974,11 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
if (atomic) {
assertResults(cmds, TRANSACTION_ABORTED, LOCK_FAILURE);
assertRefs("refs/heads/master", A);
- assertEquals(1, refsChangedEvents);
} else {
assertResults(cmds, OK, LOCK_FAILURE);
assertRefs(
"refs/heads/branch", B,
"refs/heads/master", A);
- assertEquals(2, refsChangedEvents);
}
} finally {
myLock.unlock();
@@ -810,6 +986,30 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
}
@Test
+ public void oneRefLockFailureRefsChangedEvents() throws Exception {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(zeroId(), B, "refs/heads/branch", CREATE),
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE));
+
+ LockFile myLock = new LockFile(refdir.fileFor("refs/heads/master"));
+ assertTrue(myLock.lock());
+ try {
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(
+ atomic ? initialRefsChangedEvents
+ : initialRefsChangedEvents + 1,
+ refsChangedEvents);
+ } finally {
+ myLock.unlock();
+ }
+ }
+
+ @Test
public void singleRefUpdateDoesNotRequirePackedRefsLock() throws Exception {
writeLooseRef("refs/heads/master", A);
@@ -822,7 +1022,6 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
assertFalse(getLockFile("refs/heads/master").exists());
assertResults(cmds, OK);
- assertEquals(2, refsChangedEvents);
assertRefs("refs/heads/master", B);
} finally {
myLock.unlock();
@@ -830,6 +1029,26 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
}
@Test
+ public void singleRefUpdateDoesNotRequirePackedRefsLockRefsChangedEvents()
+ throws Exception {
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays
+ .asList(new ReceiveCommand(A, B, "refs/heads/master", UPDATE));
+
+ LockFile myLock = refdir.lockPackedRefs();
+ try {
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+
+ assertEquals(initialRefsChangedEvents + 1, refsChangedEvents);
+ } finally {
+ myLock.unlock();
+ }
+ }
+
+ @Test
public void atomicUpdateRespectsInProcessLock() throws Exception {
assumeTrue(atomic);
@@ -881,6 +1100,53 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
"refs/heads/branch", B);
}
+ @Test
+ public void atomicUpdateRespectsInProcessLockRefsChangedEvents()
+ throws Exception {
+ assumeTrue(atomic);
+
+ writeLooseRef("refs/heads/master", A);
+ refdir.exactRef("refs/heads/master");
+ int initialRefsChangedEvents = refsChangedEvents;
+
+ List<ReceiveCommand> cmds = Arrays.asList(
+ new ReceiveCommand(A, B, "refs/heads/master", UPDATE),
+ new ReceiveCommand(zeroId(), B, "refs/heads/branch", CREATE));
+
+ Thread t = new Thread(() -> {
+ try {
+ execute(newBatchUpdate(cmds).setAllowNonFastForwards(true));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+
+ ReentrantLock l = refdir.inProcessPackedRefsLock;
+ l.lock();
+ try {
+ t.start();
+ long timeoutSecs = 10;
+
+ // Hold onto the lock until we observe the worker thread has
+ // attempted to
+ // acquire it.
+ while (l.getQueueLength() == 0) {
+ Thread.sleep(3);
+ }
+
+ // Once we unlock, the worker thread should finish the update
+ // promptly.
+ l.unlock();
+ t.join(SECONDS.toMillis(timeoutSecs));
+ } finally {
+ if (l.isHeldByCurrentThread()) {
+ l.unlock();
+ }
+ }
+
+ assertEquals(initialRefsChangedEvents + 1, refsChangedEvents);
+ }
+
private void setLogAllRefUpdates(boolean enable) throws Exception {
StoredConfig cfg = diskRepo.getConfig();
cfg.load();
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 de7e4b3f25..f7a52a54b6 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
@@ -276,47 +276,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();
}
/** {@inheritDoc} */
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 925b6beadb..46d2ab3397 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java
@@ -46,7 +46,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;
@@ -62,7 +61,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;
@@ -528,42 +526,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) {
@@ -635,14 +615,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.
*
Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/CONTRIBUTING.md
blob: fd87513ec2a86c870ace782ab9ec8282a1017307 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Submitting issues

If you have questions about how to use ownCloud, please direct these to the [mailing list][mailinglist] or our [forum][forum]. We are also available on [IRC][irc].

### Guidelines
* Please search the existing issues first, it's likely that your issue was already reported.
* [Report the issue](https://github.com/owncloud/core/issues/new) using our [template][template], it includes all the informations we need to track down the issue.
* This repository is *only* for issues within the ownCloud core code. Issues in other compontents should be reported in their own repositores: 
  - [Android client](https://github.com/owncloud/android/issues)
  - [iOS client](https://github.com/owncloud/ios-issues/issues)
  - [Desktop client](https://github.com/owncloud/mirall/issues)
  - Apps:
      - [Bookmarks](https://github.com/owncloud/bookmarks/issues)
      - [Calendar](https://github.com/owncloud/calendar/issues)
      - [Contacts](https://github.com/owncloud/contacts/issues)
      - [Mail](https://github.com/owncloud/mail/issues)
      - [News](https://github.com/owncloud/news/issues)
      - [Notes](https://github.com/owncloud/notes/issues)
      - [Shorty](https://github.com/owncloud/shorty/issues)
      - [other apps](https://github.com/owncloud/apps/issues) (e.g. Pictures, Music, Tasks, ...)

If your issue appears to be a bug, and hasn't been reported, open a new issue.

Help us to maximize the effort we can spend fixing issues and adding new features, by not reporting duplicate issues.

[template]: https://raw.github.com/owncloud/core/master/issue_template.md
[mailinglist]: https://mail.kde.org/mailman/listinfo/owncloud
[forum]: http://forum.owncloud.org/
[irc]: http://webchat.freenode.net/?channels=owncloud&uio=d4

## Contributing to Source Code

Thanks for wanting to contribute source code to ownCloud. That's great!

Before we're able to merge your code into the ownCloud core, you need to sign our [Contributor Agreement][agreement].

Please read the [Developer Manuals][devmanual] to get useful infos like how to create your first application or how to test the ownCloud code with phpunit.

[agreement]: http://owncloud.org/about/contributor-agreement/
[devmanual]: http://owncloud.org/dev/

## Translations
Please submit translations via [Transifex][transifex].

[transifex]: https://www.transifex.com/projects/p/owncloud/