-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce usages of Guava #766
Conversation
@@ -3054,7 +3053,7 @@ private void sparseCheckout(@NonNull List<String> paths) throws GitException, In | |||
return; | |||
} else if(paths.isEmpty() && coreSparseCheckoutConfigEnable) { // deactivating sparse checkout needed | |||
deactivatingSparseCheckout = true; | |||
paths = Lists.newArrayList("/*"); | |||
paths = Collections.singletonList("/*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paths
is on the stack, is not returned (because this method returns void
), and is only ever read from (not written to) in this method. Therefore, it is safe to switch from a ArrayList
to an undefined List
implementation.
@@ -1452,7 +1449,7 @@ else if (!referencePath.isDirectory()) | |||
|
|||
StoredConfig config = repository.getConfig(); | |||
config.setString("remote", remote, "url", url); | |||
config.setStringList("remote", remote, "fetch", Lists.newArrayList(Iterables.transform(refspecs, Functions.toStringFunction()))); | |||
config.setStringList("remote", remote, "fetch", refspecs.stream().map(Object::toString).collect(Collectors.toList())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refspecs
is not null because of the code on line 1438, so it is safe to call stream
on it. The Guava documentation explicitly recommends Object::toString
over Functions.toStringFunction
. The setStringList()
method we are calling does a defensive copy of its input, so it is safe to switch from ArrayList
to an undefined List
implementation.
@@ -2463,7 +2460,7 @@ private void markAllRefs(RevWalk walk) throws IOException { | |||
private void markRefs(RevWalk walk, Predicate<Ref> filter) throws IOException { | |||
try (Repository repo = getRepository()) { | |||
for (Ref r : repo.getAllRefs().values()) { | |||
if (filter.apply(r)) { | |||
if (filter.test(r)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A consequence of switching from Guava's Predicate
type to Java's Predicate
type. Since this method is private, serialization is not a concern.
@@ -2775,7 +2772,7 @@ public boolean isBareRepository(String GIT_DIR) throws GitException, Interrupted | |||
public String getDefaultRemote(String _default_) throws GitException, InterruptedException { | |||
Set<String> remotes = getConfig(null).getSubsections("remote"); | |||
if (remotes.contains(_default_)) return _default_; | |||
else return com.google.common.collect.Iterables.getFirst(remotes, null); | |||
else return remotes.stream().findFirst().orElse(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remotes
is not null, or we we would have NPE'd on the previous line, so it is safe to call stream()
. The Guava documentation explicitly recommends this paradigm.
This PR contains some reduction of Guava usages. In general, depending on fewer third-party libraries in favor of native Java Platform functionality eases maintenance.