Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce2014-11-24 22:51:09 +0000
committerShawn Pearce2014-11-24 22:56:13 +0000
commit485b751b2fb74b5ea11582787d859c6cd59b65d2 (patch)
treea18c463f059087f269c739436575539cb7c2ec78
parent6c3999477ce3ab04e923935492534209e6ff8da4 (diff)
downloadjgit-485b751b2fb74b5ea11582787d859c6cd59b65d2.tar.gz
jgit-485b751b2fb74b5ea11582787d859c6cd59b65d2.tar.xz
jgit-485b751b2fb74b5ea11582787d859c6cd59b65d2.zip
Allow configurable ObjectCheckers in fetch
RecievePack already honors fsck settings for safeForWindows and safeForMacOS. Allow those same checks to be performed during fetch through a caller-configurable ObjectChecker. Default the fetch fsck options to match the current platform, as it can be reasonably assumed the repository will be accessed here. Change-Id: I3c0f411fad209c6bd8fb9c4acf5c55a6799a6a2a
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java35
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java33
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java2
5 files changed, 63 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
index e7e8af50a8..f907891bae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
@@ -757,7 +757,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection
try {
PackParser parser = ins.newPackParser(input);
parser.setAllowThin(thinPack);
- parser.setObjectChecking(transport.isCheckFetchedObjects());
+ parser.setObjectChecker(transport.getObjectChecker());
parser.setLockMessage(lockMessage);
packLock = parser.parse(monitor);
ins.flush();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
index 15ff9d3627..e3cfd22adb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
@@ -187,7 +187,7 @@ class BundleFetchConnection extends BaseFetchConnection {
try {
PackParser parser = ins.newPackParser(bin);
parser.setAllowThin(true);
- parser.setObjectChecking(transport.isCheckFetchedObjects());
+ parser.setObjectChecker(transport.getObjectChecker());
parser.setLockMessage(lockMessage);
packLock = parser.parse(NullProgressMonitor.INSTANCE);
ins.flush();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
index b00d607eee..1de91a57ef 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
@@ -48,8 +48,10 @@ import java.util.Map;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Config.SectionParser;
+import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.util.SystemReader;
/**
* The standard "transfer", "fetch", "receive", and "uploadpack" configuration
@@ -63,7 +65,10 @@ public class TransferConfig {
}
};
- private final boolean fetchFsck;
+ private final boolean checkReceivedObjects;
+ private final boolean allowLeadingZeroFileMode;
+ private final boolean safeForWindows;
+ private final boolean safeForMacOS;
private final boolean allowTipSha1InWant;
private final String[] hideRefs;
@@ -72,9 +77,17 @@ public class TransferConfig {
}
private TransferConfig(final Config rc) {
- fetchFsck = rc.getBoolean(
+ 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$
+ safeForWindows = checkReceivedObjects
+ && 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$
+ SystemReader.getInstance().isMacOS());
allowTipSha1InWant = rc.getBoolean(
"uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
@@ -83,9 +96,25 @@ public class TransferConfig {
/**
* @return strictly verify received objects?
+ * @deprecated use {@link #newObjectChecker()} instead.
*/
+ @Deprecated
public boolean isFsckObjects() {
- return fetchFsck;
+ return checkReceivedObjects;
+ }
+
+ /**
+ * @return checker to verify fetched objects, or null if checking is not
+ * enabled in the repository configuration.
+ * @since 3.6
+ */
+ public ObjectChecker newObjectChecker() {
+ if (!checkReceivedObjects)
+ return null;
+ return new ObjectChecker()
+ .setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
+ .setSafeForWindows(safeForWindows)
+ .setSafeForMacOS(safeForMacOS);
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
index 3ad1db2d49..218562254c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
@@ -75,6 +75,7 @@ import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
+import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -746,7 +747,7 @@ public abstract class Transport {
private boolean dryRun;
/** Should an incoming (fetch) transfer validate objects? */
- private boolean checkFetchedObjects;
+ private ObjectChecker objectChecker;
/** Should refs no longer on the source be pruned from the destination? */
private boolean removeDeletedRefs;
@@ -775,7 +776,7 @@ public abstract class Transport {
final TransferConfig tc = local.getConfig().get(TransferConfig.KEY);
this.local = local;
this.uri = uri;
- this.checkFetchedObjects = tc.isFsckObjects();
+ this.objectChecker = tc.newObjectChecker();
this.credentialsProvider = CredentialsProvider.getDefault();
}
@@ -787,7 +788,7 @@ public abstract class Transport {
protected Transport(final URIish uri) {
this.uri = uri;
this.local = null;
- this.checkFetchedObjects = true;
+ this.objectChecker = new ObjectChecker();
this.credentialsProvider = CredentialsProvider.getDefault();
}
@@ -873,16 +874,38 @@ public abstract class Transport {
* client side of the connection.
*/
public boolean isCheckFetchedObjects() {
- return checkFetchedObjects;
+ return getObjectChecker() != null;
}
/**
* @param check
* true to enable checking received objects; false to assume all
* received objects are valid.
+ * @see #setObjectChecker(ObjectChecker)
*/
public void setCheckFetchedObjects(final boolean check) {
- checkFetchedObjects = check;
+ if (check && objectChecker == null)
+ setObjectChecker(new ObjectChecker());
+ else if (!check && objectChecker != null)
+ setObjectChecker(null);
+ }
+
+ /**
+ * @return configured object checker for received objects, or null.
+ * @since 3.6
+ */
+ public ObjectChecker getObjectChecker() {
+ return objectChecker;
+ }
+
+ /**
+ * @param impl
+ * if non-null the object checking instance to verify each
+ * received object with; null to disable object checking.
+ * @since 3.6
+ */
+ public void setObjectChecker(ObjectChecker impl) {
+ objectChecker = impl;
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
index 565b457acb..6b7183b759 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
@@ -193,7 +193,7 @@ class WalkFetchConnection extends BaseFetchConnection {
WalkFetchConnection(final WalkTransport t, final WalkRemoteObjectDatabase w) {
Transport wt = (Transport)t;
local = wt.local;
- objCheck = wt.isCheckFetchedObjects() ? new ObjectChecker() : null;
+ objCheck = wt.getObjectChecker();
inserter = local.newObjectInserter();
reader = local.newObjectReader();

Back to the top