diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2019-10-17 09:01:25 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2019-10-17 10:20:14 +0900 |
commit | 98cdca9b5a830f1c2ceca52379d662a68109d43e (patch) | |
tree | d843141173394b4ea4e435553885749096d4fb79 /org.eclipse.jgit.lfs/src/org/eclipse | |
parent | 762f6212b4692b28f098ac597058bd6a489b8b49 (diff) | |
download | jgit-98cdca9b5a830f1c2ceca52379d662a68109d43e.tar.gz jgit-98cdca9b5a830f1c2ceca52379d662a68109d43e.zip |
Enable and fix "Statement unnecessarily nested within else clause" warnings
Since [1] the gerrit project includes jgit as a submodule, and has this
warning enabled, resulting in 100s of warnings in the console.
Also enable the warning here, and fix them.
At the same time, add missing braces around adjacent and nearby one-line
blocks.
[1] https://gerrit-review.googlesource.com/c/gerrit/+/227897
Change-Id: I81df3fc7ed6eedf6874ce1a3bedfa727a1897e4c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.lfs/src/org/eclipse')
4 files changed, 28 insertions, 34 deletions
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java index 56e3a12ddc..3c5826362c 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/BuiltinLFS.java @@ -83,9 +83,8 @@ public class BuiltinLFS extends LfsFactory { Attribute attribute) throws IOException { if (isEnabled(db) && (attribute == null || isEnabled(db, attribute))) { return LfsBlobFilter.smudgeLfsBlob(db, loader); - } else { - return loader; } + return loader; } @Override @@ -93,9 +92,8 @@ public class BuiltinLFS extends LfsFactory { long length, Attribute attribute) throws IOException { if (isEnabled(db, attribute)) { return new LfsInputStream(LfsBlobFilter.cleanLfsBlob(db, input)); - } else { - return new LfsInputStream(input, length); } + return new LfsInputStream(input, length); } @Override diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/CleanFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/CleanFilter.java index 80da802db4..2329ade290 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/CleanFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/CleanFilter.java @@ -138,32 +138,30 @@ public class CleanFilter extends FilterCommand { aOut.write(buf, 0, length); size += length; return length; + } + aOut.close(); + AnyLongObjectId loid = aOut.getId(); + aOut = null; + Path mediaFile = lfsUtil.getMediaFile(loid); + if (Files.isRegularFile(mediaFile)) { + long fsSize = Files.size(mediaFile); + if (fsSize != size) { + throw new CorruptMediaFile(mediaFile, size, fsSize); + } + FileUtils.delete(tmpFile.toFile()); } else { - aOut.close(); - AnyLongObjectId loid = aOut.getId(); - aOut = null; - Path mediaFile = lfsUtil.getMediaFile(loid); - if (Files.isRegularFile(mediaFile)) { - long fsSize = Files.size(mediaFile); - if (fsSize != size) { - throw new CorruptMediaFile(mediaFile, size, fsSize); - } else { - FileUtils.delete(tmpFile.toFile()); - } - } else { - Path parent = mediaFile.getParent(); - if (parent != null) { - FileUtils.mkdirs(parent.toFile(), true); - } - FileUtils.rename(tmpFile.toFile(), mediaFile.toFile(), - StandardCopyOption.ATOMIC_MOVE); + Path parent = mediaFile.getParent(); + if (parent != null) { + FileUtils.mkdirs(parent.toFile(), true); } - LfsPointer lfsPointer = new LfsPointer(loid, size); - lfsPointer.encode(out); - in.close(); - out.close(); - return -1; + FileUtils.rename(tmpFile.toFile(), mediaFile.toFile(), + StandardCopyOption.ATOMIC_MOVE); } + LfsPointer lfsPointer = new LfsPointer(loid, size); + lfsPointer.encode(out); + in.close(); + out.close(); + return -1; } catch (IOException e) { if (aOut != null) { aOut.abort(); diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java index feb8b4ae5a..184658d4d2 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java @@ -179,9 +179,8 @@ public class LfsConnectionFactory { remoteUrl, u); additionalHeaders.putAll(action.header); return action.href; - } else { - return remoteUrl + Protocol.INFO_LFS_ENDPOINT; } + return remoteUrl + Protocol.INFO_LFS_ENDPOINT; } private static Protocol.ExpiringAction getSshAuthentication( @@ -262,9 +261,8 @@ public class LfsConnectionFactory { if (path.endsWith(org.eclipse.jgit.lib.Constants.DOT_GIT)) { return path.substring(0, path.length() - 4); - } else { - return path; } + return path; } /** diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AnyLongObjectId.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AnyLongObjectId.java index b095d20e63..a9bd27f5c5 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AnyLongObjectId.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AnyLongObjectId.java @@ -303,10 +303,10 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> { /** {@inheritDoc} */ @Override public final boolean equals(Object o) { - if (o instanceof AnyLongObjectId) + if (o instanceof AnyLongObjectId) { return equals((AnyLongObjectId) o); - else - return false; + } + return false; } /** |