mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-140051 Avoid SIOOBE is the hash is too short for some reason
+ remove some obsolete code; + add diagnostics for hashes with unexpected length.
This commit is contained in:
@@ -71,6 +71,7 @@ public class DvcsUtil {
|
||||
private static final Logger LOGGER = Logger.getInstance(DvcsUtil.class);
|
||||
private static final int IO_RETRIES = 3; // number of retries before fail if an IOException happens during file read.
|
||||
private static final int SHORT_HASH_LENGTH = 8;
|
||||
private static final int LONG_HASH_LENGTH = 40;
|
||||
|
||||
public static void installStatusBarWidget(@NotNull Project project, @NotNull StatusBarWidget widget) {
|
||||
StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
|
||||
@@ -163,13 +164,13 @@ public class DvcsUtil {
|
||||
|
||||
@NotNull
|
||||
public static String getShortHash(@NotNull String hash) {
|
||||
if (hash.length() == 0) return "";
|
||||
if (hash.length() == 40) return hash.substring(0, SHORT_HASH_LENGTH);
|
||||
if (hash.length() > 40) // revision string encoded with date too
|
||||
{
|
||||
return hash.substring(hash.indexOf("[") + 1, SHORT_HASH_LENGTH);
|
||||
if (hash.length() < SHORT_HASH_LENGTH) {
|
||||
LOG.debug("Unexpectedly short hash: [" + hash + "]");
|
||||
}
|
||||
return hash;
|
||||
if (hash.length() > LONG_HASH_LENGTH) {
|
||||
LOG.debug("Unexpectedly long hash: [" + hash + "]");
|
||||
}
|
||||
return hash.substring(0, Math.min(SHORT_HASH_LENGTH, hash.length()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -271,7 +271,7 @@ public class GitBranchUtil {
|
||||
if (state == GitRepository.State.DETACHED) {
|
||||
String currentRevision = repository.getCurrentRevision();
|
||||
assert currentRevision != null : "Current revision can't be null in DETACHED state, only on the fresh repository.";
|
||||
return currentRevision.substring(0, 7);
|
||||
return DvcsUtil.getShortHash(currentRevision);
|
||||
}
|
||||
|
||||
String prefix = "";
|
||||
|
||||
Reference in New Issue
Block a user