]> source.dussan.org Git - jgit.git/commitdiff
Skip unborn branches in UploadPack 12/114912/2
authorZhen Chen <czhen@google.com>
Wed, 3 Jan 2018 22:12:30 +0000 (14:12 -0800)
committerZhen Chen <czhen@google.com>
Wed, 3 Jan 2018 22:21:05 +0000 (14:21 -0800)
The ObjectId of an unborn branch is null, skip those in UploadPack.

Change-Id: I7cbf66b05dff98c4fe9f33e20a647ba6acf364b2
Signed-off-by: Zhen Chen <czhen@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index 8c448af904a3b0986450422e25b21dadc34b4f95..4c0bde1376ea766eca0fbaf554ac1f5c4afdc9e7 100644 (file)
@@ -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).
         */
index 822d47c7c22865de34adfc192b2f7a820432566e..5034c34d840b80ebc4a9f4ece236d21442752f42 100644 (file)
@@ -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));
+                                       }
                                }
                        }