From 351bca931637f603c8a5285bcea7e90a37245606 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 26 Nov 2015 16:59:32 +0300 Subject: [PATCH] [refactoring] GitUtil.findGitDir: extract parsing .git file content --- plugins/git4idea/src/git4idea/GitUtil.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java index a0925b93f4e0..62b80d30e330 100644 --- a/plugins/git4idea/src/git4idea/GitUtil.java +++ b/plugins/git4idea/src/git4idea/GitUtil.java @@ -82,6 +82,7 @@ public class GitUtil { } }; + private static final String SUBMODULE_REPO_PATH_PREFIX = "gitdir:"; private final static Logger LOG = Logger.getInstance(GitUtil.class); /** @@ -105,14 +106,7 @@ public class GitUtil { // if .git is a file with some specific content, it indicates a submodule with a link to the real repository path String content = readContent(child); if (content == null) return null; - String pathToDir; - String prefix = "gitdir:"; - if (content.startsWith(prefix)) { - pathToDir = content.substring(prefix.length()).trim(); - } - else { - pathToDir = content; - } + String pathToDir = parsePathToRepository(content); if (!FileUtil.isAbsolute(pathToDir)) { String canonicalPath = FileUtil.toCanonicalPath(FileUtil.join(rootDir.getPath(), pathToDir)); @@ -124,6 +118,12 @@ public class GitUtil { return VcsUtil.getVirtualFileWithRefresh(new File(pathToDir)); } + @NotNull + private static String parsePathToRepository(@NotNull String content) { + content = content.trim(); + return content.startsWith(SUBMODULE_REPO_PATH_PREFIX) ? content.substring(SUBMODULE_REPO_PATH_PREFIX.length()).trim() : content; + } + @Nullable private static String readContent(@NotNull VirtualFile child) { String content;