From ab4aada4727aea4d7e2b4ec81a64d4ec0f6f44ca Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 11 Apr 2014 18:09:10 +0400 Subject: [PATCH] [git] Simplify packed-refs line parsing a bit. --- .../git4idea/repo/GitRepositoryReader.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java index 49dbe64997fe..366bbde88050 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryReader.java @@ -427,7 +427,10 @@ class GitRepositoryReader { @Nullable private static HashAndName parsePackedRefsLine(@NotNull String line) { line = line.trim(); - char firstChar = line.isEmpty() ? 0 : line.charAt(0); + if (line.isEmpty()) { + return null; + } + char firstChar = line.charAt(0); if (firstChar == '#') { // ignoring comments return null; } @@ -444,9 +447,14 @@ class GitRepositoryReader { break; } } + if (hash == null) { + LOG.warn("Ignoring invalid packed-refs line: [" + line + "]"); + return null; + } + String branch = null; int start = i; - if (hash != null && start < line.length() && line.charAt(start++) == ' ') { + if (start < line.length() && line.charAt(start++) == ' ') { for (i = start; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c)) { @@ -456,12 +464,11 @@ class GitRepositoryReader { branch = line.substring(start, i); } - if (hash != null && branch != null) { - return new HashAndName(shortBuffer(hash.trim()), shortBuffer(branch)); + if (branch == null) { + LOG.warn("Ignoring invalid packed-refs line: [" + line + "]"); + return null; } - - LOG.info("Ignoring invalid packed-refs line: [" + line + "]"); - return null; + return new HashAndName(shortBuffer(hash.trim()), shortBuffer(branch)); } @NotNull