aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/transport
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2016-01-03 10:27:36 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2016-01-03 10:27:37 -0500
commit91a3f1747460e71ef310d9d989b3deea1226336a (patch)
treee589c9177a27e2597384c1046d1f5681fb3bef7a /org.eclipse.jgit/src/org/eclipse/jgit/transport
parent63bb0bcd4af3e70afe13173b4e3b9173fcb8eaea (diff)
parentac41920a430941b9385889d19e0fc2764ba23474 (diff)
downloadjgit-91a3f1747460e71ef310d9d989b3deea1226336a.tar.gz
jgit-91a3f1747460e71ef310d9d989b3deea1226336a.zip
Merge changes Idaed9310,I62bd7c0b
* changes: ObjectChecker: honor some git-core fsck.* options ObjectChecker: allow some objects to skip errors
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java97
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java7
3 files changed, 98 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
index 6e5fc9f009..b96fe885e1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
@@ -1049,8 +1049,11 @@ public abstract class PackParser {
final byte[] data) throws IOException {
if (objCheck != null) {
try {
- objCheck.check(type, data);
+ objCheck.check(id, type, data);
} catch (CorruptObjectException e) {
+ if (e.getErrorType() != null) {
+ throw e;
+ }
throw new CorruptObjectException(MessageFormat.format(
JGitText.get().invalidObject,
Constants.typeString(type),
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 f9b74c84e5..72c9c8b93e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
@@ -43,13 +43,20 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.util.StringUtils.equalsIgnoreCase;
+import static org.eclipse.jgit.util.StringUtils.toLowerCase;
+
+import java.io.File;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jgit.annotations.Nullable;
+import org.eclipse.jgit.internal.storage.file.LazyObjectIdSetFile;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Config.SectionParser;
import org.eclipse.jgit.lib.ObjectChecker;
+import org.eclipse.jgit.lib.ObjectIdSet;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.SystemReader;
@@ -59,6 +66,8 @@ import org.eclipse.jgit.util.SystemReader;
* parameters.
*/
public class TransferConfig {
+ private static final String FSCK = "fsck"; //$NON-NLS-1$
+
/** Key for {@link Config#get(SectionParser)}. */
public static final Config.SectionParser<TransferConfig> KEY = new SectionParser<TransferConfig>() {
public TransferConfig parse(final Config cfg) {
@@ -66,9 +75,14 @@ public class TransferConfig {
}
};
+ enum FsckMode {
+ ERROR, WARN, IGNORE;
+ }
+
private final boolean fetchFsck;
private final boolean receiveFsck;
- private final boolean allowLeadingZeroFileMode;
+ private final String fsckSkipList;
+ private final EnumSet<ObjectChecker.ErrorType> ignore;
private final boolean allowInvalidPersonIdent;
private final boolean safeForWindows;
private final boolean safeForMacOS;
@@ -84,13 +98,44 @@ public class TransferConfig {
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$
+ fsckSkipList = rc.getString(FSCK, null, "skipList"); //$NON-NLS-1$
+ allowInvalidPersonIdent = rc.getBoolean(FSCK, "allowInvalidPersonIdent", false); //$NON-NLS-1$
+ safeForWindows = rc.getBoolean(FSCK, "safeForWindows", //$NON-NLS-1$
SystemReader.getInstance().isWindows());
- safeForMacOS = rc.getBoolean("fsck", "safeForMacOS", //$NON-NLS-1$ //$NON-NLS-2$
+ safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", //$NON-NLS-1$
SystemReader.getInstance().isMacOS());
+ ignore = EnumSet.noneOf(ObjectChecker.ErrorType.class);
+ EnumSet<ObjectChecker.ErrorType> set = EnumSet
+ .noneOf(ObjectChecker.ErrorType.class);
+ for (String key : rc.getNames(FSCK)) {
+ if (equalsIgnoreCase(key, "skipList") //$NON-NLS-1$
+ || equalsIgnoreCase(key, "allowLeadingZeroFileMode") //$NON-NLS-1$
+ || equalsIgnoreCase(key, "allowInvalidPersonIdent") //$NON-NLS-1$
+ || equalsIgnoreCase(key, "safeForWindows") //$NON-NLS-1$
+ || equalsIgnoreCase(key, "safeForMacOS")) { //$NON-NLS-1$
+ continue;
+ }
+
+ ObjectChecker.ErrorType id = FsckKeyNameHolder.parse(key);
+ if (id != null) {
+ switch (rc.getEnum(FSCK, null, key, FsckMode.ERROR)) {
+ case ERROR:
+ ignore.remove(id);
+ break;
+ case WARN:
+ case IGNORE:
+ ignore.add(id);
+ break;
+ }
+ set.add(id);
+ }
+ }
+ if (!set.contains(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE)
+ && rc.getBoolean(FSCK, "allowLeadingZeroFileMode", false)) { //$NON-NLS-1$
+ ignore.add(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE);
+ }
+
allowTipSha1InWant = rc.getBoolean(
"uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
allowReachableSha1InWant = rc.getBoolean(
@@ -123,10 +168,18 @@ public class TransferConfig {
return null;
}
return new ObjectChecker()
- .setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
+ .setIgnore(ignore)
.setAllowInvalidPersonIdent(allowInvalidPersonIdent)
.setSafeForWindows(safeForWindows)
- .setSafeForMacOS(safeForMacOS);
+ .setSafeForMacOS(safeForMacOS)
+ .setSkipList(skipList());
+ }
+
+ private ObjectIdSet skipList() {
+ if (fsckSkipList != null && !fsckSkipList.isEmpty()) {
+ return new LazyObjectIdSetFile(new File(fsckSkipList));
+ }
+ return null;
}
/**
@@ -175,4 +228,34 @@ public class TransferConfig {
}
};
}
+
+ static class FsckKeyNameHolder {
+ private static final Map<String, ObjectChecker.ErrorType> errors;
+
+ static {
+ errors = new HashMap<>();
+ for (ObjectChecker.ErrorType m : ObjectChecker.ErrorType.values()) {
+ errors.put(keyNameFor(m.name()), m);
+ }
+ }
+
+ @Nullable
+ static ObjectChecker.ErrorType parse(String key) {
+ return errors.get(toLowerCase(key));
+ }
+
+ private static String keyNameFor(String name) {
+ StringBuilder r = new StringBuilder(name.length());
+ for (int i = 0; i < name.length(); i++) {
+ char c = name.charAt(i);
+ if (c != '_') {
+ r.append(c);
+ }
+ }
+ return toLowerCase(r.toString());
+ }
+
+ private FsckKeyNameHolder() {
+ }
+ }
}
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 dfc3ee4c30..17edfdc4fb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
@@ -637,10 +637,11 @@ class WalkFetchConnection extends BaseFetchConnection {
final byte[] raw = uol.getCachedBytes();
if (objCheck != null) {
try {
- objCheck.check(type, raw);
+ objCheck.check(id, type, raw);
} catch (CorruptObjectException e) {
- throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionInvalid
- , Constants.typeString(type), id.name(), e.getMessage()));
+ throw new TransportException(MessageFormat.format(
+ JGitText.get().transportExceptionInvalid,
+ Constants.typeString(type), id.name(), e.getMessage()));
}
}