From 21d22e6f63a1adcfaeaee155f1be32f8123fd789 Mon Sep 17 00:00:00 2001 From: Zhen Chen Date: Wed, 3 Jan 2018 14:12:30 -0800 Subject: [PATCH] Skip unborn branches in UploadPack The ObjectId of an unborn branch is null, skip those in UploadPack. Change-Id: I7cbf66b05dff98c4fe9f33e20a647ba6acf364b2 Signed-off-by: Zhen Chen --- .../src/org/eclipse/jgit/lib/Repository.java | 3 ++- .../src/org/eclipse/jgit/transport/UploadPack.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 8c448af904..4c0bde1376 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -1104,7 +1104,8 @@ public abstract class Repository implements AutoCloseable { } /** - * Get mutable map of all known refs + * Get mutable map of all known refs, including symrefs like HEAD that may + * not point to any object yet. * * @return mutable map of all known refs (heads, tags, remotes). */ 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 822d47c7c2..5034c34d84 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1617,6 +1617,10 @@ public class UploadPack { if (options.contains(OPTION_INCLUDE_TAG) && refs != null) { for (Ref ref : refs.values()) { ObjectId objectId = ref.getObjectId(); + if (objectId == null) { + // skip unborn branch + continue; + } // If the object was already requested, skip it. if (wantAll.isEmpty()) { @@ -1632,12 +1636,13 @@ public class UploadPack { ref = db.peel(ref); ObjectId peeledId = ref.getPeeledObjectId(); - if (peeledId == null) + objectId = ref.getObjectId(); + if (peeledId == null || objectId == null) continue; - objectId = ref.getObjectId(); - if (pw.willInclude(peeledId) && !pw.willInclude(objectId)) + if (pw.willInclude(peeledId) && !pw.willInclude(objectId)) { pw.addObject(rw.parseAny(objectId)); + } } } -- 2.39.5