git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org, Marek Zawirski <marek.zawirski@gmail.com>,
	Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 2/9] Cached modification times for symbolic refs too
Date: Fri, 11 Jul 2008 00:40:44 +0200	[thread overview]
Message-ID: <1215729651-26781-3-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1215729651-26781-2-git-send-email-robin.rosenberg@dewire.com>

We want to detect changes to symbolic refs like HEAD. When HEAD is
redirected to another branch, that's a change even if if the branch
head itself did not change.

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

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 4be33b8..17a74e5 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -71,7 +71,8 @@ class RefDatabase {
 
 	private final File refsDir;
 
-	private Map<String, CachedRef> looseRefs;
+	private Map<String, Ref> looseRefs;
+	private Map<String, Long> looseRefsMTime;
 
 	private final File packedRefsFile;
 
@@ -94,7 +95,8 @@ class RefDatabase {
 	}
 
 	void clearCache() {
-		looseRefs = new HashMap<String, CachedRef>();
+		looseRefs = new HashMap<String, Ref>();
+		looseRefsMTime = new HashMap<String, Long>();
 		packedRefs = new HashMap<String, Ref>();
 		packedRefsLastModified = 0;
 		packedRefsLength = 0;
@@ -135,7 +137,8 @@ class RefDatabase {
 	}
 
 	void stored(final String name, final ObjectId id, final long time) {
-		looseRefs.put(name, new CachedRef(Ref.Storage.LOOSE, name, id, time));
+		looseRefs.put(name, new Ref(Ref.Storage.LOOSE, name, id));
+		looseRefsMTime.put(name, time);
 		setModified();
 		db.fireRefsMaybeChanged();
 	}
@@ -203,7 +206,11 @@ class RefDatabase {
 		final HashMap<String, Ref> avail = new HashMap<String, Ref>();
 		readPackedRefs(avail);
 		readLooseRefs(avail, REFS_SLASH, refsDir);
-		readOneLooseRef(avail, Constants.HEAD, new File(gitDir, Constants.HEAD));
+		try {
+			avail.put(Constants.HEAD, readRefBasic(Constants.HEAD, 0));
+		} catch (IOException e) {
+			// ignore here
+		}
 		db.fireRefsMaybeChanged();
 		return avail;
 	}
@@ -231,13 +238,15 @@ class RefDatabase {
 			final String refName, final File ent) {
 		// Unchanged and cached? Don't read it again.
 		//
-		CachedRef ref = looseRefs.get(refName);
+		Ref ref = looseRefs.get(refName);
 		if (ref != null) {
-			if (ref.lastModified == ent.lastModified()) {
+			Long cachedlastModified = looseRefsMTime.get(refName);
+			if (cachedlastModified != null && cachedlastModified == ent.lastModified()) {
 				avail.put(ref.getName(), ref);
 				return;
 			}
 			looseRefs.remove(refName);
+			looseRefsMTime.remove(refName);
 		}
 
 		// Recurse into the directory.
@@ -269,9 +278,9 @@ class RefDatabase {
 					return;
 				}
 
-				ref = new CachedRef(Ref.Storage.LOOSE, refName, id, ent
-						.lastModified());
+				ref = new Ref(Ref.Storage.LOOSE, refName, id);
 				looseRefs.put(ref.getName(), ref);
+				looseRefsMTime.put(ref.getName(), ent.lastModified());
 				avail.put(ref.getName(), ref);
 			} finally {
 				in.close();
@@ -297,13 +306,15 @@ class RefDatabase {
 		// Prefer loose ref to packed ref as the loose
 		// file can be more up-to-date than a packed one.
 		//
-		CachedRef ref = looseRefs.get(name);
+		Ref ref = looseRefs.get(name);
 		final File loose = fileForRef(name);
 		final long mtime = loose.lastModified();
 		if (ref != null) {
-			if (ref.lastModified == mtime)
+			Long cachedlastModified = looseRefsMTime.get(name);
+			if (cachedlastModified != null && cachedlastModified == mtime)
 				return ref;
 			looseRefs.remove(name);
+			looseRefsMTime.remove(name);
 		}
 
 		if (mtime == 0) {
@@ -331,6 +342,10 @@ class RefDatabase {
 
 			final String target = line.substring("ref: ".length());
 			final Ref r = readRefBasic(target, depth + 1);
+			Long cachedMtime = looseRefsMTime.get(name);
+			if (cachedMtime != null && cachedMtime != mtime)
+				setModified();
+			looseRefsMTime.put(name, mtime);
 			return r != null ? r : new Ref(Ref.Storage.LOOSE, target, null);
 		}
 
@@ -343,8 +358,9 @@ class RefDatabase {
 			throw new IOException("Not a ref: " + name + ": " + line);
 		}
 
-		ref = new CachedRef(Ref.Storage.LOOSE, name, id, mtime);
+		ref = new Ref(Ref.Storage.LOOSE, name, id);
 		looseRefs.put(name, ref);
+		looseRefsMTime.put(name, mtime);
 		return ref;
 	}
 
@@ -421,14 +437,4 @@ class RefDatabase {
 				fileLocation), CHAR_ENC));
 	}
 
-	private static class CachedRef extends Ref {
-		final long lastModified;
-
-		CachedRef(final Storage st, final String refName, final ObjectId id,
-				final long mtime) {
-			super(st, refName, id);
-			lastModified = mtime;
-		}
-	}
-
 }
-- 
1.5.6.2.220.g44701

  reply	other threads:[~2008-07-10 22:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10 22:40 [EGIT PATCH 0/9] Repository change listeners Robin Rosenberg
2008-07-10 22:40 ` [EGIT PATCH 1/9] Create a listener structure for changes to refs and index Robin Rosenberg
2008-07-10 22:40   ` Robin Rosenberg [this message]
2008-07-10 22:40     ` [EGIT PATCH 3/9] Connect the history page to the refs update subscription mechanism Robin Rosenberg
2008-07-10 22:40       ` [EGIT PATCH 4/9] Add a method to listen to changes in any repository Robin Rosenberg
2008-07-10 22:40         ` [EGIT PATCH 5/9] Add a job to periodically scan for repository changes Robin Rosenberg
2008-07-10 22:40           ` [EGIT PATCH 6/9] Change GitHistoryPage to listen on any repository Robin Rosenberg
2008-07-10 22:40             ` [EGIT PATCH 7/9] Add a job to refresh projects when the index changes Robin Rosenberg
2008-07-10 22:40               ` [EGIT PATCH 8/9] Make git dectected changes depend on the automatic refresh setting Robin Rosenberg
2008-07-10 22:40                 ` [EGIT PATCH 9/9] Attach the resource decorator to the repository change event mechanism Robin Rosenberg
2008-07-11  4:33               ` [EGIT PATCH 7/9] Add a job to refresh projects when the index changes Shawn O. Pearce
2008-07-11  9:32                 ` [PATCH 7/7] " Robin Rosenberg
2008-07-11  4:28         ` [EGIT PATCH 4/9] Add a method to listen to changes in any repository Shawn O. Pearce
2008-07-11  9:48           ` [PATCH 4/4] " Robin Rosenberg
2008-07-11 12:24             ` jgit (was: [PATCH 4/4] Add a method...) Andreas Ericsson
2008-07-11 12:24               ` Robin Rosenberg
2008-07-11  4:22   ` [EGIT PATCH 1/9] Create a listener structure for changes to refs and index Shawn O. Pearce
2008-07-11  9:27     ` [PATCH] " Robin Rosenberg
2008-07-11  5:26 ` [EGIT PATCH 0/9] Repository change listeners 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=1215729651-26781-3-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=marek.zawirski@gmail.com \
    --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).