diff options
author | Kaushik Lingarkar <quic_kaushikl@quicinc.com> | 2023-04-04 18:05:53 -0700 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-04-21 02:04:35 +0200 |
commit | 064691e90c4cbf1c550cb65b41b91e6fa07c7c81 (patch) | |
tree | 6bb0e40518559a40ead86618eef7a607c52311db /org.eclipse.jgit/src/org/eclipse | |
parent | 40daa780ef00f999b9e95417a9ee15355d591955 (diff) | |
download | jgit-064691e90c4cbf1c550cb65b41b91e6fa07c7c81.tar.gz jgit-064691e90c4cbf1c550cb65b41b91e6fa07c7c81.zip |
UploadPack: Fix NPE when traversing a tag chain
Always parse RevTags including their body before getting their object
to ensure that non-cached objects are handled correctly when traversing
a tag chain. An NPE in UploadPack#addTagChain will occur on a depth=1
fetch of a branch containing a tag chain and the ref to one of the
middle tags in the chain is deleted.
Change-Id: Ifd8fe868869070b365df926fec5dcd8e64d4f521
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 27 |
1 files changed, 14 insertions, 13 deletions
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 6cb8fe43c0..0c23c8cadf 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 { |