Allow Repository.getDirectory() to be null
Some types of repositories might not be stored on local disk. For these, they will most likely return null for getDirectory() as the java.io.File type cannot describe where their storage is, its not in the host's filesystem. Document that getDirectory() can return null now, and update all current non-test callers in JGit that might run into problems on such repositories. For the most part, just act like its bare. Change-Id: I061236a691372a267fd7d41f0550650e165d2066 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
8a9844b2af
commit
ffe0614d4d
|
@ -80,6 +80,8 @@ public void doGet(final HttpServletRequest req,
|
||||||
|
|
||||||
private byte[] read(final HttpServletRequest req) throws IOException {
|
private byte[] read(final HttpServletRequest req) throws IOException {
|
||||||
final File gitdir = getRepository(req).getDirectory();
|
final File gitdir = getRepository(req).getDirectory();
|
||||||
|
if (gitdir == null)
|
||||||
|
throw new FileNotFoundException(fileName);
|
||||||
return IO.readFully(new File(gitdir, fileName));
|
return IO.readFully(new File(gitdir, fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,8 +138,10 @@ protected boolean isExportOk(HttpServletRequest req, String repositoryName,
|
||||||
Repository db) throws IOException {
|
Repository db) throws IOException {
|
||||||
if (isExportAll())
|
if (isExportAll())
|
||||||
return true;
|
return true;
|
||||||
else
|
else if (db.getDirectory() != null)
|
||||||
return new File(db.getDirectory(), "git-daemon-export-ok").exists();
|
return new File(db.getDirectory(), "git-daemon-export-ok").exists();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isUnreasonableName(final String name) {
|
private static boolean isUnreasonableName(final String name) {
|
||||||
|
|
|
@ -125,10 +125,12 @@ protected RevWalk createWalk() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String repoName() {
|
private String repoName() {
|
||||||
final File f = db.getDirectory();
|
final File gitDir = db.getDirectory();
|
||||||
String n = f.getName();
|
if (gitDir == null)
|
||||||
|
return db.toString();
|
||||||
|
String n = gitDir.getName();
|
||||||
if (Constants.DOT_GIT.equals(n))
|
if (Constants.DOT_GIT.equals(n))
|
||||||
n = f.getParentFile().getName();
|
n = gitDir.getParentFile().getName();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,17 +171,18 @@ public RevCommit call() throws NoHeadException, NoMessageException,
|
||||||
Result rc = ru.update();
|
Result rc = ru.update();
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case NEW:
|
case NEW:
|
||||||
case FAST_FORWARD:
|
case FAST_FORWARD: {
|
||||||
setCallable(false);
|
setCallable(false);
|
||||||
if (state == RepositoryState.MERGING_RESOLVED) {
|
File meta = repo.getDirectory();
|
||||||
|
if (state == RepositoryState.MERGING_RESOLVED
|
||||||
|
&& meta != null) {
|
||||||
// Commit was successful. Now delete the files
|
// Commit was successful. Now delete the files
|
||||||
// used for merge commits
|
// used for merge commits
|
||||||
new File(repo.getDirectory(), Constants.MERGE_HEAD)
|
new File(meta, Constants.MERGE_HEAD).delete();
|
||||||
.delete();
|
new File(meta, Constants.MERGE_MSG).delete();
|
||||||
new File(repo.getDirectory(), Constants.MERGE_MSG)
|
|
||||||
.delete();
|
|
||||||
}
|
}
|
||||||
return revCommit;
|
return revCommit;
|
||||||
|
}
|
||||||
case REJECTED:
|
case REJECTED:
|
||||||
case LOCK_FAILURE:
|
case LOCK_FAILURE:
|
||||||
throw new ConcurrentRefUpdateException(
|
throw new ConcurrentRefUpdateException(
|
||||||
|
|
|
@ -165,9 +165,7 @@ public void create() throws IOException {
|
||||||
*/
|
*/
|
||||||
public abstract void create(boolean bare) throws IOException;
|
public abstract void create(boolean bare) throws IOException;
|
||||||
|
|
||||||
/**
|
/** @return local metadata directory; null if repository isn't local. */
|
||||||
* @return GIT_DIR
|
|
||||||
*/
|
|
||||||
public File getDirectory() {
|
public File getDirectory() {
|
||||||
return gitDir;
|
return gitDir;
|
||||||
}
|
}
|
||||||
|
@ -712,7 +710,13 @@ protected void doClose() {
|
||||||
public abstract void openPack(File pack, File idx) throws IOException;
|
public abstract void openPack(File pack, File idx) throws IOException;
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Repository[" + getDirectory() + "]";
|
String desc;
|
||||||
|
if (getDirectory() != null)
|
||||||
|
desc = getDirectory().getPath();
|
||||||
|
else
|
||||||
|
desc = getClass().getSimpleName() + "-"
|
||||||
|
+ System.identityHashCode(this);
|
||||||
|
return "Repository[" + desc + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -908,7 +912,7 @@ static byte[] gitInternalSlash(byte[] bytes) {
|
||||||
* @return an important state
|
* @return an important state
|
||||||
*/
|
*/
|
||||||
public RepositoryState getRepositoryState() {
|
public RepositoryState getRepositoryState() {
|
||||||
if (isBare())
|
if (isBare() || getDirectory() == null)
|
||||||
return RepositoryState.BARE;
|
return RepositoryState.BARE;
|
||||||
|
|
||||||
// Pre Git-1.6 logic
|
// Pre Git-1.6 logic
|
||||||
|
@ -1096,7 +1100,7 @@ public abstract ReflogReader getReflogReader(String refName)
|
||||||
* if the repository is "bare"
|
* if the repository is "bare"
|
||||||
*/
|
*/
|
||||||
public String readMergeCommitMsg() throws IOException {
|
public String readMergeCommitMsg() throws IOException {
|
||||||
if (isBare())
|
if (isBare() || getDirectory() == null)
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
JGitText.get().bareRepositoryNoWorkdirAndIndex);
|
JGitText.get().bareRepositoryNoWorkdirAndIndex);
|
||||||
|
|
||||||
|
@ -1123,7 +1127,7 @@ public String readMergeCommitMsg() throws IOException {
|
||||||
* if the repository is "bare"
|
* if the repository is "bare"
|
||||||
*/
|
*/
|
||||||
public List<ObjectId> readMergeHeads() throws IOException {
|
public List<ObjectId> readMergeHeads() throws IOException {
|
||||||
if (isBare())
|
if (isBare() || getDirectory() == null)
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
JGitText.get().bareRepositoryNoWorkdirAndIndex);
|
JGitText.get().bareRepositoryNoWorkdirAndIndex);
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,10 @@ public static Repository open(final Key location, final boolean mustExist)
|
||||||
* repository to register.
|
* repository to register.
|
||||||
*/
|
*/
|
||||||
public static void register(final Repository db) {
|
public static void register(final Repository db) {
|
||||||
cache.registerRepository(FileKey.exact(db.getDirectory(), db.getFS()), db);
|
if (db.getDirectory() != null) {
|
||||||
|
FileKey key = FileKey.exact(db.getDirectory(), db.getFS());
|
||||||
|
cache.registerRepository(key, db);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,7 +136,10 @@ public static void register(final Repository db) {
|
||||||
* repository to unregister.
|
* repository to unregister.
|
||||||
*/
|
*/
|
||||||
public static void close(final Repository db) {
|
public static void close(final Repository db) {
|
||||||
cache.unregisterRepository(FileKey.exact(db.getDirectory(), db.getFS()));
|
if (db.getDirectory() != null) {
|
||||||
|
FileKey key = FileKey.exact(db.getDirectory(), db.getFS());
|
||||||
|
cache.unregisterRepository(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unregister all repositories from the cache. */
|
/** Unregister all repositories from the cache. */
|
||||||
|
|
|
@ -271,8 +271,10 @@ private void removeFetchHeadRecord(final ObjectId want) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFETCH_HEAD(final FetchResult result) throws IOException {
|
private void updateFETCH_HEAD(final FetchResult result) throws IOException {
|
||||||
final LockFile lock = new LockFile(new File(transport.local
|
File meta = transport.local.getDirectory();
|
||||||
.getDirectory(), "FETCH_HEAD"));
|
if (meta == null)
|
||||||
|
return;
|
||||||
|
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"));
|
||||||
try {
|
try {
|
||||||
if (lock.lock()) {
|
if (lock.lock()) {
|
||||||
final Writer w = new OutputStreamWriter(lock.getOutputStream());
|
final Writer w = new OutputStreamWriter(lock.getOutputStream());
|
||||||
|
|
|
@ -357,6 +357,6 @@ public String toString() {
|
||||||
+ "..." + (newObjectId != null ? newObjectId.abbreviate(localDb).name() : "(null)")
|
+ "..." + (newObjectId != null ? newObjectId.abbreviate(localDb).name() : "(null)")
|
||||||
+ (fastForward ? ", fastForward" : "")
|
+ (fastForward ? ", fastForward" : "")
|
||||||
+ ", srcRef=" + srcRef + (forceUpdate ? ", forceUpdate" : "") + ", message=" + (message != null ? "\""
|
+ ", srcRef=" + srcRef + (forceUpdate ? ", forceUpdate" : "") + ", message=" + (message != null ? "\""
|
||||||
+ message + "\"" : "null") + ", " + localDb.getDirectory() + "]";
|
+ message + "\"" : "null") + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue