Git development
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, stefan.lay@sap.com,
	Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [JGIT PATCH] Fix update of the refs cache when updating via a symbolic ref
Date: Sat, 15 Aug 2009 20:43:39 +0200	[thread overview]
Message-ID: <1250361819-20031-1-git-send-email-robin.rosenberg@dewire.com> (raw)

The branch pointed to by HEAD was lost in the refs cache, i.e. the
HEAD Ref was inserted into the cache with the the peeled ref as
key instead of HEAD. Then when asking for the peeled ref name HEAD
was returned.

This only happened when the ref name was a loose ref and not in
packed-refs at all, hence we test with an unborn branch, though an
existing loose (only) ref would show the same problem.

See http://bugs.eclipse.org/285991

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../tst/org/spearce/jgit/lib/RefUpdateTest.java    |   61 ++++++++++++++++++++
 .../src/org/spearce/jgit/lib/RefDatabase.java      |    2 +-
 2 files changed, 62 insertions(+), 1 deletions(-)


I'm not posting the patch to bugzilla since this is bug in JGit and not EGit.

-- robin

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java
index 8df8c2a..655e54e 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java
@@ -298,6 +298,67 @@ public void testUpdateRefNoChange() throws IOException {
 	}
 
 	/**
+	 * Test case originating from 
+	 * <a href="http://bugs.eclipse.org/285991">bug 285991</a>
+	 *
+	 * Make sure the in memory cache is updated properly after
+	 * update of symref. This one did not fail because the
+	 * ref was packed due to implementation issues.
+	 *
+	 * @throws Exception
+	 */
+	public void testRefsCacheAfterUpdate() throws Exception {
+		// Do not use the defalt repo for this case.
+		Map<String, Ref> allRefs = db.getAllRefs();
+		ObjectId oldValue = db.resolve("HEAD");
+		ObjectId newValue = db.resolve("HEAD^");
+		// first make HEAD refer to loose ref
+		RefUpdate updateRef = db.updateRef(Constants.HEAD);
+		updateRef.setForceUpdate(true);
+		updateRef.setNewObjectId(newValue);
+		Result update = updateRef.update();
+		assertEquals(Result.FORCED, update);
+		
+		// now update that ref
+		updateRef = db.updateRef(Constants.HEAD);
+		updateRef.setForceUpdate(true);
+		updateRef.setNewObjectId(oldValue);
+		update = updateRef.update();
+		assertEquals(Result.FAST_FORWARD, update);
+		allRefs = db.getAllRefs();
+		assertEquals("refs/heads/master", allRefs.get("refs/heads/master").getName());
+		assertEquals("refs/heads/master", allRefs.get("refs/heads/master").getOrigName());
+		assertEquals("refs/heads/master", allRefs.get("HEAD").getName());
+		assertEquals("HEAD", allRefs.get("HEAD").getOrigName());
+	}
+	
+	/**
+	 * Test case originating from 
+	 * <a href="http://bugs.eclipse.org/285991">bug 285991</a>
+	 *
+	 * Make sure the in memory cache is updated properly after
+	 * update of symref.
+	 *
+	 * @throws Exception
+	 */
+	public void testRefsCacheAfterUpdateLoosOnly() throws Exception {
+		// Do not use the defalt repo for this case.
+		Map<String, Ref> allRefs = db.getAllRefs();
+		ObjectId oldValue = db.resolve("HEAD");
+		db.writeSymref(Constants.HEAD, "refs/heads/newref");
+		RefUpdate updateRef = db.updateRef(Constants.HEAD);
+		updateRef.setForceUpdate(true);
+		updateRef.setNewObjectId(oldValue);
+		Result update = updateRef.update();
+		assertEquals(Result.NEW, update);
+		allRefs = db.getAllRefs();
+		assertEquals("refs/heads/newref", allRefs.get("HEAD").getName());
+		assertEquals("HEAD", allRefs.get("HEAD").getOrigName());
+		assertEquals("refs/heads/newref", allRefs.get("refs/heads/newref").getName());
+		assertEquals("refs/heads/newref", allRefs.get("refs/heads/newref").getOrigName());
+	}
+
+	/**
 	 * Try modify a ref, but get wrong expected old value
 	 *
 	 * @throws IOException
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 f7751c4..ba4b654 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -140,7 +140,7 @@ RefUpdate newUpdate(final String name) throws IOException {
 
 	void stored(final String origName, final String name, final ObjectId id, final long time) {
 		synchronized (this) {
-			looseRefs.put(name, new Ref(Ref.Storage.LOOSE, origName, name, id));
+			looseRefs.put(name, new Ref(Ref.Storage.LOOSE, name, name, id));
 			looseRefsMTime.put(name, time);
 			setModified();
 		}
-- 
1.6.4.115.gc0eb0

                 reply	other threads:[~2009-08-15 18:45 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=1250361819-20031-1-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    --cc=stefan.lay@sap.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