[JGIT PATCH 18/19] Use Config SectionParser cache to store daemon enable states

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

 



Rather than looking up the boolean each time we start a new connection
in a repository we now cache it in the configuration cache under a key
that is unique to the daemon service.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../org/spearce/jgit/transport/DaemonService.java  |   30 ++++++++++++++++----
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java
index 817aeee..b7198c7 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java
@@ -39,13 +39,15 @@
 
 import java.io.IOException;
 
+import org.spearce.jgit.lib.Config;
 import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.lib.Config.SectionParser;
 
 /** A service exposed by {@link Daemon} over anonymous <code>git://</code>. */
 public abstract class DaemonService {
 	private final String command;
 
-	private final String config;
+	private final SectionParser<ServiceConfig> configKey;
 
 	private boolean enabled;
 
@@ -53,10 +55,23 @@
 
 	DaemonService(final String cmdName, final String cfgName) {
 		command = cmdName.startsWith("git-") ? cmdName : "git-" + cmdName;
-		config = cfgName;
+		configKey = new SectionParser<ServiceConfig>() {
+			public ServiceConfig parse(final Config cfg) {
+				return new ServiceConfig(DaemonService.this, cfg, cfgName);
+			}
+		};
 		overridable = true;
 	}
 
+	private static class ServiceConfig {
+		final boolean enabled;
+
+		ServiceConfig(final DaemonService service, final Config cfg,
+				final String name) {
+			enabled = cfg.getBoolean("daemon", name, service.isEnabled());
+		}
+	}
+
 	/** @return is this service enabled for invocation? */
 	public boolean isEnabled() {
 		return enabled;
@@ -109,16 +124,19 @@ void execute(final DaemonClient client, final String commandLine)
 		if (db == null)
 			return;
 		try {
-			boolean on = isEnabled();
-			if (isOverridable())
-				on = db.getConfig().getBoolean("daemon", config, on);
-			if (on)
+			if (isEnabledFor(db))
 				execute(client, db);
 		} finally {
 			db.close();
 		}
 	}
 
+	private boolean isEnabledFor(final Repository db) {
+		if (isOverridable())
+			return db.getConfig().get(configKey).enabled;
+		return isEnabled();
+	}
+
 	abstract void execute(DaemonClient client, Repository db)
 			throws IOException;
 }
-- 
1.6.4.rc2.216.g769fa

--
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]