From 8025443db4234bbf095e593434693141863753f8 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 19 May 2015 09:30:02 +0200 Subject: [PATCH] Move resolveGrandparentFile() to the base class for wider use Change-Id: I67ec732ea2e5345a6946783f0c5ef60c07ce254e Signed-off-by: Sebastian Schuberth Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/util/FS.java | 15 +++++++++++++++ .../src/org/eclipse/jgit/util/FS_POSIX.java | 7 ++----- .../src/org/eclipse/jgit/util/FS_Win32.java | 9 --------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index d11b03e67..762b36ecb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -507,6 +507,21 @@ public abstract class FS { /** @return the $prefix directory C Git would use. */ protected abstract File discoverGitPrefix(); + /** + * @param grandchild + * @return the parent directory of this file's parent directory or + * {@code null} in case there's no grandparent directory + * @since 4.0 + */ + protected static File resolveGrandparentFile(File grandchild) { + if (grandchild != null) { + File parent = grandchild.getParentFile(); + if (parent != null) + return parent.getParentFile(); + } + return null; + } + /** * Set the $prefix directory C Git uses. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java index 9c92d7c4c..667b96979 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java @@ -138,7 +138,7 @@ public class FS_POSIX extends FS { String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$ File gitExe = searchPath(path, "git"); //$NON-NLS-1$ if (gitExe != null) - return gitExe.getParentFile().getParentFile(); + return resolveGrandparentFile(gitExe); if (SystemReader.getInstance().isMacOS()) { // On MacOSX, PATH is shorter when Eclipse is launched from the @@ -150,10 +150,7 @@ public class FS_POSIX extends FS { Charset.defaultCharset().name()); if (w == null || w.length() == 0) return null; - File parentFile = new File(w).getParentFile(); - if (parentFile == null) - return null; - return parentFile.getParentFile(); + return resolveGrandparentFile(new File(w)); } return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java index 41e8113a4..6e0c5e85f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java @@ -128,15 +128,6 @@ public class FS_Win32 extends FS { return null; } - private static File resolveGrandparentFile(File grandchild) { - if (grandchild != null) { - File parent = grandchild.getParentFile(); - if (parent != null) - return parent.getParentFile(); - } - return null; - } - @Override protected File userHomeImpl() { String home = SystemReader.getInstance().getenv("HOME"); //$NON-NLS-1$