aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util
diff options
context:
space:
mode:
authorMarc Strapetz <marc.strapetz@syntevo.com>2010-04-20 21:01:19 +0200
committerShawn O. Pearce <spearce@spearce.org>2010-06-04 19:08:58 -0700
commit936e4ab2f2ad4847e22483b26eb61f0c8e56b70c (patch)
tree731290ad8d049ca21e3a483a346ebb36c4fcac15 /org.eclipse.jgit/src/org/eclipse/jgit/util
parent92eedd667dd75cda762b2ac758dcd1845b05886c (diff)
downloadjgit-936e4ab2f2ad4847e22483b26eb61f0c8e56b70c.tar.gz
jgit-936e4ab2f2ad4847e22483b26eb61f0c8e56b70c.zip
Repository can be configured with FS
On Windows, FS_Win32_Cygwin has been used if a Cygwin Git installation is present in the PATH. Assuming that the user works with the Cygwin Git installation may result in unnecessary overhead if he actually does not. Applications built on top of jgit may have more knowledge on the actually used Git client (Cygwin or not) and hence should be able to configure which FS to use accordingly. Change-Id: Ifc4278078b298781d55cf5421e9647a21fa5db24
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java53
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java9
3 files changed, 27 insertions, 41 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 c4f4242f90..b8d433762e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
@@ -49,19 +49,28 @@ import java.security.PrivilegedAction;
/** Abstraction to support various file system operations not in Java. */
public abstract class FS {
- /** The implementation selected for this operating system and JRE. */
- public static final FS INSTANCE;
+ /** The auto-detected implementation selected for this operating system and JRE. */
+ public static final FS DETECTED;
static {
if (FS_Win32.detect()) {
if (FS_Win32_Cygwin.detect())
- INSTANCE = new FS_Win32_Cygwin();
+ DETECTED = new FS_Win32_Cygwin();
else
- INSTANCE = new FS_Win32();
+ DETECTED = new FS_Win32();
} else if (FS_POSIX_Java6.detect())
- INSTANCE = new FS_POSIX_Java6();
+ DETECTED = new FS_POSIX_Java6();
else
- INSTANCE = new FS_POSIX_Java5();
+ DETECTED = new FS_POSIX_Java5();
+ }
+
+ private final File userHome;
+
+ /**
+ * Constructs a file system abstraction.
+ */
+ protected FS() {
+ this.userHome = userHomeImpl();
}
/**
@@ -117,29 +126,7 @@ public abstract class FS {
* @return the translated path. <code>new File(dir,name)</code> if this
* platform does not require path name translation.
*/
- public static File resolve(final File dir, final String name) {
- return INSTANCE.resolveImpl(dir, name);
- }
-
- /**
- * Resolve this file to its actual path name that the JRE can use.
- * <p>
- * This method can be relatively expensive. Computing a translation may
- * require forking an external process per path name translated. Callers
- * should try to minimize the number of translations necessary by caching
- * the results.
- * <p>
- * Not all platforms and JREs require path name translation. Currently only
- * Cygwin on Win32 require translation for Cygwin based paths.
- *
- * @param dir
- * directory relative to which the path name is.
- * @param name
- * path name to translate.
- * @return the translated path. <code>new File(dir,name)</code> if this
- * platform does not require path name translation.
- */
- protected File resolveImpl(final File dir, final String name) {
+ public File resolve(final File dir, final String name) {
final File abspn = new File(name);
if (abspn.isAbsolute())
return abspn;
@@ -157,12 +144,8 @@ public abstract class FS {
*
* @return the user's home directory; null if the user does not have one.
*/
- public static File userHome() {
- return USER_HOME.home;
- }
-
- private static class USER_HOME {
- static final File home = INSTANCE.userHomeImpl();
+ public File userHome() {
+ return userHome;
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
index f727084860..39f2c03a06 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
@@ -72,7 +72,7 @@ class FS_Win32_Cygwin extends FS_Win32 {
return false;
}
- protected File resolveImpl(final File dir, final String pn) {
+ public File resolve(final File dir, final String pn) {
try {
final Process p;
@@ -103,7 +103,7 @@ class FS_Win32_Cygwin extends FS_Win32 {
// Fall through and use the default return.
//
}
- return super.resolveImpl(dir, pn);
+ return super.resolve(dir, pn);
}
@Override
@@ -116,6 +116,6 @@ class FS_Win32_Cygwin extends FS_Win32 {
});
if (home == null || home.length() == 0)
return super.userHomeImpl();
- return resolveImpl(new File("."), home);
+ return resolve(new File("."), home);
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
index 771e77058a..9d7feb08f2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
@@ -72,8 +72,8 @@ public abstract class SystemReader {
return System.getProperty(key);
}
- public FileBasedConfig openUserConfig() {
- final File home = FS.userHome();
+ public FileBasedConfig openUserConfig(FS fs) {
+ final File home = fs.userHome();
return new FileBasedConfig(new File(home, ".gitconfig"));
}
@@ -136,9 +136,12 @@ public abstract class SystemReader {
public abstract String getProperty(String key);
/**
+ * @param fs
+ * the file system abstraction which will be necessary to
+ * perform certain file system operations.
* @return the git configuration found in the user home
*/
- public abstract FileBasedConfig openUserConfig();
+ public abstract FileBasedConfig openUserConfig(FS fs);
/**
* @return the current system time