Eliminate SectionParser construction boilerplate
Happily, most anonymous SectionParser implementations can be replaced with FooConfig::new, as long as the constructor takes a single Config arg. Many of these, the non-public ones, can in turn be inlined. A few remaining SectionParsers can be lambdas. Change-Id: I3f563e752dfd2007dd3a48d6d313d20e2685943a
This commit is contained in:
parent
9e54cbb693
commit
cf9662cdfe
|
@ -47,7 +47,6 @@
|
|||
|
||||
import org.eclipse.jgit.http.server.GitServlet;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Config.SectionParser;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
||||
|
@ -71,13 +70,6 @@ public void access(HttpServletRequest req, Repository db)
|
|||
}
|
||||
};
|
||||
|
||||
private static final SectionParser<ServiceConfig> CONFIG = new SectionParser<ServiceConfig>() {
|
||||
@Override
|
||||
public ServiceConfig parse(final Config cfg) {
|
||||
return new ServiceConfig(cfg);
|
||||
}
|
||||
};
|
||||
|
||||
private static class ServiceConfig {
|
||||
final boolean enabled;
|
||||
|
||||
|
@ -96,7 +88,7 @@ private static class ServiceConfig {
|
|||
* {@code true}.
|
||||
*/
|
||||
protected static boolean isEnabled(Repository db) {
|
||||
return db.getConfig().get(CONFIG).enabled;
|
||||
return db.getConfig().get(ServiceConfig::new).enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Config.SectionParser;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.ReceivePack;
|
||||
|
@ -68,13 +67,6 @@
|
|||
*/
|
||||
public class DefaultReceivePackFactory implements
|
||||
ReceivePackFactory<HttpServletRequest> {
|
||||
private static final SectionParser<ServiceConfig> CONFIG = new SectionParser<ServiceConfig>() {
|
||||
@Override
|
||||
public ServiceConfig parse(final Config cfg) {
|
||||
return new ServiceConfig(cfg);
|
||||
}
|
||||
};
|
||||
|
||||
private static class ServiceConfig {
|
||||
final boolean set;
|
||||
|
||||
|
@ -89,7 +81,7 @@ private static class ServiceConfig {
|
|||
@Override
|
||||
public ReceivePack create(final HttpServletRequest req, final Repository db)
|
||||
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
||||
final ServiceConfig cfg = db.getConfig().get(CONFIG);
|
||||
final ServiceConfig cfg = db.getConfig().get(ServiceConfig::new);
|
||||
String user = req.getRemoteUser();
|
||||
|
||||
if (cfg.set) {
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Config.SectionParser;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.UploadPack;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||
|
@ -61,13 +60,6 @@
|
|||
*/
|
||||
public class DefaultUploadPackFactory implements
|
||||
UploadPackFactory<HttpServletRequest> {
|
||||
private static final SectionParser<ServiceConfig> CONFIG = new SectionParser<ServiceConfig>() {
|
||||
@Override
|
||||
public ServiceConfig parse(final Config cfg) {
|
||||
return new ServiceConfig(cfg);
|
||||
}
|
||||
};
|
||||
|
||||
private static class ServiceConfig {
|
||||
final boolean enabled;
|
||||
|
||||
|
@ -79,7 +71,7 @@ private static class ServiceConfig {
|
|||
@Override
|
||||
public UploadPack create(final HttpServletRequest req, final Repository db)
|
||||
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
||||
if (db.getConfig().get(CONFIG).enabled)
|
||||
if (db.getConfig().get(ServiceConfig::new).enabled)
|
||||
return new UploadPack(db);
|
||||
else
|
||||
throw new ServiceNotEnabledException();
|
||||
|
|
|
@ -54,12 +54,7 @@
|
|||
/** Keeps track of diff related configuration options. */
|
||||
public class DiffConfig {
|
||||
/** Key for {@link Config#get(SectionParser)}. */
|
||||
public static final Config.SectionParser<DiffConfig> KEY = new SectionParser<DiffConfig>() {
|
||||
@Override
|
||||
public DiffConfig parse(final Config cfg) {
|
||||
return new DiffConfig(cfg);
|
||||
}
|
||||
};
|
||||
public static final Config.SectionParser<DiffConfig> KEY = DiffConfig::new;
|
||||
|
||||
/** Permissible values for {@code diff.renames}. */
|
||||
public static enum RenameDetectionType {
|
||||
|
|
|
@ -49,12 +49,7 @@
|
|||
|
||||
class WriteConfig {
|
||||
/** Key for {@link Config#get(SectionParser)}. */
|
||||
static final Config.SectionParser<WriteConfig> KEY = new SectionParser<WriteConfig>() {
|
||||
@Override
|
||||
public WriteConfig parse(final Config cfg) {
|
||||
return new WriteConfig(cfg);
|
||||
}
|
||||
};
|
||||
static final Config.SectionParser<WriteConfig> KEY = WriteConfig::new;
|
||||
|
||||
private final int compression;
|
||||
|
||||
|
|
|
@ -57,12 +57,7 @@
|
|||
*/
|
||||
public class CoreConfig {
|
||||
/** Key for {@link Config#get(SectionParser)}. */
|
||||
public static final Config.SectionParser<CoreConfig> KEY = new SectionParser<CoreConfig>() {
|
||||
@Override
|
||||
public CoreConfig parse(final Config cfg) {
|
||||
return new CoreConfig(cfg);
|
||||
}
|
||||
};
|
||||
public static final Config.SectionParser<CoreConfig> KEY = CoreConfig::new;
|
||||
|
||||
/** Permissible values for {@code core.autocrlf}. */
|
||||
public static enum AutoCRLF {
|
||||
|
|
|
@ -51,12 +51,7 @@
|
|||
/** The standard "user" configuration parameters. */
|
||||
public class UserConfig {
|
||||
/** Key for {@link Config#get(SectionParser)}. */
|
||||
public static final Config.SectionParser<UserConfig> KEY = new SectionParser<UserConfig>() {
|
||||
@Override
|
||||
public UserConfig parse(final Config cfg) {
|
||||
return new UserConfig(cfg);
|
||||
}
|
||||
};
|
||||
public static final Config.SectionParser<UserConfig> KEY = UserConfig::new;
|
||||
|
||||
private String authorName;
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@
|
|||
import org.eclipse.jgit.internal.storage.file.PackLock;
|
||||
import org.eclipse.jgit.lib.AnyObjectId;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Config.SectionParser;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.MutableObjectId;
|
||||
import org.eclipse.jgit.lib.NullProgressMonitor;
|
||||
|
@ -250,7 +249,7 @@ public BasePackFetchConnection(final PackTransport packTransport) {
|
|||
super(packTransport);
|
||||
|
||||
if (local != null) {
|
||||
final FetchConfig cfg = local.getConfig().get(FetchConfig.KEY);
|
||||
final FetchConfig cfg = local.getConfig().get(FetchConfig::new);
|
||||
allowOfsDelta = cfg.allowOfsDelta;
|
||||
} else {
|
||||
allowOfsDelta = true;
|
||||
|
@ -279,13 +278,6 @@ public BasePackFetchConnection(final PackTransport packTransport) {
|
|||
}
|
||||
|
||||
private static class FetchConfig {
|
||||
static final SectionParser<FetchConfig> KEY = new SectionParser<FetchConfig>() {
|
||||
@Override
|
||||
public FetchConfig parse(final Config cfg) {
|
||||
return new FetchConfig(cfg);
|
||||
}
|
||||
};
|
||||
|
||||
final boolean allowOfsDelta;
|
||||
|
||||
FetchConfig(final Config c) {
|
||||
|
|
|
@ -78,7 +78,6 @@
|
|||
import org.eclipse.jgit.internal.storage.file.PackLock;
|
||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||
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;
|
||||
|
@ -314,7 +313,7 @@ protected BaseReceivePack(final Repository into) {
|
|||
TransferConfig tc = db.getConfig().get(TransferConfig.KEY);
|
||||
objectChecker = tc.newReceiveObjectChecker();
|
||||
|
||||
ReceiveConfig rc = db.getConfig().get(ReceiveConfig.KEY);
|
||||
ReceiveConfig rc = db.getConfig().get(ReceiveConfig::new);
|
||||
allowCreates = rc.allowCreates;
|
||||
allowAnyDeletes = true;
|
||||
allowBranchDeletes = rc.allowDeletes;
|
||||
|
@ -332,13 +331,6 @@ protected BaseReceivePack(final Repository into) {
|
|||
|
||||
/** Configuration for receive operations. */
|
||||
protected static class ReceiveConfig {
|
||||
static final SectionParser<ReceiveConfig> KEY = new SectionParser<ReceiveConfig>() {
|
||||
@Override
|
||||
public ReceiveConfig parse(final Config cfg) {
|
||||
return new ReceiveConfig(cfg);
|
||||
}
|
||||
};
|
||||
|
||||
final boolean allowCreates;
|
||||
final boolean allowDeletes;
|
||||
final boolean allowNonFastForwards;
|
||||
|
|
|
@ -64,12 +64,7 @@ public abstract class DaemonService {
|
|||
|
||||
DaemonService(final String cmdName, final String cfgName) {
|
||||
command = cmdName.startsWith("git-") ? cmdName : "git-" + cmdName; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
configKey = new SectionParser<ServiceConfig>() {
|
||||
@Override
|
||||
public ServiceConfig parse(final Config cfg) {
|
||||
return new ServiceConfig(DaemonService.this, cfg, cfgName);
|
||||
}
|
||||
};
|
||||
configKey = cfg -> new ServiceConfig(DaemonService.this, cfg, cfgName);
|
||||
overridable = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,7 @@
|
|||
public class SignedPushConfig {
|
||||
/** Key for {@link Config#get(SectionParser)}. */
|
||||
public static final SectionParser<SignedPushConfig> KEY =
|
||||
new SectionParser<SignedPushConfig>() {
|
||||
@Override
|
||||
public SignedPushConfig parse(Config cfg) {
|
||||
return new SignedPushConfig(cfg);
|
||||
}
|
||||
};
|
||||
SignedPushConfig::new;
|
||||
|
||||
private String certNonceSeed;
|
||||
private int certNonceSlopLimit;
|
||||
|
|
|
@ -69,12 +69,8 @@ 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>() {
|
||||
@Override
|
||||
public TransferConfig parse(final Config cfg) {
|
||||
return new TransferConfig(cfg);
|
||||
}
|
||||
};
|
||||
public static final Config.SectionParser<TransferConfig> KEY =
|
||||
TransferConfig::new;
|
||||
|
||||
/**
|
||||
* A git configuration value for how to handle a fsck failure of a particular kind.
|
||||
|
|
|
@ -91,7 +91,6 @@
|
|||
import org.eclipse.jgit.internal.JGitText;
|
||||
import org.eclipse.jgit.internal.storage.file.RefDirectory;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Config.SectionParser;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectIdRef;
|
||||
|
@ -231,13 +230,6 @@ public Transport open(URIish uri, Repository local, String remoteName)
|
|||
}
|
||||
};
|
||||
|
||||
private static final Config.SectionParser<HttpConfig> HTTP_KEY = new SectionParser<HttpConfig>() {
|
||||
@Override
|
||||
public HttpConfig parse(final Config cfg) {
|
||||
return new HttpConfig(cfg);
|
||||
}
|
||||
};
|
||||
|
||||
private static class HttpConfig {
|
||||
final int postBuffer;
|
||||
|
||||
|
@ -279,7 +271,7 @@ private static class HttpConfig {
|
|||
} catch (MalformedURLException e) {
|
||||
throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e);
|
||||
}
|
||||
http = local.getConfig().get(HTTP_KEY);
|
||||
http = local.getConfig().get(HttpConfig::new);
|
||||
proxySelector = ProxySelector.getDefault();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,8 @@
|
|||
/** Options used by the {@link WorkingTreeIterator}. */
|
||||
public class WorkingTreeOptions {
|
||||
/** Key for {@link Config#get(SectionParser)}. */
|
||||
public static final Config.SectionParser<WorkingTreeOptions> KEY = new SectionParser<WorkingTreeOptions>() {
|
||||
@Override
|
||||
public WorkingTreeOptions parse(final Config cfg) {
|
||||
return new WorkingTreeOptions(cfg);
|
||||
}
|
||||
};
|
||||
public static final Config.SectionParser<WorkingTreeOptions> KEY =
|
||||
WorkingTreeOptions::new;
|
||||
|
||||
private final boolean fileMode;
|
||||
|
||||
|
|
Loading…
Reference in New Issue