Browse Source

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
stable-4.9
Dave Borowitz 7 years ago
parent
commit
cf9662cdfe
  1. 10
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java
  2. 10
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java
  3. 10
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java
  4. 7
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffConfig.java
  5. 7
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WriteConfig.java
  6. 7
      org.eclipse.jgit/src/org/eclipse/jgit/lib/CoreConfig.java
  7. 7
      org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java
  8. 10
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
  9. 10
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
  10. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java
  11. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/SignedPushConfig.java
  12. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
  13. 10
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
  14. 8
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java

10
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java

@ -47,7 +47,6 @@ import javax.servlet.http.HttpServletRequest;
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 class AsIsFileService {
}
};
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 @@ public class AsIsFileService {
* {@code true}.
*/
protected static boolean isEnabled(Repository db) {
return db.getConfig().get(CONFIG).enabled;
return db.getConfig().get(ServiceConfig::new).enabled;
}
/**

10
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java

@ -46,7 +46,6 @@ package org.eclipse.jgit.http.server.resolver;
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 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
*/
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 @@ public class DefaultReceivePackFactory implements
@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) {

10
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java

@ -46,7 +46,6 @@ package org.eclipse.jgit.http.server.resolver;
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 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory;
*/
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 @@ public class DefaultUploadPackFactory implements
@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();

7
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffConfig.java

@ -54,12 +54,7 @@ import org.eclipse.jgit.util.StringUtils;
/** 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 {

7
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WriteConfig.java

@ -49,12 +49,7 @@ import org.eclipse.jgit.lib.CoreConfig;
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;

7
org.eclipse.jgit/src/org/eclipse/jgit/lib/CoreConfig.java

@ -57,12 +57,7 @@ import org.eclipse.jgit.lib.Config.SectionParser;
*/
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 {

7
org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java

@ -51,12 +51,7 @@ import org.eclipse.jgit.util.SystemReader;
/** 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;

10
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java

@ -63,7 +63,6 @@ import org.eclipse.jgit.internal.JGitText;
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 abstract class BasePackFetchConnection extends BasePackConnection
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 abstract class BasePackFetchConnection extends BasePackConnection
}
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) {

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

@ -78,7 +78,6 @@ import org.eclipse.jgit.internal.JGitText;
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 @@ public abstract class BaseReceivePack {
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 @@ public abstract class BaseReceivePack {
/** 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;

7
org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java

@ -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;
}

7
org.eclipse.jgit/src/org/eclipse/jgit/transport/SignedPushConfig.java

@ -54,12 +54,7 @@ import org.eclipse.jgit.lib.Config.SectionParser;
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;

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

@ -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.

10
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

@ -91,7 +91,6 @@ import org.eclipse.jgit.errors.TransportException;
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 class TransportHttp extends HttpTransport implements WalkTransport,
}
};
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 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
} 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();
}

8
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java

@ -55,12 +55,8 @@ import org.eclipse.jgit.lib.CoreConfig.SymLinks;
/** 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…
Cancel
Save