]> source.dussan.org Git - jgit.git/commitdiff
Unify fetch and receive ObjectChecker setup 66/63366/2
authorShawn Pearce <spearce@spearce.org>
Wed, 30 Dec 2015 00:53:56 +0000 (16:53 -0800)
committerShawn Pearce <spearce@spearce.org>
Wed, 30 Dec 2015 00:55:41 +0000 (16:55 -0800)
This avoids duplication of code between receive-pack and fetch-pack paths.
Separate methods are still required to check use of receive.fsckobjects vs.
fetch.fsckobjects, both of which default to transfer.fsckobjects.

Change-Id: I41193e093e981a79fc2f63914e273aaa44b82162

org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java

index c224d8eeb89fa27e791015f79812ee98e8721a58..728643e9256edf83b1cf0a65bfcb375ae96d8b93 100644 (file)
@@ -293,18 +293,20 @@ public abstract class BaseReceivePack {
                db = into;
                walk = new RevWalk(db);
 
-               final ReceiveConfig cfg = db.getConfig().get(ReceiveConfig.KEY);
-               objectChecker = cfg.newObjectChecker();
-               allowCreates = cfg.allowCreates;
+               TransferConfig tc = db.getConfig().get(TransferConfig.KEY);
+               objectChecker = tc.newReceiveObjectChecker();
+
+               ReceiveConfig rc = db.getConfig().get(ReceiveConfig.KEY);
+               allowCreates = rc.allowCreates;
                allowAnyDeletes = true;
-               allowBranchDeletes = cfg.allowDeletes;
-               allowNonFastForwards = cfg.allowNonFastForwards;
-               allowOfsDelta = cfg.allowOfsDelta;
+               allowBranchDeletes = rc.allowDeletes;
+               allowNonFastForwards = rc.allowNonFastForwards;
+               allowOfsDelta = rc.allowOfsDelta;
                advertiseRefsHook = AdvertiseRefsHook.DEFAULT;
                refFilter = RefFilter.DEFAULT;
                advertisedHaves = new HashSet<ObjectId>();
                clientShallowCommits = new HashSet<ObjectId>();
-               signedPushConfig = cfg.signedPush;
+               signedPushConfig = rc.signedPush;
        }
 
        /** Configuration for receive operations. */
@@ -315,32 +317,13 @@ public abstract class BaseReceivePack {
                        }
                };
 
-               final boolean checkReceivedObjects;
-               final boolean allowLeadingZeroFileMode;
-               final boolean allowInvalidPersonIdent;
-               final boolean safeForWindows;
-               final boolean safeForMacOS;
-
                final boolean allowCreates;
                final boolean allowDeletes;
                final boolean allowNonFastForwards;
                final boolean allowOfsDelta;
