git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH] Don't NPE in server code if a symbolic reference is incomplete
Date: Wed, 17 Jun 2009 19:12:00 -0700	[thread overview]
Message-ID: <1245291120-16688-1-git-send-email-spearce@spearce.org> (raw)

If a symbolic reference's target doesn't exist, then we still get the
Ref instance back from the database but its ObjectId is null.  Instead
of trying to advertise null as a SHA-1 to the client, skip it and say
nothing about that ref.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../org/spearce/jgit/transport/ReceivePack.java    |   45 +++++++++++---------
 .../src/org/spearce/jgit/transport/UploadPack.java |    2 +
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
index abaf876..c92a903 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
@@ -461,34 +461,39 @@ private void sendAdvertisedRefs() throws IOException {
 		final StringBuilder m = new StringBuilder(100);
 		final char[] idtmp = new char[2 * Constants.OBJECT_ID_LENGTH];
 		final Iterator<Ref> i = RefComparator.sort(refs.values()).iterator();
-		{
-			if (i.hasNext()) {
-				final Ref r = i.next();
-				format(m, idtmp, r.getObjectId(), r.getOrigName());
-			} else {
-				format(m, idtmp, ObjectId.zeroId(), "capabilities^{}");
-			}
-			m.append('\0');
-			m.append(' ');
-			m.append(CAPABILITY_DELETE_REFS);
-			m.append(' ');
-			m.append(CAPABILITY_REPORT_STATUS);
-			if (allowOfsDelta) {
-				m.append(' ');
-				m.append(CAPABILITY_OFS_DELTA);
-			}
-			m.append(' ');
-			writeAdvertisedRef(m);
-		}
-
+		boolean first = true;
 		while (i.hasNext()) {
 			final Ref r = i.next();
+			if (r.getObjectId() == null)
+				continue;
 			format(m, idtmp, r.getObjectId(), r.getOrigName());
+			if (first) {
+				first = false;
+				advertiseCapabilities(m);
+			}
+			writeAdvertisedRef(m);
+		}
+		if (first) {
+			format(m, idtmp, ObjectId.zeroId(), "capabilities^{}");
+			advertiseCapabilities(m);
 			writeAdvertisedRef(m);
 		}
 		pckOut.end();
 	}
 
+	private void advertiseCapabilities(final StringBuilder m) {
+		m.append('\0');
+		m.append(' ');
+		m.append(CAPABILITY_DELETE_REFS);
+		m.append(' ');
+		m.append(CAPABILITY_REPORT_STATUS);
+		if (allowOfsDelta) {
+			m.append(' ');
+			m.append(CAPABILITY_OFS_DELTA);
+		}
+		m.append(' ');
+	}
+
 	private void format(final StringBuilder m, final char[] idtmp,
 			final ObjectId id, final String name) {
 		m.setLength(0);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
index 159bd10..7d17b2d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
@@ -235,6 +235,8 @@ private void sendAdvertisedRefs() throws IOException {
 		}
 		while (i.hasNext()) {
 			final Ref r = i.next();
+			if (r.getObjectId() == null)
+				continue;
 			final RevObject o = safeParseAny(r.getObjectId());
 			if (o != null) {
 				advertise(m, idtmp, o, r.getOrigName());
-- 
1.6.3.2.406.gd6a466

                 reply	other threads:[~2009-06-18  2:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1245291120-16688-1-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).