[JGIT PATCH] Read symbolic refs too when reading all refs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We failed to read symrefs when scanning for all refs. Single refs
were ok before too.

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---
 .../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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]