From d300609495fc52f19535a8d541ec3a848aad3f5d Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 12 Mar 2014 16:36:07 -0700 Subject: [PATCH] Allow ReceivePack callers to configure their own ObjectChecker PackParser permits supplying a specific ObjectChecker instance. Allow this to be passed through ReceivePack, giving the caller more flexibility to configure the implementation. Change-Id: I9440dd25588008626222f33bfd697f57c05b439e --- .../jgit/transport/BaseReceivePack.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java index 68b3262a0b..483ac55fa9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java @@ -74,6 +74,7 @@ import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; +import org.eclipse.jgit.lib.ObjectChecker; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdSubclassMap; import org.eclipse.jgit.lib.ObjectInserter; @@ -160,7 +161,7 @@ public abstract class BaseReceivePack { private boolean expectDataAfterPackFooter; /** Should an incoming transfer validate objects? */ - private boolean checkReceivedObjects; + private ObjectChecker objectChecker; /** Should an incoming transfer permit create requests? */ private boolean allowCreates; @@ -254,7 +255,7 @@ public abstract class BaseReceivePack { walk = new RevWalk(db); final ReceiveConfig cfg = db.getConfig().get(ReceiveConfig.KEY); - checkReceivedObjects = cfg.checkReceivedObjects; + objectChecker = cfg.checkReceivedObjects ? new ObjectChecker() : null; allowCreates = cfg.allowCreates; allowDeletes = cfg.allowDeletes; allowNonFastForwards = cfg.allowNonFastForwards; @@ -481,16 +482,29 @@ public abstract class BaseReceivePack { * of the connection. */ public boolean isCheckReceivedObjects() { - return checkReceivedObjects; + return objectChecker != null; } /** * @param check * true to enable checking received objects; false to assume all * received objects are valid. + * @see #setObjectChecker(ObjectChecker) */ public void setCheckReceivedObjects(final boolean check) { - checkReceivedObjects = check; + if (check && objectChecker == null) + setObjectChecker(new ObjectChecker()); + else if (!check && objectChecker != null) + setObjectChecker(null); + } + + /** + * @param impl if non-null the object checking instance to verify each + * received object with; null to disable object checking. + * @since 3.4 + */ + public void setObjectChecker(ObjectChecker impl) { + objectChecker = impl; } /** @return true if the client can request refs to be created. */ @@ -983,7 +997,7 @@ public abstract class BaseReceivePack { parser.setCheckEofAfterPackFooter(!biDirectionalPipe && !isExpectDataAfterPackFooter()); parser.setExpectDataAfterPackFooter(isExpectDataAfterPackFooter()); - parser.setObjectChecking(isCheckReceivedObjects()); + parser.setObjectChecker(objectChecker); parser.setLockMessage(lockMsg); parser.setMaxObjectSizeLimit(maxObjectSizeLimit); packLock = parser.parse(receiving, resolving); -- 2.39.5