-
                final SignedPushConfig signedPush;
 
                ReceiveConfig(final Config config) {
-                       checkReceivedObjects = config.getBoolean(
-                                       "receive", "fsckobjects", //$NON-NLS-1$ //$NON-NLS-2$
-                                       config.getBoolean("transfer", "fsckobjects", false)); //$NON-NLS-1$ //$NON-NLS-2$
-                       allowLeadingZeroFileMode = checkReceivedObjects
-                                       && config.getBoolean("fsck", "allowLeadingZeroFileMode", false); //$NON-NLS-1$ //$NON-NLS-2$
-                       allowInvalidPersonIdent = checkReceivedObjects
-                                       && config.getBoolean("fsck", "allowInvalidPersonIdent", false); //$NON-NLS-1$ //$NON-NLS-2$
-                       safeForWindows = checkReceivedObjects
-                                       && config.getBoolean("fsck", "safeForWindows", false); //$NON-NLS-1$ //$NON-NLS-2$
-                       safeForMacOS = checkReceivedObjects
-                                       && config.getBoolean("fsck", "safeForMacOS", false); //$NON-NLS-1$ //$NON-NLS-2$
-
                        allowCreates = true;
                        allowDeletes = !config.getBoolean("receive", "denydeletes", false); //$NON-NLS-1$ //$NON-NLS-2$
                        allowNonFastForwards = !config.getBoolean("receive", //$NON-NLS-1$
@@ -349,16 +332,6 @@ public abstract class BaseReceivePack {
                                        true);
                        signedPush = SignedPushConfig.KEY.parse(config);
                }
-
-               ObjectChecker newObjectChecker() {
-                       if (!checkReceivedObjects)
-                               return null;
-                       return new ObjectChecker()
-                               .setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
-                               .setAllowInvalidPersonIdent(allowInvalidPersonIdent)
-                               .setSafeForWindows(safeForWindows)
-                               .setSafeForMacOS(safeForMacOS);
-               }
        }
 
        /**
index f0c513427afeac89164c413ee89e9790ba73d5a9..f9b74c84e5e2ad2a9309c281adf2c6ba65c3f8cd 100644 (file)
@@ -46,6 +46,7 @@ package org.eclipse.jgit.transport;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.eclipse.jgit.annotations.Nullable;
 import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.lib.Config.SectionParser;
 import org.eclipse.jgit.lib.ObjectChecker;
@@ -65,7 +66,8 @@ public class TransferConfig {
                }
        };
 
-       private final boolean checkReceivedObjects;
+       private final boolean fetchFsck;
+       private final boolean receiveFsck;
        private final boolean allowLeadingZeroFileMode;
        private final boolean allowInvalidPersonIdent;
        private final boolean safeForWindows;
@@ -79,18 +81,14 @@ public class TransferConfig {
        }
 
        TransferConfig(final Config rc) {
-               checkReceivedObjects = rc.getBoolean(
-                               "fetch", "fsckobjects", //$NON-NLS-1$ //$NON-NLS-2$
-                               rc.getBoolean("transfer", "fsckobjects", false)); //$NON-NLS-1$ //$NON-NLS-2$
-               allowLeadingZeroFileMode = checkReceivedObjects
-                               && rc.getBoolean("fsck", "allowLeadingZeroFileMode", false); //$NON-NLS-1$ //$NON-NLS-2$
-               allowInvalidPersonIdent = checkReceivedObjects
-                               && rc.getBoolean("fsck", "allowInvalidPersonIdent", false); //$NON-NLS-1$ //$NON-NLS-2$
-               safeForWindows = checkReceivedObjects
-                               && rc.getBoolean("fsck", "safeForWindows", //$NON-NLS-1$ //$NON-NLS-2$
+               boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); //$NON-NLS-1$ //$NON-NLS-2$
+               fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); //$NON-NLS-1$ //$NON-NLS-2$
+               receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); //$NON-NLS-1$ //$NON-NLS-2$
+               allowLeadingZeroFileMode = rc.getBoolean("fsck", "allowLeadingZeroFileMode", false); //$NON-NLS-1$ //$NON-NLS-2$
+               allowInvalidPersonIdent = rc.getBoolean("fsck", "allowInvalidPersonIdent", false); //$NON-NLS-1$ //$NON-NLS-2$
+               safeForWindows = rc.getBoolean("fsck", "safeForWindows", //$NON-NLS-1$ //$NON-NLS-2$
                                                SystemReader.getInstance().isWindows());
-               safeForMacOS = checkReceivedObjects
-                               && rc.getBoolean("fsck", "safeForMacOS", //$NON-NLS-1$ //$NON-NLS-2$
+               safeForMacOS = rc.getBoolean("fsck", "safeForMacOS", //$NON-NLS-1$ //$NON-NLS-2$
                                                SystemReader.getInstance().isMacOS());
 
                allowTipSha1InWant = rc.getBoolean(
@@ -105,9 +103,25 @@ public class TransferConfig {
         *         enabled in the repository configuration.
         * @since 3.6
         */
+       @Nullable
        public ObjectChecker newObjectChecker() {
-               if (!checkReceivedObjects)
+               return newObjectChecker(fetchFsck);
+       }
+
+       /**
+        * @return checker to verify objects pushed into this repository, or null if
+        *         checking is not enabled in the repository configuration.
+        * @since 4.2
+        */
+       @Nullable
+       public ObjectChecker newReceiveObjectChecker() {
+               return newObjectChecker(receiveFsck);
+       }
+
+       private ObjectChecker newObjectChecker(boolean check) {
+               if (!check) {
                        return null;
+               }
                return new ObjectChecker()
                        .setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
                        .setAllowInvalidPersonIdent(allowInvalidPersonIdent)