Introduce a named constant for the ".git" directory extension

Change-Id: Icfe9205994c6810fcd880054a586e9eef29df9a1
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
This commit is contained in:
Robin Rosenberg 2010-01-15 00:18:11 +01:00
parent 0b8b6b5309
commit 1c785d6902
4 changed files with 13 additions and 7 deletions

View File

@ -311,6 +311,9 @@ public final class Constants {
/** Default name for the Git repository directory */ /** Default name for the Git repository directory */
public static final String DOT_GIT = ".git"; public static final String DOT_GIT = ".git";
/** A bare repository typically ends with this string */
public static final String DOT_GIT_EXT = ".git";
/** /**
* Create a new digest function for objects. * Create a new digest function for objects.
* *

View File

@ -382,8 +382,8 @@ public static File resolve(final File directory) {
final String name = directory.getName(); final String name = directory.getName();
final File parent = directory.getParentFile(); final File parent = directory.getParentFile();
if (isGitRepository(new File(parent, name + ".git"))) if (isGitRepository(new File(parent, name + Constants.DOT_GIT_EXT)))
return new File(parent, name + ".git"); return new File(parent, name + Constants.DOT_GIT_EXT);
return null; return null;
} }
} }

View File

@ -57,6 +57,7 @@
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache; import org.eclipse.jgit.lib.RepositoryCache;
@ -204,8 +205,8 @@ public void setExportAll(final boolean export) {
* the repository instance. * the repository instance.
*/ */
public void exportRepository(String name, final Repository db) { public void exportRepository(String name, final Repository db) {
if (!name.endsWith(".git")) if (!name.endsWith(Constants.DOT_GIT_EXT))
name = name + ".git"; name = name + Constants.DOT_GIT_EXT;
exports.put(name, db); exports.put(name, db);
RepositoryCache.register(db); RepositoryCache.register(db);
} }
@ -358,7 +359,8 @@ Repository openRepository(String name) {
name = name.substring(1); name = name.substring(1);
Repository db; Repository db;
db = exports.get(name.endsWith(".git") ? name : name + ".git"); db = exports.get(name.endsWith(Constants.DOT_GIT_EXT) ? name : name
+ Constants.DOT_GIT_EXT);
if (db != null) { if (db != null) {
db.incrementOpen(); db.incrementOpen();
return db; return db;

View File

@ -410,8 +410,9 @@ public String getHumanishName() throws IllegalArgumentException {
String result = elements[elements.length - 1]; String result = elements[elements.length - 1];
if (Constants.DOT_GIT.equals(result)) if (Constants.DOT_GIT.equals(result))
result = elements[elements.length - 2]; result = elements[elements.length - 2];
else if (result.endsWith(DOT_GIT)) else if (result.endsWith(Constants.DOT_GIT_EXT))
result = result.substring(0, result.length() - DOT_GIT.length()); result = result.substring(0, result.length()
- Constants.DOT_GIT_EXT.length());
return result; return result;
} }