Browse Source

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
stable-3.6
Shawn Pearce 10 years ago
parent
commit
485b751b2f
  1. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
  3. 35
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
  4. 33
      org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
  5. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

2
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();

2
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();

35
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);
}
/**

33
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;
}
/**

2
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();

Loading…
Cancel
Save