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
@@ -20,21 +20,18 @@ import com.google.common.collect.Ordering;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefDatabase;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefDatabase;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
@Singleton
|
||||
public class ChangeUtil {
|
||||
private static final Random UUID_RANDOM = new SecureRandom();
|
||||
private static final BaseEncoding UUID_ENCODING =
|
||||
BaseEncoding.base16().lowerCase();
|
||||
private static final BaseEncoding UUID_ENCODING = BaseEncoding.base16().lowerCase();
|
||||
|
||||
private static final int SUBJECT_MAX_LENGTH = 80;
|
||||
private static final String SUBJECT_CROP_APPENDIX = "...";
|
||||
@@ -47,12 +44,10 @@ public class ChangeUtil {
|
||||
public static String messageUuid() {
|
||||
byte[] buf = new byte[8];
|
||||
UUID_RANDOM.nextBytes(buf);
|
||||
return UUID_ENCODING.encode(buf, 0, 4) + '_'
|
||||
+ UUID_ENCODING.encode(buf, 4, 4);
|
||||
return UUID_ENCODING.encode(buf, 0, 4) + '_' + UUID_ENCODING.encode(buf, 4, 4);
|
||||
}
|
||||
|
||||
public static PatchSet.Id nextPatchSetId(Map<String, Ref> allRefs,
|
||||
PatchSet.Id id) {
|
||||
public static PatchSet.Id nextPatchSetId(Map<String, Ref> allRefs, PatchSet.Id id) {
|
||||
PatchSet.Id next = nextPatchSetId(id);
|
||||
while (allRefs.containsKey(next.toRefName())) {
|
||||
next = nextPatchSetId(next);
|
||||
@@ -64,8 +59,7 @@ public class ChangeUtil {
|
||||
return new PatchSet.Id(id.getParentKey(), id.get() + 1);
|
||||
}
|
||||
|
||||
public static PatchSet.Id nextPatchSetId(Repository git, PatchSet.Id id)
|
||||
throws IOException {
|
||||
public static PatchSet.Id nextPatchSetId(Repository git, PatchSet.Id id) throws IOException {
|
||||
return nextPatchSetId(git.getRefDatabase().getRefs(RefDatabase.ALL), id);
|
||||
}
|
||||
|
||||
@@ -73,7 +67,8 @@ public class ChangeUtil {
|
||||
if (subject.length() > SUBJECT_MAX_LENGTH) {
|
||||
int maxLength = SUBJECT_MAX_LENGTH - SUBJECT_CROP_APPENDIX.length();
|
||||
for (int cropPosition = maxLength;
|
||||
cropPosition > maxLength - SUBJECT_CROP_RANGE; cropPosition--) {
|
||||
cropPosition > maxLength - SUBJECT_CROP_RANGE;
|
||||
cropPosition--) {
|
||||
if (Character.isWhitespace(subject.charAt(cropPosition - 1))) {
|
||||
return subject.substring(0, cropPosition) + SUBJECT_CROP_APPENDIX;
|
||||
}
|
||||
@@ -83,6 +78,5 @@ public class ChangeUtil {
|
||||
return subject;
|
||||
}
|
||||
|
||||
private ChangeUtil() {
|
||||
}
|
||||
private ChangeUtil() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user