summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-04-26 21:55:16 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-04-26 21:55:16 +0200
commit6082ae25dd92ec5f67fbbcfd00e1c244caf63f87 (patch)
tree08e8cf67021437f40b7d6a746ce000a89309b18d
parente59ade2a6f88cbe18466924f76867e2cc167b233 (diff)
parent9445e42b7a79771dd69a55edacb11f30c499ae86 (diff)
downloadjgit-6082ae25dd92ec5f67fbbcfd00e1c244caf63f87.tar.gz
jgit-6082ae25dd92ec5f67fbbcfd00e1c244caf63f87.zip
Merge branch 'stable-6.0' into stable-6.1
* stable-6.0: [bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory Demote severity of some error prone bug patterns to warnings UploadPack: Fix NPE when traversing a tag chain Change-Id: I5e13d5b5414aef97e518898166bfa166c692e60f
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java69
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java27
-rw-r--r--tools/BUILD6
3 files changed, 86 insertions, 16 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 7131905850..2b05decb45 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -2539,6 +2539,75 @@ public class UploadPackTest {
}
@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
public void testSafeToClearRefsInFetchV0() throws Exception {
server =
new RefCallsCountingRepository(
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 1617c5063d..46abe34fa2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -2405,11 +2405,11 @@ public class UploadPack implements Closeable {
if (peeledId == null || objectId == null)
continue;
- objectId = ref.getObjectId();
- if (pw.willInclude(peeledId) && !pw.willInclude(objectId)) {
- RevObject o = rw.parseAny(objectId);
- addTagChain(o, pw);
- pw.addObject(o);
+ if (pw.willInclude(peeledId)) {
+ // We don't need to handle parseTag throwing an
+ // IncorrectObjectTypeException as we only reach
+ // here when ref is an annotated tag
+ addTagChain(rw.parseTag(objectId), pw);
}
}
}
@@ -2459,15 +2459,16 @@ public class UploadPack implements Closeable {
}
private void addTagChain(
- RevObject o, PackWriter pw) throws IOException {
- while (Constants.OBJ_TAG == o.getType()) {
- RevTag t = (RevTag) o;
- o = t.getObject();
- if (o.getType() == Constants.OBJ_TAG && !pw.willInclude(o.getId())) {
- walk.parseBody(o);
- pw.addObject(o);
+ RevTag tag, PackWriter pw) throws IOException {
+ RevObject o = tag;
+ do {
+ tag = (RevTag) o;
+ walk.parseBody(tag);
+ if (!pw.willInclude(tag.getId())) {
+ pw.addObject(tag);
}
- }
+ o = tag.getObject();
+ } while (Constants.OBJ_TAG == o.getType());
}
private static class ResponseBufferedOutputStream extends OutputStream {
diff --git a/tools/BUILD b/tools/BUILD
index a10901982f..1e671087d6 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -45,7 +45,7 @@ java_package_configuration(
"-Xep:CannotMockFinalClass:ERROR",
"-Xep:ClassCanBeStatic:ERROR",
"-Xep:ClassNewInstance:ERROR",
- "-Xep:DefaultCharset:ERROR",
+ "-Xep:DefaultCharset:WARN",
"-Xep:DoubleCheckedLocking:ERROR",
"-Xep:ElementsCountedInLoop:ERROR",
"-Xep:EqualsHashCode:ERROR",
@@ -55,7 +55,7 @@ java_package_configuration(
"-Xep:FragmentInjection:ERROR",
"-Xep:FragmentNotInstantiable:ERROR",
"-Xep:FunctionalInterfaceClash:ERROR",
- "-Xep:FutureReturnValueIgnored:ERROR",
+ "-Xep:FutureReturnValueIgnored:WARN",
"-Xep:GetClassOnEnum:ERROR",
"-Xep:ImmutableAnnotationChecker:ERROR",
"-Xep:ImmutableEnumChecker:ERROR",
@@ -89,7 +89,7 @@ java_package_configuration(
"-Xep:TypeParameterShadowing:ERROR",
"-Xep:TypeParameterUnusedInFormals:WARN",
"-Xep:URLEqualsHashCode:ERROR",
- "-Xep:UnusedException:ERROR",
+ "-Xep:UnusedException:WARN",
"-Xep:UnsynchronizedOverridesSynchronized:ERROR",
"-Xep:WaitNotInLoop:ERROR",
],