From ae1f7947de907798f59421150ca3a63d5fe36b7c Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 14 Mar 2011 09:19:39 -0700 Subject: [PATCH] FS: Allow cloning an FS instance This permits an application to create its own copy of FS.DETECTED before manually setting the userHome or gitPrefix. Bug: 337101 Change-Id: Ieea33c8d0ebdc801a4656b829d2a4b398559fd45 Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 14 ++++++++++++++ .../src/org/eclipse/jgit/util/FS_POSIX.java | 8 ++++++++ .../src/org/eclipse/jgit/util/FS_POSIX_Java5.java | 13 +++++++++++++ .../src/org/eclipse/jgit/util/FS_POSIX_Java6.java | 13 +++++++++++++ .../src/org/eclipse/jgit/util/FS_Win32.java | 12 ++++++++++++ .../src/org/eclipse/jgit/util/FS_Win32_Cygwin.java | 12 ++++++++++++ 6 files changed, 72 insertions(+) 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 a7c088921..5a48513b6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -110,6 +110,20 @@ public abstract class FS { // Do nothing by default. } + /** + * Initialize this FS using another's current settings. + * + * @param src + * the source FS to copy from. + */ + protected FS(FS src) { + userHome = src.userHome; + gitPrefix = src.gitPrefix; + } + + /** @return a new instance of the same type of FS. */ + public abstract FS newInstance(); + /** * Does this operating system and JRE support the execute flag on files? * 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 180b016be..c181a7a74 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 @@ -77,6 +77,14 @@ abstract class FS_POSIX extends FS { return null; } + FS_POSIX() { + super(); + } + + FS_POSIX(FS src) { + super(src); + } + @Override public ProcessBuilder runInShell(String cmd, String[] args) { List argv = new ArrayList(4 + args.length); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java5.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java5.java index ec8175ab5..c79bbe69b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java5.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java5.java @@ -46,6 +46,19 @@ package org.eclipse.jgit.util; import java.io.File; class FS_POSIX_Java5 extends FS_POSIX { + FS_POSIX_Java5() { + super(); + } + + FS_POSIX_Java5(FS src) { + super(src); + } + + @Override + public FS newInstance() { + return new FS_POSIX_Java5(this); + } + public boolean supportsExecute() { return false; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java index 2417ae735..09a4db7a2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java @@ -74,6 +74,19 @@ class FS_POSIX_Java6 extends FS_POSIX { } } + FS_POSIX_Java6() { + super(); + } + + FS_POSIX_Java6(FS src) { + super(src); + } + + @Override + public FS newInstance() { + return new FS_POSIX_Java6(this); + } + public boolean supportsExecute() { return true; } 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 5838fed6a..b441d2066 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 @@ -64,6 +64,18 @@ class FS_Win32 extends FS { && StringUtils.toLowerCase(osDotName).indexOf("windows") != -1; } + FS_Win32() { + super(); + } + + FS_Win32(FS src) { + super(src); + } + + public FS newInstance() { + return new FS_Win32(this); + } + public boolean supportsExecute() { return false; } 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 0cc937d59..e5e97c5fb 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 @@ -68,6 +68,18 @@ class FS_Win32_Cygwin extends FS_Win32 { return cygpath != null; } + FS_Win32_Cygwin() { + super(); + } + + FS_Win32_Cygwin(FS src) { + super(src); + } + + public FS newInstance() { + return new FS_Win32_Cygwin(this); + } + public File resolve(final File dir, final String pn) { String w = readPipe(dir, // new String[] { cygpath, "--windows", "--absolute", pn }, //