From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, alex.blewitt@gmail.com,
Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [JGIT PATCH] Read symbolic refs too when reading all refs
Date: Tue, 12 May 2009 00:49:00 +0200 [thread overview]
Message-ID: <1242082140-740-1-git-send-email-robin.rosenberg@dewire.com> (raw)
We failed to read symrefs when scanning for all refs. Single refs
were ok before too.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../tst/org/spearce/jgit/lib/RefTest.java | 71 ++++++++++++++++++++
.../src/org/spearce/jgit/lib/RefDatabase.java | 13 ++--
2 files changed, 77 insertions(+), 7 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java
new file mode 100644
index 0000000..db79a8a
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2009, Robin Rosenberg
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.lib;
+
+import java.util.Map;
+
+/**
+ * Misc tests for refs. A lot of things are tested elsewhere so not having a
+ * test for a ref related method, does not mean it is untested.
+ */
+public class RefTest extends RepositoryTestCase {
+
+ public void testReadAllIncludingSymrefs() throws Exception {
+ ObjectId masterId = db.resolve("refs/heads/master");
+ RefUpdate updateRef = db.updateRef("refs/remotes/origin/master");
+ updateRef.setNewObjectId(masterId);
+ updateRef.setForceUpdate(true);
+ updateRef.update();
+ db
+ .writeSymref("refs/remotes/origin/HEAD",
+ "refs/remotes/origin/master");
+
+ ObjectId r = db.resolve("refs/remotes/origin/HEAD");
+ assertEquals(masterId, r);
+
+ Map<String, Ref> allRefs = db.getAllRefs();
+ Ref refHEAD = allRefs.get("refs/remotes/origin/HEAD");
+ assertEquals(masterId, refHEAD.getObjectId());
+ assertTrue(refHEAD.isPeeled());
+ assertNull(refHEAD.getPeeledObjectId());
+
+ Ref refmaster = allRefs.get("refs/remotes/origin/master");
+ assertEquals(masterId, refmaster.getObjectId());
+ assertFalse(refmaster.isPeeled());
+ assertNull(refmaster.getPeeledObjectId());
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
index 87f26bf..e364b15 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -265,23 +265,22 @@ private synchronized void readOneLooseRef(final Map<String, Ref> avail,
final byte[] str = new byte[Constants.OBJECT_ID_LENGTH * 2];
NB.readFully(in, str, 0, str.length);
id = ObjectId.fromString(str, 0);
+ ref = new Ref(Ref.Storage.LOOSE, origName, refName, id, null, false); // unpeeled
} catch (EOFException tooShortToBeRef) {
// Its below the minimum length needed. It could
// be a symbolic reference.
//
- return;
+ ref = readRefBasic(refName, refName, 0);
} catch (IllegalArgumentException notRef) {
// It is not a well-formed ObjectId. It may be
// a symbolic reference ("ref: ").
//
- return;
+ ref = readRefBasic(refName, refName, 0);
}
- ref = new Ref(Ref.Storage.LOOSE, origName, refName, id, null, false); // unpeeled
-
- looseRefs.put(ref.getName(), ref);
- looseRefsMTime.put(ref.getName(), ent.lastModified());
- avail.put(ref.getName(), ref);
+ looseRefs.put(ref.getOrigName(), ref);
+ looseRefsMTime.put(ref.getOrigName(), ent.lastModified());
+ avail.put(ref.getOrigName(), ref);
} finally {
in.close();
}
--
1.6.3.dirty
next reply other threads:[~2009-05-11 22:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-11 22:49 Robin Rosenberg [this message]
2009-05-12 2:22 ` [JGIT PATCH] Read symbolic refs too when reading all refs Shawn O. Pearce
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=1242082140-740-1-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=alex.blewitt@gmail.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/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).