Now that we have a nice JVM wide cache for Repository instances, we can use that inside of the Daemon code to manage setting up a Repository and locating it on disk using the standard search rules defined by FileKey.resolve(). Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/transport/Daemon.java | 38 +++++++++----------- .../org/spearce/jgit/transport/DaemonService.java | 14 +++++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java b/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java index f55e049..790745d 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java @@ -53,6 +53,8 @@ import org.spearce.jgit.lib.PersonIdent; import org.spearce.jgit.lib.Repository; +import org.spearce.jgit.lib.RepositoryCache; +import org.spearce.jgit.lib.RepositoryCache.FileKey; /** Basic daemon for the anonymous <code>git://</code> transport protocol. */ public class Daemon { @@ -199,6 +201,7 @@ public void exportRepository(String name, final Repository db) { if (!name.endsWith(".git")) name = name + ".git"; exports.put(name, db); + RepositoryCache.register(db); } /** @@ -350,34 +353,27 @@ Repository openRepository(String name) { Repository db; db = exports.get(name.endsWith(".git") ? name : name + ".git"); - if (db != null) + if (db != null) { + db.incrementOpen(); return db; + } - for (final File f : exportBase) { - db = openRepository(new File(f, name)); - if (db != null) - return db; - - db = openRepository(new File(f, name + ".git")); - if (db != null) - return db; - - db = openRepository(new File(f, name + "/.git")); - if (db != null) - return db; + for (final File baseDir : exportBase) { + final File gitdir = FileKey.resolve(new File(baseDir, name)); + if (gitdir != null && canExport(gitdir)) + return openRepository(gitdir); } return null; } - private Repository openRepository(final File d) { - if (d.isDirectory() && canExport(d)) { - try { - return new Repository(d); - } catch (IOException err) { - // Ignore - } + private static Repository openRepository(final File gitdir) { + try { + return RepositoryCache.open(FileKey.exact(gitdir)); + } catch (IOException err) { + // null signals it "wasn't found", which is all that is suitable + // for the remote client to know. + return null; } - return null; } private boolean canExport(final File d) { diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java index c511d5a..817aeee 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java @@ -108,11 +108,15 @@ void execute(final DaemonClient client, final String commandLine) final Repository db = client.getDaemon().openRepository(name); if (db == null) return; - boolean on = isEnabled(); - if (isOverridable()) - on = db.getConfig().getBoolean("daemon", config, on); - if (on) - execute(client, db); + try { + boolean on = isEnabled(); + if (isOverridable()) + on = db.getConfig().getBoolean("daemon", config, on); + if (on) + execute(client, db); + } finally { + db.close(); + } } abstract void execute(DaemonClient client, Repository db) -- 1.6.4.rc0.117.g28cb -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html