[JGIT PATCH 19/19] Use Config cache for fetch and receive configuration parsing

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

 



Rather than parsing the fields on each transfer we now parse the
fields once and cache them in the Config object, under a unique
section key for the fetch or receive direction.  This permits the
keys to be scanned only once, rather than per-request.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../jgit/transport/BasePackFetchConnection.java    |   21 ++++++++-
 .../org/spearce/jgit/transport/ReceivePack.java    |   45 ++++++++++++++++----
 2 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackFetchConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackFetchConnection.java
index 7163e02..dea6181 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackFetchConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackFetchConnection.java
@@ -46,12 +46,13 @@
 
 import org.spearce.jgit.errors.TransportException;
 import org.spearce.jgit.lib.AnyObjectId;
+import org.spearce.jgit.lib.Config;
 import org.spearce.jgit.lib.MutableObjectId;
 import org.spearce.jgit.lib.ObjectId;
 import org.spearce.jgit.lib.PackLock;
 import org.spearce.jgit.lib.ProgressMonitor;
 import org.spearce.jgit.lib.Ref;
-import org.spearce.jgit.lib.RepositoryConfig;
+import org.spearce.jgit.lib.Config.SectionParser;
 import org.spearce.jgit.revwalk.RevCommit;
 import org.spearce.jgit.revwalk.RevCommitList;
 import org.spearce.jgit.revwalk.RevFlag;
@@ -146,10 +147,10 @@
 	BasePackFetchConnection(final PackTransport packTransport) {
 		super(packTransport);
 
-		final RepositoryConfig cfg = local.getConfig();
+		final FetchConfig cfg = local.getConfig().get(FetchConfig.KEY);
 		includeTags = transport.getTagOpt() != TagOpt.NO_TAGS;
 		thinPack = transport.isFetchThin();
-		allowOfsDelta = cfg.getBoolean("repack", "usedeltabaseoffset", true);
+		allowOfsDelta = cfg.allowOfsDelta;
 
 		walk = new RevWalk(local);
 		reachableCommits = new RevCommitList<RevCommit>();
@@ -162,6 +163,20 @@
 		walk.carry(ADVERTISED);
 	}
 
+	private static class FetchConfig {
+		static final SectionParser<FetchConfig> KEY = new SectionParser<FetchConfig>() {
+			public FetchConfig parse(final Config cfg) {
+				return new FetchConfig(cfg);
+			}
+		};
+
+		final boolean allowOfsDelta;
+
+		FetchConfig(final Config c) {
+			allowOfsDelta = c.getBoolean("repack", "usedeltabaseoffset", true);
+		}
+	}
+
 	public final void fetch(final ProgressMonitor monitor,
 			final Collection<Ref> want, final Set<ObjectId> have)
 			throws TransportException {
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
index 38f0b5c..ca4a7ec 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
@@ -54,6 +54,7 @@
 
 import org.spearce.jgit.errors.MissingObjectException;
 import org.spearce.jgit.errors.PackProtocolException;
+import org.spearce.jgit.lib.Config;
 import org.spearce.jgit.lib.Constants;
 import org.spearce.jgit.lib.NullProgressMonitor;
 import org.spearce.jgit.lib.ObjectId;
@@ -62,7 +63,7 @@
 import org.spearce.jgit.lib.Ref;
 import org.spearce.jgit.lib.RefUpdate;
 import org.spearce.jgit.lib.Repository;
-import org.spearce.jgit.lib.RepositoryConfig;
+import org.spearce.jgit.lib.Config.SectionParser;
 import org.spearce.jgit.revwalk.ObjectWalk;
 import org.spearce.jgit.revwalk.RevCommit;
 import org.spearce.jgit.revwalk.RevFlag;
@@ -158,17 +159,45 @@ public ReceivePack(final Repository into) {
 		db = into;
 		walk = new RevWalk(db);
 
-		final RepositoryConfig cfg = db.getConfig();
-		checkReceivedObjects = cfg.getBoolean("receive", "fsckobjects", false);
-		allowCreates = true;
-		allowDeletes = !cfg.getBoolean("receive", "denydeletes", false);
-		allowNonFastForwards = !cfg.getBoolean("receive",
-				"denynonfastforwards", false);
-		allowOfsDelta = cfg.getBoolean("repack", "usedeltabaseoffset", true);
+		final ReceiveConfig cfg = db.getConfig().get(ReceiveConfig.KEY);
+		checkReceivedObjects = cfg.checkReceivedObjects;
+		allowCreates = cfg.allowCreates;
+		allowDeletes = cfg.allowDeletes;
+		allowNonFastForwards = cfg.allowNonFastForwards;
+		allowOfsDelta = cfg.allowOfsDelta;
 		preReceive = PreReceiveHook.NULL;
 		postReceive = PostReceiveHook.NULL;
 	}
 
+	private static class ReceiveConfig {
+		static final SectionParser<ReceiveConfig> KEY = new SectionParser<ReceiveConfig>() {
+			public ReceiveConfig parse(final Config cfg) {
+				return new ReceiveConfig(cfg);
+			}
+		};
+
+		final boolean checkReceivedObjects;
+
+		final boolean allowCreates;
+
+		final boolean allowDeletes;
+
+		final boolean allowNonFastForwards;
+
+		final boolean allowOfsDelta;
+
+		ReceiveConfig(final Config config) {
+			checkReceivedObjects = config.getBoolean("receive", "fsckobjects",
+					false);
+			allowCreates = true;
+			allowDeletes = !config.getBoolean("receive", "denydeletes", false);
+			allowNonFastForwards = !config.getBoolean("receive",
+					"denynonfastforwards", false);
+			allowOfsDelta = config.getBoolean("repack", "usedeltabaseoffset",
+					true);
+		}
+	}
+
 	/** @return the repository this receive completes into. */
 	public final Repository getRepository() {
 		return db;
-- 
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]