Merge branch 'stable-6.1' into stable-6.2

* stable-6.1:
  GcConcurrentTest: @Ignore flaky testInterruptGc
  Fix CommitTemplateConfigTest
  Fix after_open config and Snapshotting RefDir tests to work with bazel
  [bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory
  Demote severity of some error prone bug patterns to warnings
  UploadPack: Fix NPE when traversing a tag chain

Change-Id: I9863cbce95d845efc891724898954b0b2f8dbf7b
This commit is contained in:
Matthias Sohn 2023-04-27 01:48:07 +02:00
commit 206f0f44f6
6 changed files with 111 additions and 16 deletions

View File

@ -51,6 +51,23 @@ tests(tests = glob(
exclude = HELPERS + DATA + EXCLUDED, exclude = HELPERS + DATA + EXCLUDED,
)) ))
# Non abstract base classes used for tests by other test classes
BASE = [
PKG + "internal/storage/file/FileRepositoryBuilderTest.java",
PKG + "internal/storage/file/RefDirectoryTest.java",
]
java_library(
name = "base",
testonly = 1,
srcs = BASE,
deps = [
"//lib:junit",
"//org.eclipse.jgit:jgit",
"//org.eclipse.jgit.junit:junit",
],
)
java_library( java_library(
name = "helpers", name = "helpers",
testonly = 1, testonly = 1,

View File

@ -52,6 +52,12 @@ def tests(tests):
"//lib:xz", "//lib:xz",
"//org.eclipse.jgit.archive:jgit-archive", "//org.eclipse.jgit.archive:jgit-archive",
] ]
if src.endswith("FileRepositoryBuilderAfterOpenConfigTest.java") or \
src.endswith("RefDirectoryAfterOpenConfigTest.java") or \
src.endswith("SnapshottingRefDirectoryTest.java"):
additional_deps = [
":base",
]
heap_size = "-Xmx256m" heap_size = "-Xmx256m"
if src.endswith("HugeCommitMessageTest.java"): if src.endswith("HugeCommitMessageTest.java"):
heap_size = "-Xmx512m" heap_size = "-Xmx512m"

View File

