Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time. google-java-format is Google's standard formatter and is somewhat inspired by gofmt[1]. This commit formats everything using google-java-format version 1.2. The downside of this one-off formatting is breaking blame. This can be somewhat hacked around with a tool like git-hyper-blame[2], but it's definitely not optimal until/unless this kind of feature makes its way to git core. Not in this change: * Tool support, e.g. Eclipse. The command must be run manually [3]. * Documentation of best practice, e.g. new 100-column default. [1] https://talks.golang.org/2015/gofmt-en.slide#3 [2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html [3] git ls-files | grep java$ | xargs google-java-format -i Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3 Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
committed by
David Pursehouse
parent
6723b6d0fa
commit
292fa154c1
@@ -21,35 +21,27 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.sshd.SshScope.Context;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class AbstractGitCommand extends BaseCommand {
|
||||
@Argument(index = 0, metaVar = "PROJECT.git", required = true, usage = "project name")
|
||||
protected ProjectControl projectControl;
|
||||
|
||||
@Inject
|
||||
private SshScope sshScope;
|
||||
@Inject private SshScope sshScope;
|
||||
|
||||
@Inject
|
||||
private GitRepositoryManager repoManager;
|
||||
@Inject private GitRepositoryManager repoManager;
|
||||
|
||||
@Inject
|
||||
private SshSession session;
|
||||
@Inject private SshSession session;
|
||||
|
||||
@Inject
|
||||
private SshScope.Context context;
|
||||
@Inject private SshScope.Context context;
|
||||
|
||||
@Inject
|
||||
private IdentifiedUser user;
|
||||
@Inject private IdentifiedUser user;
|
||||
|
||||
@Inject
|
||||
private IdentifiedUser.GenericFactory userFactory;
|
||||
@Inject private IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
protected Repository repo;
|
||||
protected Project project;
|
||||
@@ -59,31 +51,35 @@ public abstract class AbstractGitCommand extends BaseCommand {
|
||||
Context ctx = context.subContext(newSession(), context.getCommandLine());
|
||||
final Context old = sshScope.set(ctx);
|
||||
try {
|
||||
startThread(new ProjectCommandRunnable() {
|
||||
@Override
|
||||
public void executeParseCommand() throws Exception {
|
||||
parseCommandLine();
|
||||
}
|
||||
startThread(
|
||||
new ProjectCommandRunnable() {
|
||||
@Override
|
||||
public void executeParseCommand() throws Exception {
|
||||
parseCommandLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
AbstractGitCommand.this.service();
|
||||
}
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
AbstractGitCommand.this.service();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project.NameKey getProjectName() {
|
||||
Project project = projectControl.getProjectState().getProject();
|
||||
return project.getNameKey();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Project.NameKey getProjectName() {
|
||||
Project project = projectControl.getProjectState().getProject();
|
||||
return project.getNameKey();
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
sshScope.set(old);
|
||||
}
|
||||
}
|
||||
|
||||
private SshSession newSession() {
|
||||
SshSession n = new SshSession(session, session.getRemoteAddress(),
|
||||
userFactory.create(session.getRemoteAddress(), user.getAccountId()));
|
||||
SshSession n =
|
||||
new SshSession(
|
||||
session,
|
||||
session.getRemoteAddress(),
|
||||
userFactory.create(session.getRemoteAddress(), user.getAccountId()));
|
||||
n.setAccessPath(AccessPath.GIT);
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user