@ -43,6 +43,7 @@
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
public class GcConcurrentTest extends GcTestCase { public class GcConcurrentTest extends GcTestCase {
@ -197,6 +198,7 @@ public void repackAndCheckBitmapUsage() throws Exception {
assertNotNull(getSinglePack(repository).getBitmapIndex()); assertNotNull(getSinglePack(repository).getBitmapIndex());
} }
@Ignore
@Test @Test
public void testInterruptGc() throws Exception { public void testInterruptGc() throws Exception {
FileBasedConfig c = repo.getConfig(); FileBasedConfig c = repo.getConfig();

View File

@ -2538,6 +2538,75 @@ public void onSendPack(UploadPack up,
} }
} }
@Test
public void testSingleBranchShallowCloneTagChainWithReflessTag() throws Exception {
RevCommit one = remote.commit().message("1").create();
remote.update("master", one);
RevTag tag1 = remote.tag("t1", one);
remote.lightweightTag("t1", tag1);
RevTag tag2 = remote.tag("t2", tag1);
RevTag tag3 = remote.tag("t3", tag2);
remote.lightweightTag("t3", tag3);
UploadPack uploadPack = new UploadPack(remote.getRepository());
ByteArrayOutputStream cli = new ByteArrayOutputStream();
PacketLineOut clientWant = new PacketLineOut(cli);
clientWant.writeString("want " + one.name() + " include-tag");
clientWant.writeString("deepen 1\n");
clientWant.end();
clientWant.writeString("done\n");
try (ByteArrayOutputStream serverResponse = new ByteArrayOutputStream()) {
uploadPack.setPreUploadHook(new PreUploadHook() {
@Override
public void onBeginNegotiateRound(UploadPack up,
Collection<? extends ObjectId> wants, int cntOffered)
throws ServiceMayNotContinueException {
// Do nothing.
}
@Override
public void onEndNegotiateRound(UploadPack up,
Collection<? extends ObjectId> wants, int cntCommon,
int cntNotFound, boolean ready)
throws ServiceMayNotContinueException {
// Do nothing.
}
@Override
public void onSendPack(UploadPack up,
Collection<? extends ObjectId> wants,
Collection<? extends ObjectId> haves)
throws ServiceMayNotContinueException {
// collect pack data
serverResponse.reset();
}
});
uploadPack.upload(new ByteArrayInputStream(cli.toByteArray()),
serverResponse, System.err);
ByteArrayInputStream packReceived = new ByteArrayInputStream(
serverResponse.toByteArray());
PackLock lock = null;
try (ObjectInserter ins = client.newObjectInserter()) {
PackParser parser = ins.newPackParser(packReceived);
parser.setAllowThin(true);
parser.setLockMessage("receive-tag-chain");
ProgressMonitor mlc = NullProgressMonitor.INSTANCE;
lock = parser.parse(mlc, mlc);
ins.flush();
} finally {
if (lock != null) {
lock.unlock();
}
}
InMemoryRepository.MemObjDatabase objDb = client
.getObjectDatabase();
assertTrue(objDb.has(one.toObjectId()));
}
}
@Test @Test
public void testSafeToClearRefsInFetchV0() throws Exception { public void testSafeToClearRefsInFetchV0() throws Exception {
server = server =

View File

@ -2405,11 +2405,11 @@ else if (ref.getName().startsWith(Constants.R_HEADS))
if (peeledId == null || objectId == null) if (peeledId == null || objectId == null)
continue; continue;
objectId = ref.getObjectId(); if (pw.willInclude(peeledId)) {
if (pw.willInclude(peeledId) && !pw.willInclude(objectId)) { // We don't need to handle parseTag throwing an
RevObject o = rw.parseAny(objectId); // IncorrectObjectTypeException as we only reach
addTagChain(o, pw); // here when ref is an annotated tag
pw.addObject(o); addTagChain(rw.parseTag(objectId), pw);
} }
} }
} }
@ -2459,15 +2459,16 @@ private static void findSymrefs(
} }
private void addTagChain( private void addTagChain(
RevObject o, PackWriter pw) throws IOException { RevTag tag, PackWriter pw) throws IOException {
while (Constants.OBJ_TAG == o.getType()) { RevObject o = tag;
RevTag t = (RevTag) o; do {
o = t.getObject(); tag = (RevTag) o;
if (o.getType() == Constants.OBJ_TAG && !pw.willInclude(o.getId())) { walk.parseBody(tag);
walk.parseBody(o); if (!pw.willInclude(tag.getId())) {
pw.addObject(o); pw.addObject(tag);
} }
} o = tag.getObject();
} while (Constants.OBJ_TAG == o.getType());
} }
private static class ResponseBufferedOutputStream extends OutputStream { private static class ResponseBufferedOutputStream extends OutputStream {

View File

@ -45,7 +45,7 @@ java_package_configuration(
"-Xep:CannotMockFinalClass:ERROR", "-Xep:CannotMockFinalClass:ERROR",
"-Xep:ClassCanBeStatic:ERROR", "-Xep:ClassCanBeStatic:ERROR",
"-Xep:ClassNewInstance:ERROR", "-Xep:ClassNewInstance:ERROR",
"-Xep:DefaultCharset:ERROR", "-Xep:DefaultCharset:WARN",
"-Xep:DoubleCheckedLocking:ERROR", "-Xep:DoubleCheckedLocking:ERROR",
"-Xep:ElementsCountedInLoop:ERROR", "-Xep:ElementsCountedInLoop:ERROR",
"-Xep:EqualsHashCode:ERROR", "-Xep:EqualsHashCode:ERROR",
@ -55,7 +55,7 @@ java_package_configuration(
"-Xep:FragmentInjection:ERROR", "-Xep:FragmentInjection:ERROR",
"-Xep:FragmentNotInstantiable:ERROR", "-Xep:FragmentNotInstantiable:ERROR",
"-Xep:FunctionalInterfaceClash:ERROR", "-Xep:FunctionalInterfaceClash:ERROR",
"-Xep:FutureReturnValueIgnored:ERROR", "-Xep:FutureReturnValueIgnored:WARN",
"-Xep:GetClassOnEnum:ERROR", "-Xep:GetClassOnEnum:ERROR",
"-Xep:ImmutableAnnotationChecker:ERROR", "-Xep:ImmutableAnnotationChecker:ERROR",
"-Xep:ImmutableEnumChecker:ERROR", "-Xep:ImmutableEnumChecker:ERROR",
@ -89,7 +89,7 @@ java_package_configuration(
"-Xep:TypeParameterShadowing:ERROR", "-Xep:TypeParameterShadowing:ERROR",
"-Xep:TypeParameterUnusedInFormals:WARN", "-Xep:TypeParameterUnusedInFormals:WARN",
"-Xep:URLEqualsHashCode:ERROR", "-Xep:URLEqualsHashCode:ERROR",
"-Xep:UnusedException:ERROR", "-Xep:UnusedException:WARN",
"-Xep:UnsynchronizedOverridesSynchronized:ERROR", "-Xep:UnsynchronizedOverridesSynchronized:ERROR",
"-Xep:WaitNotInLoop:ERROR", "-Xep:WaitNotInLoop:ERROR",
], ],